#include #include using namespace std; typedef unsigned long long ll; set s; ll mx_added; void add_full(ll n) { if( n <= mx_added ) return; ll t = 1; while( t <= n ) { s.insert(t); t = t * 2 + 1; } } inline ll lowbit(ll x) { return x&-x; } int get_h(ll n) { int h = 0; while( (1ull << h) < n+1 ) ++h; return h; } bool okay(int a,int b) { int d = b-a; if( d < 0 ) d = -d; return d <= 1; } void dfs(ll x) { if( x == 0 ) return; if( x == 1 ) { s.insert(1); return; } if( lowbit(x+1) == (x+1) ) { add_full(x); return; } ll t = 1; while( !okay(get_h(t),get_h(x-1-t) ) ) { t = t * 2 + 1; } dfs(t); dfs(x-1-t); s.insert(x); } int main() { ll n; while( 1 == scanf("%I64u",&n) ) { mx_added = 0; s.clear(); dfs(n); printf("%u\n",s.size()); } return 0; }