from functools import lru_cache @lru_cache(maxsize=None) def solve(a,b,c): if c<=2: cnt=0 while b<2**c: b+=b.bit_count()+a cnt+=1 return cnt,b cnt0,x0=solve(a,b,c-1) cnt1,x1=solve(a+1,x0-2**(c-1),c-1) return cnt0+cnt1,x1+2**(c-1) N=int(input()) ans=1 cur=1 for p in range(40,-1,-1): while cur+2**p<=N: assert cur+2**(p+1)>N q,r=divmod(cur,2**p) cnt,d=solve(q.bit_count(),r,p) ans+=cnt cur=q*2**p+d if cur!=N: ans=-1 print(ans)