R=range N=int(input())+1 def p(i):return sum(i>>d&1for d in R(20)) print(sum(sum((p(i)==p(j))*i&j for j in R(i,N))for i in R(N)))