The New Year tree is an infinite perfect binary tree rooted in the node 1. Each node v has two children: nodes indexed (2·v) and (2·v + 1).  Polar bears love decorating the New Year tree and Limak is no exception. As he is only a little bear, he was told to decorate only one simple path between some pair of nodes. Though he was given an opportunity to pick the pair himself! Now he wants to know the number of unordered pairs of indices (u, v) (u ≤ v), such that the sum of indices of all nodes along the simple path between u and v (including endpoints) is equal to s. Can you help him and count this value?

The only line of the input contains a single integer s (1 ≤ s ≤ 1015).

Print one integer, denoting the number of unordered pairs of nodes indices defining simple paths with the sum of indices of vertices equal to s.

NoteIn sample test, there are 4 paths with the sum of indices equal to 10:

#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	char ch;
	while (ch = getchar(), !isdigit(ch));
	res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
}

template <class T>
inline void put(T x)
{
	if (x > 9)
		put(x / 10);
	putchar(x % 10 + 48);
}

typedef long long ll;
const int N = 55;
const int M = 105;
ll s, f[N][M][2];

template <class T>
inline void CkMin(T &x, T y) {x > y ? x = y : 0;}
template <class T>
inline T Max(T x, T y) {return x > y ? x : y;}
template <class T>
inline T Min(T x, T y) {return x < y ? x : y;}

inline int askD(ll x)
{
	int cnt = 0;
	while (x)
		x >>= 1, ++cnt;
	return cnt;
}

inline int solve1()
{
	int ans = 0;
	for (int h = 2; h <= 50; ++h)
	{
		ll x = s / ((1ll << h) - 1);
		if (!x)
			break ;
		ll delt = s - ((1ll << h) - 1) * x;
		for (int j = h - 1; j >= 1; --j)
			if (delt >= (1ll << j) - 1)
				delt -= (1ll << j) - 1;
		!delt ? ++ans : 0;
	}
	return ans;
}

inline ll solve2()
{
	ll res = 0;
	for (int h1 = 2; h1 <= 50; ++h1)
		for (int h2 = 2; h2 <= 50; ++h2)
		{
			if (s - (1ll << h2 - 1) + 1 <= 0)
				break ;
			ll x = (s - (1ll << h2 - 1) + 1) / ((1ll << h1) + (1ll << h2) - 3);
			if (!x)
				break ;
			ll delt = s - ((1ll << h1) + (1ll << h2) - 3) * x - (1ll << h2 - 1) + 1;
			int tot = h1 + h2 - 4;
			for (int cnt = 0; cnt <= tot; ++cnt)
				if (!(delt + cnt & 1))
				{
					delt += cnt;
					int ds = askD(delt) + 1;
					for (int i = 1; i <= ds + 1; ++i)
						for (int j = 0, jm = i - 1 << 1; j <= jm; ++j)
							f[i][j][0] = f[i][j][1] = 0;
					f[1][0][0] = 1;
					for (int i = 1; i <= ds; ++i)
						for (int j = 0, jm = Min(i - 1 << 1, tot); j <= jm; ++j)
							for (int k = 0; k < 2; ++k)
								if (f[i][j][k])
								for (int a = 0, am = i < h1 - 1 ? 1 : 0; a <= am; ++a)
									for (int b = 0, bm = i < h2 - 1 ? 1 : 0; b <= bm; ++b)
										if ((k + a + b & 1) == (delt >> i & 1))
											f[i + 1][j + a + b][k + a + b >> 1] += f[i][j][k];
					res += f[ds + 1][cnt][0];
					delt -= cnt;
				}
		}
	return res;

}

int main()
{
	read(s);
	put(solve1() + solve2() + 1), putchar('\n');
}
//hellobig_tq

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll S, R;
int len1, len2;

ll cc[52][102][2];
ll dp(int bit, int sum, int c) {
    if(bit > 50) return sum == 0 && c == 0;
    ll &ret = cc[bit][sum][c];
    if(ret != -1) return ret;

    ret = 0;
    for(int i = 0; i <= (sum && bit < len1? 1 : 0); i++) {
        int j = (i + c) % 2 == ((R & (1LL << bit))? 1 : 0)? 0 : 1;
        if(j && (sum - i == 0 || bit >= len2)) continue;
        ret += dp(bit + 1, sum - i - j, (i + j + c >= 2));
    }
    return ret;
}

int main() {
    cin >> S;

    ll ans = 0;
    for(int i = 0; i <= 50; i++) {
        for(int j = 0; j <= 50; j++) {
            ll Q;
            if(i == 0 && j == 0) Q = 1;
            else if(i == 0) Q = (1LL << (j + 1)) - 1;
            else if(j == 0) Q = (1LL << (i + 1)) - 1;
            else Q = (1LL << (i + 1)) + (1LL << (j + 1)) - 3;
            if(Q > S) break;
            R = S % Q;
            if(R < (1LL << j) - 1) continue;
            R -= (1LL << j) - 1;

            len1 = i;
            len2 = j;
            for(int sum = 0; sum <= (i? i - 1 : 0) + (j? j - 1 : 0); sum++) {
                R += sum;
                if(R % 2) {
                    R -= sum;
                    continue;
                }
                memset(cc, -1, sizeof(cc));
                ans += dp(1, sum, 0);
                R -= sum;
            }
        }
    }
    cout << ans;
}

#include<bits/stdc++.h>
using namespace std;
#define err(x) cout<<#x<<"= "<<x<<endl;
#define FOR(i,a,b) for(int i =a; i< b; ++i)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define INF 1000000000
#define TRVI(it,it1,it2) for(vi::iterator it = it1; it!= it2; it++)
#define ff first
#define ss second
#define mp make_pair
#define pq priority_queue<int, vector<int>, greater<int> >
#define ll long long
const ll PR = 1000000009;
#define SIZE 1
#define vi vector<int>
#define pii pair<int,int>
//#define endl '\n'

ll dp[60][180][2];

ll solve(ll ones, ll sum, ll len1, ll len2){
	for(int i =0; i< 60; i++){
		rep(j,180)
			rep(k,2)
				dp[i][j][k] =0;
	}
	dp[0][0][0] = 1;
	ll nowbit;
	for( nowbit = 1; (1ll<<nowbit-1) <= sum; nowbit++){
		for(int dig1 = 0; dig1<2; dig1++){
			if(dig1==1 && nowbit>len1)continue;
			for(int dig2 =0; dig2<2; dig2++){
				if(dig2 ==1 && nowbit>len2)continue;
				for(int carry=0; carry <2; carry++){
					int dignow = carry + dig1+ dig2;
					if(dignow%2 != (sum>>nowbit-1)%2)continue;
					for(int prev = 0; prev<= ones; prev++){
//						if(nowbit)
						dp[nowbit][prev+dig1+dig2] [dignow/2] += dp[nowbit-1][prev][carry];
//						else{
//							if(carry) continue;
//							dp[0][dig1+dig2][dignow/2] = 1;
//						}
					}
				}
			}
		}
	}
	return dp[nowbit-1][ones][0];
}

int main(){
//	#ifdef ONLINE_JUDGE
//	freopen("a.in", "r" , stdin);
//	freopen("a.out", "w", stdout);
//      cin.tie(false); cout.tie(false);
//	#endif
	ios::sync_with_stdio(false);
	ll s,ans=0;
	cin>>s;
	ll a,l1,l2;
//	cin>>a>>s>>l1>>l2;
//	cout<<solve(a,s,l1,l2)<<' '<< solveDP(a,l1,l2,s)<<endl;

	for(ll m = 0; m< 60; m++){

		for(ll n = 0; n< 60; n++){
//			cout<<m<<' '<<n<<endl;
			ll start = (1ll<<(m+1)) -1,s2 = (1ll<<(n+1))-1,denom;
			denom = start + s2-1;
			start = s/denom;

			if(start ==0)continue;

//			cout<<m <<' '<<n<<' '<<start<<endl;
			start = s%denom ;
			start -= (1ll<<n)-1;
		//	if(start<0)continue;
		///	ll ans= 0;
			for(ll ones = 0; ones<=m+n; ones++){
				ll tot = start;
				tot+= ones;
				if(tot&1 || tot<0)continue;
				tot/=2;
//				int pra =ans;
				ans+= solve(ones, tot,max(m-1,0ll),max(n-1,0ll));
//				if(ans>pra)cout<<s/denom<<' '<<m<<' '<<n<<endl;
			}
		}
	}
	cout<<ans<<endl;

	return 0;
};

#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxd=58;
ll f[maxd+10][maxd*2+10][2],two[maxd+10];
int i,j,k,l,t,n,m,a,b;
ll x,y,now,s,ans;
void work(int a,int b,ll now,int cnt){
	int i,j,k,l,r,t,s,d,mx=max(a-2,b-1)+2;
	fo(i,0,maxd+2)
		fo(j,0,cnt)
			f[i][j][0]=f[i][j][1]=0;
	f[0][0][0]=1;
	fo(i,0,mx-1){
		if ((now&two[i])) d=1;else d=0;
		fo(j,0,cnt)
			fo(t,0,1)
				if (f[i][j][t]){
					fo(l,0,1)
						fo(r,0,1){
							if (l&&i>a-2) continue;
							if (r&&i>b-1) continue;
							if (!r&&i==b-1) continue;
							s=l+r+t;
							k=s/2;s=s%2;
							if (s!=d) continue;
							f[i+1][j+l+r][k]+=f[i][j][t];
						}
				}
	}
	ans+=f[mx][cnt][0];
}
int main(){
	two[0]=1;
	fo(i,1,maxd+1) two[i]=two[i-1]*2;
	scanf("%I64d",&s);
	fo(a,0,maxd)
		fo(b,0,maxd){
			y=two[a+1]+two[b+1]-3;
			x=s/y;
			while (x){
				now=s-x*y;
				if (now>two[a]-a+two[b+1]-b-3){
					x=0;
					break;
				}
				if (now>=two[b]-1&&now<=two[a]-a+two[b+1]-b-3) break;
				x--;
			}
			if (!x) continue;
			now=s-x*y;
			fo(i,0,maxd*2)
				if ((now+i)%2==0) work(a,b,(now+i)/2,i);
		}
	printf("%I64d\n",ans);
}

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
void dec(ll &x, ll y) {
    if (x >= y)
        x -= y;
}
ll p(int x) {
    return 1ll << x;
}

ll f[51][101][2];
ll calc(ll s, ll x, int a, int b, int n) {
    if (s & 1)
        return 0;
    if (n == 0)
        return s == 0 ? 1 : 0;
    if (a == 1 && b == 1)
        return ((s - n) == (x * 5 + 1)) ? 1 : 0;
    memset(f, 0, sizeof f);
    f[0][0][0] = 1;
    for (int i = 1; i <= 50; ++i) {
        int d = (s >> i) & 1;
        for (int j = 0; j <= 2 * (i - 1); ++j) {
            for (int aa = 0; aa <= 1; ++aa) {
                if (aa == 1 && i >= a)
                    continue;
                for (int bb = 0; bb <= 1; ++bb) {
                    if (bb == 1 && i >= b)
                        continue;
                    for (int k = 0; k <= 1; ++k) {
                        if ((k + aa + bb) % 2 == d)
                            f[i][j + aa + bb][(k + aa + bb) / 2] += f[i - 1][j][k];
                    }
                }
            }
        }
    }
    return f[50][n][0];
}

int main() {
	#ifndef ONLINE_JUDGE
		freopen("s.in","r",stdin);
		freopen("t.out","w",stdout);
	#endif
    ll s;
    cin >> s;
    ll num = 0;
    for (int i = 1; i <= 50; ++i) {
        ll x = s / (p(i) - 1);
        if (x > 0) {
            ll last = s % (p(i) - 1);
            for (int j = i - 1; j >= 1; --j)
                dec(last, p(j) - 1);
            if (last == 0)
                ++num;
        }
    }
    for (int h1 = 1; h1 <= 50; ++h1) {
        for (int h2 = 1; p(h2) - 1 <= s; ++h2) {
            ll x = (s - p(h2) + 1) / (p(h1 + 1) + p(h2 + 1) - 3);
            if (x > 0) {
                ll last = (s - p(h2) + 1) % (p(h1 + 1) + p(h2 + 1) - 3);
                for (int n = 0; n <= h1 + h2; ++n) {
                    ll temp = calc(last + n, x, h1, h2, n);
                    num += temp;
                }
            }
        }
    }

    cout << num << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr ll B = 52;
ll dp[2][B+1][B+B+1];

ll solve(ll sum, ll bits, ll dmax, ll emax) {
	ll lastbit = 1;
	while ((1LL<<lastbit) <= sum) ++lastbit;

	for (int b = 0; b <= bits; ++b)
		dp[0][0][b] = dp[1][0][b] = 0;
	dp[0][0][0] = 1;

	for (int b = 1; b < lastbit; ++b) {
		sum >>= 1;
		for (int bt = 0; bt <= bits; ++bt) {
			// turn nothing on
			dp[0][b][bt] = dp[sum&1][b-1][bt];
			dp[1][b][bt] = 0; // reset for ease
			// turn d on
			if (bt > 0 && b <= dmax) dp[1^sum&1][b][bt] += dp[1^sum&1][b-1][bt-1];
			// turn e on
			if (bt > 0 && b <= emax) dp[1^sum&1][b][bt] += dp[1^sum&1][b-1][bt-1];
			// turn d,e on
			if (bt > 1 && b <= dmax && b <= emax)
				dp[1][b][bt] += dp[sum&1][b-1][bt-2];
		}
	}
	ll r = dp[0][lastbit - 1][bits];
	return r;
}

int main() {
	ll s, ans = 0;
	cin >> s;

	for (ll d = 1; d <= B; ++d)
		for (ll e = 1; e <= B; ++e) {
			ll G = ((1LL << d) + (1LL << e) - 3LL);
			ll x = s/G;
			if (x < 1) continue;
			ll r = s - x * G;
			r -= ((1LL << (e - 1)) - 1LL);
			if (r < 0) continue;
			if (r > (1LL << d) + (1LL << e) - d - e - 2LL)
				continue;
//			cerr << "Trying " << d << ' ' << e << ", making " << r << ", starting at " << x << endl;
			for (ll bits = r % 2; bits < max(2LL, d + e - 2LL); bits += 2)
				ans += solve(r+bits, bits, d-2, e-2);
		}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

LL s,ans;
LL f[2][150][2];

inline LL dp(int c,int a,int b,LL s){
	int i;
	memset(f,0,sizeof(f));
	f[1][0][0]=1;
	for(i=0;(1ll<<i)<=s;i++){
		memset(f[i&1],0,sizeof(LL)*300);
		for(int k=0;k<=c;k++)
			for(int aa=0;!aa || aa<=1 && i<a;aa++)
				for(int bb=0;!bb || bb<=1 && i<b;bb++){
					int t=(s>>i)&1^aa^bb;
					f[i&1][k+aa+bb][t+aa+bb>>1]+=f[(i&1)^1][k][t];
				}
	}
	return f[(i&1)^1][c][0];
}
int main()
{
	cin >> s;
	for(int a=0;a<60;a++)
		for(int b=0;b<60;b++){
			LL tt=(1ll<<a+1)+(1ll<<b+1)-3;
			if(tt>s) break;
			LL r=s%tt-(1ll<<b)+1;
			for(int c=0;c<=a+b;c++) if(r+c>=0 && !((r+c)%2))
				ans+=dp(c,a-1,b-1,r+c>>1);
		}
	cout << ans << endl;;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
ll n,ans;
map<ll,ll> mp[55][55];
ll Func(ll L,ll R,ll v){
	if (L>R) swap(L,R);
	if (!L&&!R) return !v;
	if (mp[L][R].find(v)!=mp[L][R].end()) return mp[L][R][v];
	if (v<0||v>(1ll<<L)+(1ll<<R)-L-R-2) return 0;
	return mp[L][R][v]=Func(L,R-1,v)+(R==1?0:Func(L,R-1,v-(1ll<<(R-1))+1));
}
/*
0  2
1  4
3  8
11 16
26 32
x 2x 4x 8x
*/
int main(){
	scanf("%lld",&n);
	for (int L=0;1ll<<(L+1)<=n+1;++L)
		for (int R=0;(1ll<<(L+1))+(3ll<<R)<=n+4;++R){
			ll s1=(1ll<<(L+1))+(1ll<<(R+1))-3,s2=(1ll<<R)-1;
			ll f=(n-s2)/s1,g=n-s1*f-s2;
			//cout<<L<<' '<<R<<' '<<f<<' '<<g<<' '<<ans<<endl;
			ans+=Func(L,R,g);
		}
	printf("%lld\n",ans);
}//hello

#include<bits/stdc++.h>
using namespace std;
#define int long long
int f[60][120][2],n,L,R,now;
int dfs(int ws,int res,int  flag){
	if (res<0)return 0;
	if (~f[ws][res][flag])return f[ws][res][flag];
	int&t=f[ws][res][flag];t=0;
	if ((1ll<<ws)>now){
		if (res==0&&flag==0)t=1;
		return t;
	}
	if ((1ll<<ws)&now){
		if (flag){
			t=dfs(ws+1,res,0);
			if (ws<L&&ws<R)t+=dfs(ws+1,res-2,1);
		}else{
			if (ws<L)t+=dfs(ws+1,res-1,0);
			if (ws<R)t+=dfs(ws+1,res-1,0);
		}
	}
	else{
		if (flag){
			if (ws<L)t+=dfs(ws+1,res-1,1);
			if (ws<R)t+=dfs(ws+1,res-1,1);
		}else{
			t=dfs(ws+1,res,0);
			if (ws<L&&ws<R)t+=dfs(ws+1,res-2,1);
		}
	}
	return t;
}
int ans;
signed main(){
	scanf("%lld",&n);
	for (int a=0;(1ll<<a)<=n;a++){
		for (int b=0;(1ll<<b)<=n;b++){
			int lca=(n-(1ll<<b)+1)/((1ll<<a+1)+(1ll<<b+1)-3);
			if (lca==0)continue;
			int nn=n-lca*((1ll<<a+1)+(1ll<<b+1)-3)+1-(1ll<<b);
			for (int i=0;i<=a+b;i++){
				memset(f,-1,sizeof(f));
				L=a-1;R=b-1;
				now=nn+i;
				if (now&1)continue;now/=2;
				ans+=dfs(0,i,0);
			}
		}
	}
	printf("%lld\n",ans);
}

//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) (x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\n');x=c;}
inline void writes(string s){puts(s.c_str());}
inline void writeln(){writes("");}
inline void writei(int x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
inline void writell(ll x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)
#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define rep0(i,x) forup ((i),0,(x))
#define rep1(i,x) forup ((i),0,(x)-1)
#define rep2(i,x) fordo ((i),(x)-1,0)
#define repd(i,x) fordo ((i),(x),1)
#define itr iterator
#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x1bbbbbbbbbbbbbbbll
#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
long long n,m,i,j,k,t,ans,pw[65],d,a,b,c,dp[65][125][2];
long long qry(long long x,long long y)
{
	long long s=0;
	while(x!=y){
		if(x<y) swap(x,y);
		s+=x;x/=2;
	}
	return s+x;
}
long long solve(long long rem,long long rt,long long h1,long long h2,long long num)
{
	memset(dp,0,sizeof(dp));
	long long i,j,k,x,y;
	dp[0][0][0]=1;
	rep(i,d){
		long long dig=((rem>>i)&1);
		rep0(j,num)rep1(k,2)if(dp[i-1][j][k]){
			rep1(x,2)if(!x||i<h1)rep1(y,2)if(!y||i<h2){
				long long t=k+x+y;
				if(t%2!=dig) continue;
				dp[i][j+x+y][(k+x+y)/2]+=dp[i-1][j][k];
			}
		}
	}
//	cerr<<rem<<' '<<rt<<' '<<h1<<' '<<h2<<' '<<num<<' '<<dp[d][num][0]<<endl;
	return dp[d][num][0];
}
int main()
{
	pw[0]=1;
	rep(i,60){
		pw[i]=pw[i-1]*2ll;
	}
	{
		d=59;
		cin>>n;
		ans=0;
		rep(i,d){
			long long rt=(n/(pw[i]-1));
			if(rt<=0) continue;
			long long rem=n-rt*(pw[i]-1);
			rep2(j,i){
				if(rem>=(pw[j]-1)){
					rem-=pw[j]-1;
				}
			}
			if(!rem) ans++;
		}
		rep(i,d)for(j=1;pw[j]-1<=n;j++){
			long long rt=((n-pw[j]+1)/(pw[i+1]+pw[j+1]-3));
			if(rt<=0) continue;
			long long rem=(n-pw[j]+1)-rt*(pw[i+1]+pw[j+1]-3);
			if(!rem){
				ans++;
				continue;
			}
			if(i==1&&j==1){
				ans+=(rem==(rt*5+1));
				continue;
			}
			rep(k,i+j)if((rem+k)%2==0){
				ans+=solve(rem+k,rt,i,j,k);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int BIT = 52;

ll s,f[2][BIT * 2][2];

int main()
{
	cin >> s;
	ll ans = 0;
	for(int L = 0;L < BIT;L ++)
		for(int R = 0;R < BIT;R ++)
		{
			ll v = s / ((1ll << (L + 1)) + (1ll << (R + 1)) - 3);
			if (v <= 0) continue;
			ll nw = s - (v - 1) * ((1ll << (L + 1)) + (1ll << (R + 1)) - 3) + 1;
			for(int os = 0;os <= L + R + 2;os ++)
			{
				ll go = nw + os;
				if (go & 1) continue;
				go /= 2;
				memset(f,0,sizeof f);
				int cr = 0;
				f[cr][0][0] = 1;
				int bit = max(L,R);
				if (go >= (1ll << (bit + 2))) continue;
				for(int i = 0;i <= bit;i ++,cr ^= 1)
				{
					memset(f[cr ^ 1],0,sizeof f[cr ^ 1]);
					for(int bc = 0;bc <= os;bc ++)
						for(int ad = 0;ad < 2;ad ++)
							if (f[cr][bc][ad])
								for(int lv = 0;lv < 2;lv ++)
									if (i > L && lv || i == L && !lv || i == L - 1 && lv) continue; else
										for(int rv = 0;rv < 2;rv ++)
											if (i > R && rv || i == R && !rv || i == R - 1 && !rv) continue; else
											{
												int cval = lv + rv + ad;
												if (cval % 2 != bool(go & (1ll << i))) continue;
												f[cr ^ 1][bc + lv + rv][cval >> 1] += f[cr][bc][ad];
											}
				}
				ans += f[cr][os][bool(go & (1ll << (bit + 1)))];
			}
		}
	cout << ans << endl;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int i,j,k,l,r,cnt,a,b;
long long s,p[52],f[52][102][2],ans;
int count(long long x)
{
	int ans=0;
	for(long long i=0;(1LL<<i)<=x;i++){
		if(x&(1LL<<i)) ans++;
	}
	return ans;
}
signed main()
{
	scanf("%lld",&s);
	int h=log2(1.0*s)+1;
	for(i=p[0]=1;i<=h;i++) p[i]=p[i-1]*2;
	for(l=1;l<=h;l++){
		long long x=s/(p[l]-1);
		if(x==0) break;
		for(cnt=0;cnt<=l-1;cnt++){
			long long tmp=s-x*(p[l]-1)+cnt;
			if(tmp%2==0&&count(tmp)==cnt) ans++;
		}
	}
	for(l=2;l<=h;l++){
		for(r=2;r<=h;r++){
			long long x=(s-p[r-1]+1)/(p[l]+p[r]-3);
			if(x==0) break;
			for(cnt=0;cnt<=l+r-4;cnt++){
				long long tmp=s-x*(p[l]+p[r]-3)-p[r-1]+1+cnt;
				if(tmp%2!=0) continue;
				memset(f,0,sizeof(f));
				f[0][0][0]=1;
				for(i=1;i<=max(l,r);i++){
					for(j=0;j<=min(cnt,2*(i-1));j++){
						for(k=0;k<=1;k++){
							for(a=0;a<=1;a++){
								for(b=0;b<=1;b++){
									if((k+a+b)%2==(tmp>>i)%2&&(a==0||i<l-1)&&(b==0||i<r-1)){
										f[i][j+a+b][(k+a+b)/2]+=f[i-1][j][k];
									}
								}
							}
						}
					}
				}
				ans+=f[max(l,r)][cnt][0];
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

typedef long long LL;

LL s, dp[66][122][2];
int vis[66][122][2], cur, tab[66], pa, pb;

inline LL dfs(int x, int c, bool up) {
  if (!x) return !c && !up;
  if (vis[x][c][up] == cur)
    return dp[x][c][up];
  vis[x][c][up] = cur;
  int s = (up << 1) + tab[x];
  LL ans = 0;
  bool tc = (c && x < pa), td = (c && x < pb);
  if (s == 0) ans = dfs(x - 1, c, 0);
  else if (s == 1) {
    if (tc) ans = dfs(x - 1, c - 1, 0);
    if (td) ans += dfs(x - 1, c - 1, 0);
    ans += dfs(x - 1, c, 1);
  }
  else if (s == 2) {
    if (tc) {
      if (td && c >= 2) ans = dfs(x - 1, c - 2, 0);
      ans += dfs(x - 1, c - 1, 1);
    }
    if (td) ans += dfs(x - 1, c - 1, 1);
  }
  else if (tc && td && c >= 2) ans = dfs(x - 1, c - 2, 1);
  return dp[x][c][up] = ans;
}

inline LL calc(int a, int b) {
  if (!a && !b) return 1;
  pa = a; pb = b;
  int len;
  LL res = 0, sum = s % ((2LL << a) + (2LL << b) - 3);
  if (sum == s) return 0;
  for (int c = !!b; c <= a + b; c ++) {
    if ((sum + c) & 1) continue;
    res += !b && c < a && __builtin_popcountll(sum + c) == c && (1LL << a) > sum + c;
    if (!c || !b) continue;
    if (sum + c < (1LL << b)) continue;
    LL tmp = (sum + c - (1LL << b)) >> 1;
    cur ++; len = 0;
    memset(tab, 0, sizeof tab);
    for (; tmp; tmp >>= 1) tab[++ len] = tmp & 1;
    res += dfs(len, c - 1, 0);
  }
  return res;
}

int main() {
  LL ans = 0;
  scanf("%lld", &s);
  for (int i = 0; (1LL << i) <= s; i ++)
    for (int j = 0; (1LL << j) <= s; j ++) ans += calc(i, j);
  printf("%lld\n", ans);
  return 0;
}

#include<stdio.h>
#include<algorithm>
using namespace std;
long long n, Res;
void Do(int d1, int d2){
    long long be = (1ll<<d2), ed = (1ll << (d2+1)) - 1, ss, mid, t;
    int i;
    while(be<=ed){
        ss = 0;
        mid = (be+ed)/2;
        t = mid;
        for(i=0;i<=d2-d1;i++){
            ss += t;
            t/=2;
        }
        if(ss == n){
            Res++;
            return;
        }
        if(ss < n)be = mid + 1;
        else ed = mid - 1;
    }
}
long long GetMin(long long a, int d){
    if(d==0)return a;
    return GetMin(a*2,d-1)+a;
}
long long GetMax(long long a, int d){
    if(d==0)return a;
    return GetMax(a*2+1,d-1)+a;
}
int C[100], a1, a2;
long long S[100], D[21][21][10000];
long long Calc(int d, long long g){
    if(d==0){
        if(!g)return 1;
        return 0;
    }
    if(S[d] < g)return 0;
    if(d<=20 && g<10000){
        if(D[min(a1,d)][min(a2,d)][g]!=-1)return D[min(a1,d)][min(a2,d)][g];
    }
    long long s = Calc(d-1,g);
    long long t = (1ll << d) - 1;
    if(C[d]>=1 && g>=t)s += Calc(d-1,g-t) * C[d];
    if(C[d]>=2 && g>=t*2)s += Calc(d-1,g-t*2);
    if(d<=20 && g<10000) D[min(a1,d)][min(a2,d)][g] = s;
    return s;
}
void Pro(long long g, int d1, int d2){
    int i;
    for(i=0;i<=50;i++)C[i]=0;
    for(i=1;i<=d1;i++)C[i]++;
    for(i=1;i<=d2;i++)C[i]++;
    a1 = min(d1,d2);
    a2 = max(d1,d2);
    for(i=1;i<=50;i++){
        S[i] = S[i-1] + ((1ll << i) - 1) * C[i];
    }
    Res += Calc(max(d1,d2), g);
}
void Do3(int d1, int d2, int d3){
    long long be = (1ll<<d1), ed = (1ll << (d1+1))-1, mid, M1, M2, r = -1, ss1 = 0, ss2 = 0, t;
    while(be<=ed){
        mid = (be+ed)/2;
        M1 = GetMin(mid*2,d2-d1-1) + GetMin(mid*2+1,d3-d1-1) + mid;
        M2 = GetMax(mid*2,d2-d1-1) + GetMax(mid*2+1,d3-d1-1) + mid;
        if(M1 <= n && n <= M2){
            r = mid;
            break;
        }
        if(n < M1)ed = mid - 1;
        else be = mid + 1;
    }
    if(r==-1)return;
    ss1 = 0, t = 1;
    int i;
    for(i=0;i<d2-d1;i++){
        ss1 += t;
        t*=2;
    }
    t=1;
    for(i=0;i<d3-d1;i++){
        ss2 += t;
        t*=2;
    }
    Pro(n - r - (r*2) *ss1 - (r*2+1) * ss2, d2-d1-1, d3-d1-1);
}
int main(){
    int i, j, k;
    for(i=0;i<21;i++)for(j=0;j<21;j++)for(k=0;k<10000;k++)D[i][j][k]=-1;
    scanf("%lld",&n);
    for(i=0;i<50;i++){
        for(j=i;j<50;j++){
            Do(i,j);
        }
    }
    for(i=0;i<50;i++){
        for(j=i+1;j<50;j++){
            for(k=i+1;k<50;k++){
                Do3(i,j,k);
            }
        }
    }
    printf("%lld\n",Res);
}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>
#define y1 y11
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define NAME ""
using namespace std;
typedef long long ll;
typedef long double ld;
const ld PI = acos(-1.0);
const int C = 58;
const int MAXN = 3001;
int c[3][3] = {{1, 0, 0}, {1, 1, 0}, {1, 2, 1}};
int gh(int x)
{
	int hh = 0;
	while ((1 << hh) <= x) hh++;
	return hh;
}
int tot[1000];
int an[101][101];
pair <ll, ll> pos[MAXN];
int pc = 0;
int main()
{
	ll s;
	cin >> s;
	ll ans = 0;
	for (int lc = 0; lc < C; lc++)
	{
		for (int rc = 0; rc < C; rc++)
		{
			ll vv = (1ll << (lc + 1)) + (1ll << (rc + 1)) - 3;
			ll ad = (1ll << rc) - 1;
			if (s < ad + vv) continue;
			ll a = (s - ad) / vv;
			ll b = s - a * vv - ad;
			ll f1 = 1, f2 = 0;
			pc = 1;
			pos[0] = mp(b, 1);
			for (int i = C; (i >= 0); i--)
			{
				int cn = 0;
				if (lc > i + 1) cn++;
				if (rc > i + 1) cn++;
				if (cn == 0) continue;
				ll cur = (1ll << (i + 1)) - 1;
				ll lf = (cur - (i + 1)) * 2;
				int dpc = pc;
				for (int j = 0; j < dpc; j++)
				{
					for (int cc = 1; (cc <= cn) && (cur * cc <= pos[j].first); cc++)
					{
						pos[pc++] = mp(pos[j].first - cur * cc, pos[j].second * c[cn][cc]);
					}
				}
				sort(pos, pos + pc);
				dpc = pc;
				if ((dpc == 0) || (pos[0].first > lf)) break;
				pc = 0;
				for (int i = 1; i < dpc; i++)
				{
					if (pos[i].first > lf) break;
					if (pos[i].first == pos[i - 1].first) pos[pc].second += pos[i].second;
					else pos[++pc] = pos[i];
				}
				pc++;
			}
			if ((pc != 0) && (pos[0].first == 0))
				ans += pos[0].second;
		}
	}
	cout << ans << endl;
    return 0;
}

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()

ll cnt1[65536];
ll popcount(ll x) {
	int rv = 0;
	while (x) {
		rv += cnt1[x & 65535];
		x /= 65536;
	}
	return rv;
}

map <pair<pll, pll>, ll> Mx;
ll getc(ll i, ll j, ll c, ll b) {
	if (i < j) swap(i, j);
	if (j == 0) {
		if (c >= (1ll << i)) return 0;
		if (popcount(c) == b) return 1;
		return 0;
	}

	auto u = mp(pll(i, j), pll(c, b));
	if (Mx.count(u)) return Mx[u];

	ll rv = 0;
	for (int x = 0; x <= 2; x++) {
		ll nc = c - x;
		if (b < x || nc < 0 || nc % 2 == 1) continue;

		ll v = getc(i - 1, j - 1, nc / 2, b - x);
		if (x == 1) rv += 2 * v;
		else rv += v;
	}
	return Mx[u] = rv;
}

int main() {
	ll S, i, j, k;
	for (i = 0; i < 65536; i++) {
		for (j = 0; j < 16; j++) if (i & (1ll << j)) cnt1[i]++;
	}

	scanf("%lld", &S);

	ll ans = 1; // Case 0

	// Case 1
	for (i = 1; i <= 50; i++) {
		ll x = (1ll << (i + 1)) - 1;
		ll a = S / x, b = S % x;
		if (a == 0) break;

		for (j = 0; j <= i; j++) {
			ll t = b + j;
			if (t % 2) continue;
			ans += getc(i, 0, t / 2, j);
		}
	}

	// Case 2
	for (i = 1; i <= 50; i++) {
		for (j = 1; j <= 50; j++) {
			ll x = (1ll << (i + 1)) + (1ll << (j + 1)) - 3;
			ll a = S / x, b = S % x;
			if (a == 0) break;

			ll tb = b - (1ll << j) + 1;
			if (tb < 0) continue;
			for (k = 0; k <= i + j - 2; k++) {
				ll nb = tb + k;
				if (nb % 2 == 0) ans += getc(i - 1, j - 1, nb / 2, k);
			}
		}
	}
	return !printf("%lld\n", ans);
}

// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;
#define int long long
const int N = (int) 60;
int p[N], dp[120][2], odp[120][2];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    p[0] = 1;
    for (int j = 1; j < N; ++j)
        p[j] = p[j - 1] << 1;
    int s, res = 0;
    cin >> s;
    for (int l = 0; l <= 52; ++l)
        for (int r = 0; r <= 52; ++r) {
            int mod = p[l + 1] + p[r + 1] - 3, mn = p[r] - 1;
            for (int choose = 0; choose <= l + r + 5; ++choose) {
                if (s - mn + choose < mod) continue;
                int len = max(l + 2, r + 2);
                int rem = (s - mn + mod) % mod;
                rem += choose;
                if (rem & 1) continue;
                memset(dp, 0, sizeof dp);
                dp[0][0] = 1;
                for (int j = 1; j <= len; ++j) {
                    for (int a = 0; a <= 1; ++a) for (int k = 0; k <= choose; ++k)
                        odp[k][a] = dp[k][a], dp[k][a] = 0;
                    for (int chose = choose; chose >= 0; --chose) for (int c = 0; c <= 1; ++c) for (int a = 0; a <= (j >= l? 0: 1); ++a)
                        for (int b = 0; b <= (j >= r? 0: 1); ++b) {
                            int nc = (a + b + c) >> 1;
                            int dig = (a + b + c) & 1;
                            if (dig == (rem >> j & 1)) {
                                dp[chose + a + b][nc] += odp[chose][c];
                            }

                        }
                }
                res += dp[choose][0];
            }
        }
    cout << res << endl;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (135)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
LL n,ans,f[2][N][2];
LL calc(int x,int lena,int lenb,LL sum){
	memset(f,0,sizeof(f)),f[1][0][0]=1;
	int now=0,pre=1;
	for(int i=0;(1ll<<i)<=sum;i++,now^=1,pre^=1){
		for(int j=0;j<=x;j++)
		f[now][j][0]=f[now][j][1]=0;
		for(int j=0;j<2;j++)
		if(i<lena||!j)
		for(int k=0;k<2;k++)
		if(i<lenb||!k)
		for(int l=0;l<2;l++){
			int S=j+k+l;
			if(((sum>>i)&1)^(S&1))continue;
			for(int m=0;m+j+k<=x;m++)
			f[now][m+j+k][S>>1]+=f[pre][m][l];
		}
	}
	return f[pre][x][0];
}
int main(){
	read(n);
	for(int i=0;i<=60;i++)
	for(int j=0;j<=60;j++){
		LL mul=(1ll<<i+1)+(1ll<<j+1)-3;
		if(n<mul)break;
		LL ret=n%mul-(1ll<<j)+1;
		if(ret<0)continue;
//		cout<<i<<" "<<j<<" faq"<<" "<<ret+i+j<<endl;
		for(int k=(ret&1);k<=i+j;k+=2)
			ans+=calc(k,i-1,j-1,(ret+k)>>1);
	}
	cout<<ans;
}

#include<bits/stdc++.h>
#define ll long long
#define die(x) memset(x,0,sizeof(x))
using namespace std;
ll n,m,mul[61],a[123],f[52][112][3],ans;

void DP_bin(ll res,ll h1,ll h2){
	for(ll had=0;had<=h1+h2;had++){//枚举用了几个
		if((res+had)%2==1)continue;
		die(f);
		f[0][0][0]=1;
		for(ll two=1;two<=max(h1,h2);two++){//枚举二次幂
			for(ll k=0;k<=had;k++){ //枚举当前用了几个
				for(ll p=0;p<=1;p++){//枚举进位p
					for(ll i=0;i<=1;i++)
					for(ll j=0;j<=1;j++){
						if(i&&(two>=h1-1))continue;
						if(j&&(two>=h2-1))continue;
						if((i+j+p)%2==((res+had)>>two)%2)f[two][k+i+j][(i+j+p)/2]+=f[two-1][k][p];
					}
				}
			}
		}
		ans+=f[max(h1,h2)][had][0];
	}
}

void do_it1(){
	ll base,res;
	for(ll h=1;h<=m;h++){
		base=(mul[h]-1)*(n/(mul[h]-1));
		if(!base)break;
		res=n-base;
		for(int i=h;i>=1;i--){
			if(mul[i]-1>res)continue;
			res=res-(mul[i]-1);
			if(!res)break;
		}
		if(!res)ans++;
	}
}

void do_it2(){
	ll base,res;
	for(ll h1=2;h1<=m;h1++)
	for(ll h2=2;h2<=m;h2++){
		base=(mul[h1]+mul[h2]-3)*( (n-mul[h2-1]+1)/(mul[h1]+mul[h2]-3) );
		if(!base)break;
		base=base+mul[h2-1]-1;
		res=n-base;
		DP_bin(res,h1,h2);
	}
}

int main(){
	cin>>n;
	m=log2(n)+1;

	mul[0]=1;
	for(int i=1;i<=m;i++)mul[i]=mul[i-1]*2;

	do_it1();
	do_it2();

	cout<<ans;
}

#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#include <assert.h>
#include <set>

using namespace std;

#define REP(i,fn_) for(int i=0; i<(fn_); ++i)
#define RREP(i,fn_) for(int i=(fn_)-1; i>=0; --i)
#define FOR(i,fa_,fb_) for(int i=(fa_); i<=(fb_); ++i)
#define RFOR(i,fa_,fb_) for (int i=(fa_); i>=(fb_); --i)
#define ALL(fc_) (fc_).begin(), (fc_).end()
#define MEMALL(fe_,fv_) memset((fe_), (fv_),sizeof((fe_)))
#define MEM(fe_,fv_,fs_) memset((fe_),(fv_), sizeof((fe_)[0])*(fs_))

typedef long long lld;
typedef vector<int> VI;
typedef vector<lld> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<lld,lld> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

const lld MOD=1e9+7;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }
template<typename T> void add(T &a, T b)
{
    a+=b;
    if(a<0)a+=MOD;
    if(a>=MOD)a-=MOD;
}
void FastIn(int &T)
{
	char C;bool F=0;
	for(;C=getchar(),C<'0'||C>'9';)if(C=='-')F=1;
	for(T=C-'0';C=getchar(),C>='0'&&C<='9';T=T*10+C-'0');
	F&&(T=-T);
}

int in() { int x; scanf("%d", &x); return x; }
lld lin() { lld x; scanf("%lld", &x); return x; }
double din(){double x; scanf("%lf",&x); return x;}
lld p2[64];
void initP2()
{
    p2[0]=1;
    FOR(i, 1, 63)
    {
        p2[i]=p2[i-1]*2;
    }
}

int countBitsBaseB(lld n, lld b)
{
    if(n==0)return 1;
    int ret=0;
    while(n)
    {
        ret++;
        n/=b;
    }

    return ret;
}

int count1(lld n)
{
    int ret=0;
    while(n)
    {
        ret+=n&1;
        n>>=1;
    }

    return ret;
}

lld c[1024][1024]={0};

void initC()
{
    REP(i,1024)
    {
        REP(j,i+1)
        {
            if(j==0||j==i)
            {
                c[i][j]=1;
            }
            else
            {
                c[i][j]=c[i-1][j-1];
                add(c[i][j], c[i-1][j]);
            }
        }
    }
}

bool IsPrime(int n)
{
    if(n<2)return false;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)return false;
    }

    return true;
}

void init()
{
    initP2();
    initC();
}

#define MAXN 310000
const lld INF=1000000000;

map<pair<int,lld>,int > sg;

int DFS(int sum, lld mask)
{
    if(sum==0) return 0;
    pair<int,lld> p=make_pair(sum,mask);

    if(sg.find(p)!=sg.end())
    {
        return sg[p];
    }

    vector<int> v;

    FOR(i,1,sum)
    {
        if(p2[i]&mask)continue;

        v.push_back(DFS(sum-i,mask|p2[i]));
    }

    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());

    int ans=-1;
  //  printf("v.size=%u",v.size());
    if(v.empty()||v[0]>0)ans=0;

    REP(i,(int)v.size()-1)
    {
        if(v[i]+1<v[i+1])
        {
            ans=v[i]+1;
            break;
        }
    }
    if(ans==-1)ans=v.back()+1;

    sg[p]=ans;
//    printf("ans=%d\n",ans);
    //printf("sg.size()=%u\n",sg.size());
    return ans;
}

lld dp[64][2][128]={0};

lld calc(int deepL,int deepR, int totalBits,lld sum)
{
    if(p2[deepL-1]+p2[deepR-1]>sum)return 0;
    if(p2[deepL]-1+p2[deepR]-1<sum)return 0;
    //printf("deepL=%lld,deepR=%lld,bits=%lld,sum=%lld\n",
      //      deepL,deepR,totalBits,sum);

    int len=max(deepL,deepR);
    RREP(i,63)
    {
        if(p2[i]&sum)
        {
            len=i+1;
            break;
        }
    }
    if(max(deepL,deepR)>len)return 0;

    REP(i,len+1)
    {
            REP(mask,2)
        {
        REP(j,totalBits+1)
            {
                dp[i][mask][j]=0;
            }
        }
    }
    dp[0][0][0]=1;
    REP(i,len)
    {
            REP(mask,2)
        {
        REP(j,totalBits+1)
            {
                if(dp[i][mask][j]==0)continue;
                REP(add,4)
                {
                    int add0=(add&1)>0;
                    int add1=(add&2)>0;
                    if(i+1>deepL && add0){continue;}
                    if(i+1==deepL&& add0==0){continue;}
                    if(i+1==deepL-1 && add0==1){continue;}

                    if(i+1>deepR && add1){continue;}
                    if(i+1==deepR && add1==0){continue;}
                    if(i+1==deepR-1&& add1 == 0){continue;}

                    if(add0+add1+j>totalBits)continue;
                    int tot=mask+add0+add1;
                    int bb=tot&1;
                    if(((sum>>i)&1)==bb)
                    {
                    dp[i+1][tot>>1][j+add0+add1]+=dp[i][mask][j];
                    }
                }
            }
        }
    }

    //cout<<"dp="<<dp[len][totalBits][0]<<endl;
    return dp[len][0][totalBits];
}

int main()
{
    init();
    //freopen("a.in","r",stdin);
    lld s; cin>>s;
    clock_t start=clock();
    lld ans=0;
    REP(L,64)
    {
        if(p2[L+1]-3>s)break;
        REP(R,64)
        {
            lld down=p2[L+1]+p2[R+1]-3;
            if(down>s){break;}
            lld x=(s-(p2[R]-1))/down;
            if(x<1)continue;
            lld newS=s-down*(x-1);
            if(newS<1)continue;
            REP(bits,L+R+2+1)
            {
                if(((newS+1+bits)&1)==0)
                {
                    ans+=calc(L+1,R+1,bits,(newS+1+bits)/2);
                }
            }
        }
    }

    cout<<ans<<endl;
    clock_t end=clock();
//cout<<CLOCKS_PER_SEC<<endl;
    //printf("%f ms\n",(double)(end-start)/CLOCKS_PER_SEC);
    return 0;
}
/*
 */

#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxd=58;
ll f[maxd+10][maxd*2+10][2],two[maxd+10];
int i,j,k,l,t,n,m,a,b;
ll x,y,now,s,ans;
void work(int a,int b,ll now,int cnt){
	int i,j,k,l,r,t,s,d,mx=max(a-2,b-1)+2;
	fo(i,0,maxd+2)
		fo(j,0,cnt)
			f[i][j][0]=f[i][j][1]=0;
	f[0][0][0]=1;
	fo(i,0,mx-1){
		if ((now&two[i])) d=1;else d=0;
		fo(j,0,cnt)
			fo(t,0,1)
				if (f[i][j][t]){
					fo(l,0,1)
						fo(r,0,1){
							if (l&&i>a-2) continue;
							if (r&&i>b-1) continue;
							if (!r&&i==b-1) continue;
							s=l+r+t;
							k=s/2;s=s%2;
							if (s!=d) continue;
							f[i+1][j+l+r][k]+=f[i][j][t];
						}
				}
	}
	ans+=f[mx][cnt][0];
}
int main(){
	two[0]=1;
	fo(i,1,maxd+1) two[i]=two[i-1]*2;
	scanf("%I64d",&s);
	fo(a,0,maxd)
		fo(b,0,maxd){
			y=two[a+1]+two[b+1]-3;
			x=s/y;
			while (x){
				now=s-x*y;
				if (now>two[a]-a+two[b+1]-b-3){
					x=0;
					break;
				}
				if (now>=two[b]-1&&now<=two[a]-a+two[b+1]-b-3) break;
				x--;
			}
			if (!x) continue;
			now=s-x*y;
			fo(i,0,maxd*2)
				if ((now+i)%2==0) work(a,b,(now+i)/2,i);
		}
	printf("%I64d\n",ans);
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr ll B = 50;
ll dp[2][B+1][B+B+1];

ll solve(ll sum, ll bits, ll dmax, ll emax) {
	ll lastbit = 1;
	while ((1LL<<lastbit) <= sum) ++lastbit;

	if (sum > (1LL << (dmax+1)) + (1LL << (emax+1LL)) - 2LL)
		return 0LL;

	for (int b = 0; b <= bits; ++b)
		dp[0][0][b] = dp[1][0][b] = 0;
	dp[0][0][0] = 1;

	for (int b = 1; b < lastbit; ++b) {
		sum >>= 1;
		for (int bt = 0; bt <= bits; ++bt) {
			// turn nothing on
			dp[0][b][bt] = dp[sum&1][b-1][bt];
			dp[1][b][bt] = 0; // reset for ease
			// turn d on
			if (bt > 0 && b <= dmax) dp[1^sum&1][b][bt] += dp[1^sum&1][b-1][bt-1];
			// turn e on
			if (bt > 0 && b <= emax) dp[1^sum&1][b][bt] += dp[1^sum&1][b-1][bt-1];
			// turn d,e on
			if (bt > 1 && b <= dmax && b <= emax)
				dp[1][b][bt] += dp[sum&1][b-1][bt-2];
		}
	}
	ll r = dp[0][lastbit - 1][bits];
	return r;
}

int main() {
	ll s, ans = 0;
	cin >> s;

	for (ll d = 1; d <= B; ++d)
		for (ll e = 1; e <= B; ++e) {
			ll G = ((1LL << d) + (1LL << e) - 3LL);
			ll x = s/G;
			if (x < 1) continue;
			ll r = s - x * G;
			r -= ((1LL << (e - 1)) - 1LL);
			if (r < 0) continue;
			if (r > (1LL << d) + (1LL << e) - d - e - 2LL)
				continue;
//			cerr << "Trying " << d << ' ' << e << ", making " << r << ", starting at " << x << endl;
			for (ll bits = r % 2; bits < max(2LL, d + e - 2LL); bits += 2)
				ans += solve(r+bits, bits, d-2, e-2);
		}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL s;

// L + 1 位的二进制数 a
// R + 1 位的二进制数 b

// a 的第 L + 1 位和 b 的第 R + 1 位都是 1
// a 的第 L 位是 0；b 的第 R 位是 1
// a + b = s
// popcount(a) + popcount(b) = t

LL solve(int L, int R, int t, LL s) {
	LL dp[55][110][2] = {};
	dp[0][0][0] = 1;
	for (int i = 0; i <= 51; ++i)
		for (int j = 0; j <= i * 2 && j <= t; ++j)
			for (int k = 0; k < 2; ++k)
				if (dp[i][j][k])
					for (int a = 0; a < 2; ++a) {
						if ((i == L - 1|| i > L) && a) continue;
						if (i == L && !a) continue;
						for (int b = 0; b < 2; ++b) {
							if ((i == R - 1 || i == R) && !b) continue;
							if (i > R && b) continue;
							if ((a + b + k & 1) == (s >> i & 1))
								dp[i + 1][j + a + b][a + b + k >= 2] += dp[i][j][k];
						}
					}
	return dp[52][t][0] + dp[52][t][1];
}

int main() {
	cin >> s;
	LL ans = 0;
	for (int L = 0; L <= 50; ++L)
		for (int R = 0; R <= 50; ++R) {
			LL x = (s + R + 1 - (1LL << R)) / ((1LL << L + 1) + (1LL << R + 1) - 3);
			if (x == 0) break;
			LL tmp = s - (x - 1) * ((1LL << L + 1) + (1LL << R + 1) - 3) + 1;
			for (int t = tmp & 1 ? 3 : 2; t <= L + R + 2; t += 2)
				ans += solve(L, R, t, (tmp + t) / 2);
		}
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
#define go(u) for(register int i=fi[u],v=e[i].to;i;v=e[i=e[i].nx].to)
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=52;
typedef long long ll;
int m,p;ll n,ans,mi[N],f[N][2*N][2];
inline ll sub(ll a,ll b){return a>=b?a-b:a;}
inline ll calc(ll s,int a,int b,int t){
	if(max(a,b)+1<log2(s))return 0;
    memset(f[p],0,sizeof f[p]);f[p][0][0]=1;
    fp(i,1,log2(s)+1){
        int d=(s>>i)&1;p^=1;memset(f[p],0,sizeof f[p]);
        fp(j,0,2*i-2)fp(k,0,1)if(f[p^1][j][k])
            fp(x,0,1)if(!x||i<a)fp(y,0,1)if(!y||i<b)
                if((k+x+y)%2==d)f[p][j+x+y][(k+x+y)/2]+=f[p^1][j][k];
    }
    return f[p][t][0];
}
int main(){
    #ifndef ONLINE_JUDGE
        file("s");
    #endif
    scanf("%lld",&n);mi[0]=1;ll x,ret;
    while(mi[m-1]<=n)mi[m+1]=mi[m]<<1,++m;--m;
    fp(i,1,m)if((x=n/(mi[i]-1))>0){
        ret=n-x*(mi[i]-1);
        fd(j,i-1,0)ret=sub(ret,mi[j]-1);
        if(!ret)++ans;
    }
    fp(i,1,m)for(int j=1;mi[j]-1<=n;++j)
        if((x=(n-mi[j]+1)/(mi[i+1]+mi[j+1]-3))>0){
            ret=(n-mi[j]+1)-x*(mi[i+1]+mi[j+1]-3);
            if(!ret){++ans;continue;}
            if(i==1&&j==1){ans+=ret==5*x+1;continue;}
            fp(k,1,i+j)if(~(ret+k)&1)
                ans+=calc(ret+k,i,j,k);
        }
	printf("%lld",ans);
return 0;
}

//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

int n1, n2, ticks, last[52][3][105];
ll target, DP[52][3][105];

ll dp(int i, int carry, int bitcount){

    if(bitcount < 0)    return 0;
    if(i == 51) return (carry == 0 && bitcount == 0);
    ll &ans = DP[i][carry][bitcount];
    if(last[i][carry][bitcount] == ticks)   return ans;

    ans = 0;
    int dig = ((target>>i)&1);

    //both zero
    if(carry == dig)
        ans += dp(i+1, 0, bitcount);

    //both 1
    if(carry == dig && i <= n1 && i <= n2 && bitcount >= 2)
        ans += dp(i+1, 1, bitcount-2);

    //1-0
    if(carry != dig && i <= n1 && bitcount >= 1)
        ans += dp(i+1, carry, bitcount-1);

    //0-1
    if(carry != dig && i <= n2 && bitcount >= 1)
        ans += dp(i+1, carry, bitcount-1);

    last[i][carry][bitcount] = ticks;
    return ans;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll S;
    cin>>S;

    //d1 and d2 are lengths of paths to left and right of LCA
    ll ans = 0;
    for(int d1=0;d1<=50;d1++)
        for(int d2=0;d2<=50;d2++)
            for(int bitcount=0;bitcount<=100;bitcount++){

                ll lca_multiplier = (1LL<<(d1+1)) + (1LL<<(d2+1)) - 3;
                if(S < lca_multiplier)  continue;

                target = S % lca_multiplier;
                target -= (1LL<<d2) - 1;
                if(target < 0)  continue;

                target += bitcount;
                if(target % 2 == 1) continue;

                n1 = d1-1;
                n2 = d2-1;
                ticks++;
                ll temp = dp(1, 0, bitcount);
                ans += temp;
            }

    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    void clear() { *this = hash_map_t(mod); }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 55;

ll f[N][N * 2][2], pw[N];
ll s, ans;

int main() {
    read(s);
    pw[0] = f[0][0][0] = 1;
    for(register int i = 1; i <= 50; i++) pw[i] = pw[i - 1] + pw[i - 1];
    for(register int a = 0; a <= 49; a++) {
        for(register int b = 0; b <= 49; b++) {
            if(!a && !b) { ++ans; continue; }
            ll x = (s - pw[b] + 1) / (pw[a + 1] + pw[b + 1] - 3);
            if(x <= 0) break;
            if(!a && b == 1) { ans += (s == x * 3 + 1); continue; }
            if(!b && a == 1) { ans += (s == x * 3); continue; }
            if(a == 1 && b == 1) { ans += (s == 5 * x + 1); continue; }
            // fprintf(stderr, "a = %d, b = %d, %I64d, %I64d\n", a, b, s - pw[b + 1] + 1, pw[a + 1] + pw[b + 1] - 3);
            ll last = s - (pw[a + 1] + pw[b + 1] - 3) * x - pw[b] + 1;
            if(!last) { ++ans; continue; }
            for(register int i = 0; i <= a + b - (a != 0) - (b != 0); i++) {
                ll now = last + i;
                if(now & 1) continue;
                int lim = max(a - 1, b - 1) + 1;
                if(now >= (1ll << (lim + 1))) continue;
                for(register int j = 1; j <= lim; j++) {
                    int zt = (now >> j) & 1;
                    memset(f[j], 0, sizeof(f[j]));
                    for(register int k = 0; k <= i; k++) {
                        for(register int t = 0; t <= 1; t++) {
                            if(f[j - 1][k][t]) {
                                for(register int x = 0; x <= 1; x++) {
                                    for(register int y = 0; y <= 1; y++) {
                                        if(x && j >= a) continue;
                                        if(y && j >= b) continue;
                                        if(((t + x + y) & 1) ^ zt) continue;
                                        f[j][k + x + y][(t + x + y) >> 1] += f[j - 1][k][t];
                                    }
                                }
                            }
                        }
                    }
                }
                ans += f[lim][i][0];
                // if(f[lim][i][0]) fprintf(stderr, "i = %d, a = %d, b = %d, val = %I64d, x = %I64d, now = %I64d\n", i, a, b, f[lim][i][0], x, now);
            }
            // fprintf(stderr, "a = %d, b = %d, ans = %I64d\n", a, b, ans);
        }
    }
    print(ans, '\n');
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll dp[60][120][2];
ll solve(ll sum, int lena, int lenb, int bit) {
	memset(dp, 0, sizeof(dp));
	int i;
	dp[0][0][0] = 1;
	for(i = 1; 1LL << i <= sum; ++i) {
		int d = sum >> i & 1;
		for(int j = 0; j <= bit; ++j)
			for(int x = 0; x < 2; ++x) if(!x || i < lena)
				for(int y = 0; y < 2; ++y) if(!y || i < lenb) {
					if((x + y) % 2 == d) dp[i][j + x + y][x + y >> 1] += dp[i - 1][j][0];
					else dp[i][j + x + y][x + y + 1 >> 1] += dp[i - 1][j][1];
				}
	}
	return dp[i - 1][bit][0];
}
int main() {
	cin >> n;
	ll ans = 0;
	for(int i = 0; i <= 58; ++i) {
		for(int j = 0; j <= 58; ++j) {
			ll x = (n - (1LL << j) + 1) / ((1LL << i + 1) + (1LL << j + 1) - 3);
			if(!x) continue;
			ll res = n - (1LL << j) + 1 - x * ((1LL << i + 1) + (1LL << j + 1) - 3);
			if(!res) {
				++ans;
				continue;
			}
			for(int k = 1; k <= i + j - (!i) - (!j); ++k)
				if((res + k) % 2 == 0)
					ans += solve(res + k, i, j, k);
		}
	}
	cout << ans;
	return 0;
}

#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define reg register
	#define Rint register int
	#define FOR(i,a,b) for(register int i=(a),ed_##i=(b);i<=ed_##i;++i)
	#define ROF(i,a,b) for(register int i=(a),ed_##i=(b);i>=ed_##i;--i)
	#define FORit(templ,arr,i,a,b) for(register templ *i=(arr)+(a),*ed_##i=(arr)+(b)+1;i!=ed_##i;++i)
	#define ROFit(templ,arr,i,a,b) for(register templ *i=(arr)+(a),*ed_##i=(arr)+(b)-1;i!=ed_##i;--i)
	#define GO(x,p,e,i,v) for(register int i=p[x].head,v;i;i=e[i].link)
	#define MEM(x,v) memset(x,v,sizeof(x))
	#define fir first
	#define sec second
	#define pq priority_queue
	#define MP make_pair
	typedef long long LL;
	typedef double DB;
	typedef pair<int,int> PII;
	#define Templ(T) template<typename T>
	inline LL read(){
		reg LL ans=0,f=1;reg char c=getchar();
		while(!isdigit(c)){ f^=(c=='-'); c=getchar(); }
		for(;isdigit(c);c=getchar()) ans=ans*10+c-'0'; return f?ans:-ans;
	}
	Templ(_Tp) inline int chkmin(_Tp &x,_Tp y){ return x>y?x=y,1:0; }
	Templ(_Tp) inline int chkmax(_Tp &x,_Tp y){ return x<y?x=y,1:0; }
	#define using_mod
	const int mod = 998244353, MX = 50;
	#ifdef using_mod
	inline void inc(int &x,const int &y){ x+=y; if(x>=mod) x-=mod; }
	inline int ksm(int x,LL y){ int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res;}
	#endif
	Templ(_Tp) inline _Tp gcd(_Tp x,_Tp y){ return y?gcd(y,x%y):x; }
	#define FILE(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
	#define PBTXDY
}
using namespace my_std;

LL n, f[60][120][2];
//inline int count1(LL x){ return x ? count1(x & (x - 1)) + 1 : 0; }
#define count1(x) (__builtin_popcountll(x))

inline LL work1(){
	reg LL ans = 0, x, res;
	FOR(i, 1, MX){
		x = n / ((1ll << i) - 1);
		if(!x) break;
		res = n - x * ((1ll << i) - 1);
		FOR(j, 0, i - 1) if( !((res + j) & 1) && count1(res + j) == j) ++ans;
	}
	return ans;
}

inline LL work2(){
	reg LL ans = 0, x, res;
	FOR(l, 2, MX) FOR(r, 2, MX){
		x = (n - (1ll << (r - 1)) + 1) / ((1ll << r) + (1ll << l) - 3);
		if(!x) break;
		res = n - (1ll << (r - 1)) + 1 - x * ((1ll << r) + (1ll << l) - 3);
		FOR(cnt, 0, l + r - 4) if(!((res + cnt) & 1)){
			FOR(i, 0, max(l, r)) FOR(j, 0, min(cnt, i << 1)) f[i][j][0] = f[i][j][1] = 0;
			f[0][0][0] = 1;
			FOR(i, 1, max(l, r)) FOR(j, 0, min(cnt, (i - 1) << 1)){
				FOR(k, 0, 1) FOR(a, 0, 1) FOR(b, 0, 1){
					if(i >= l - 1 && a) continue;
					if(i >= r - 1 && b) continue;
					if( ((k + a + b) & 1) == (((res + cnt) >> i) & 1) ){
						f[i][j + a + b][(k + a + b) >> 1] += f[i - 1][j][k];
					}
				}
			}
			ans += f[max(l, r)][cnt][0];
		}
	}
	return ans;
}

int main(){
	n = read();
	return printf("%lld\n", work1() + work2()), 0;
}

#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=210;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
LL f[N][N][2];
LL calc (int a,int b,LL s,int c)//s=p+q,c=cntp+cntq
{
    int m=max (max (a-1,b),(int)log2 (s)+1);
    for (int i=0; i<=m; i++)
        for (int j=0; j<=c; j++)
            f[i][j][0]=f[i][j][1]=0;
    for (int x=0; x<=1; x++)
        for (int y=0; y<=1; y++)
        {
            if (b==1&&!y) continue;
            if (((x+y)&1)!=(s&1)) continue;
            if (a<=1&&x) continue;
            if (b<=0&&y) continue;
            ++f[0][x+y][x&&y];
        }
    for (int i=0; i< m; i++)
    {
        LL d=s>>(i+1)&1;
        for (int j=0; j<=c; j++)
            for (int t=0; t<=1; t++) if (f[i][j][t])
                for (int x=0; x<=1; x++)
                    for (int y=0; y<=1; y++)
                    {
                        int g=x+y+t;
                        if (i+1==b-1&&!y) continue;
                        if ((g&1)!=d) continue;
                        if (i+1> a-2&&x) continue;
                        if (i+1> b-1&&y) continue;
                        f[i+1][j+x+y][g>=2]+=f[i][j][t];
                    }
    }
    return f[m][c][0];
}
LL calc (LL x)
{
    LL ans=x<<1;
    while (x) ans-=x&1,x>>=1;
    return ans;
}
int a[N],b[N];
LL lca (LL x,LL y)
{
    int n=0,m=0;
    while (x) a[n++]=x&1,x>>=1; reverse (a,a+n);
    while (y) b[m++]=y&1,y>>=1; reverse (b,b+m);
    chkmin (n,m);
    LL z=0;
    for (int i=0; i< n; i++)
        if (a[i]==b[i]) z=z<<1|a[i];
        else break;
    return z;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
    LL s; sc(s);
    LL ans=0;
    for (int a=0; a< 50; a++)
        for (int b=0; b< 50; b++)
        {
            LL v=((1LL<<(a+1))+(1LL<<(b+1))-3),z=s/v;
            if (!z) continue;
            if ((int)log2 (z)+1+max (a,b)> 50) continue;
            LL k=s-v*z;
            for (int c=0; c<=a+b; c++)//cntp+cntq
                if (!((k+c)&1)) ans+=calc (a,b,(k+c)>>1,c);
        }
    pr(ans);

    return 0;
}

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define sz(a) ((int)(a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))
using namespace std;
typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1.01e9;
const dbl eps = 1e-9;
const int L = 55;
ll d[66][111][66][66];
ll RES = 0;
void solve2(ll s)
{
    memset(d, 0, sizeof d);
    for (int l1 = 0; l1 < L; ++l1)
    {
        for (int l2 = 0; l2 < L; ++l2)
        {
            ll xs = 1;
            for (int i = 1; i <= l1; ++i) xs += pw(i);
            for (int i = 1; i <= l2; ++i) xs += pw(i);
            if (xs > s) break;
            ll rem = s % xs;
            ll smallest = pw(l2) - 1;
            ll largest = 0;
            for (int i = 1; i < l1; ++i) largest += pw(i) - 1;
            for (int i = 1; i <= l2; ++i) largest += pw(i) - 1;
            if (!(smallest <= rem && rem <= largest)) continue;
            for (int i1 = 0; i1 <= l1; ++i1) for (int i2 = 0; i2 <= l2; ++i2) d[0][0][i1][i2] =1;
            for (int i = 0; i < L; ++i)
            {
                int want = (rem >> i) & 1;
                int mn1 = 0;
                int mx1 = 0;
                if (i <= l1 - 2) mx1 = l1 - 1 - i;
                int mn2 = 0;
                int mx2 = 0;
                if (i <= l2 - 2) mn2 = 1, mx2 = l2 - i;
                else if (i == l2 - 1) mn2 = 1, mx2 = 1;
                for (int i1 = mn1; i1 <= mx1; ++i1) for (int i2 = mn2; i2 <= mx2; ++i2)
                for (int per = i > 0 ? (i1 + i2) / 2 : 0; per <= min(111, i1 + i2 + 10); ++per)
                {
                    int sum = per + i1 + i2;
                    if (sum % 2 != want) continue;
                    if (i > 0)
                    {
                        forn(di, 2) forn(dj, 2)
                        {
                            d[i + 1][sum / 2][i1][i2] += d[i][per][i1 + di][i2 + dj];
                        }
                    }
                    else
                    {
                        d[i + 1][sum / 2][i1][i2] += d[i][per][i1][i2];
                    }
                }
            }
            RES += d[L][0][0][0];

            for (int i = L - 1; i >= 0; --i)
            {
                int want = (rem >> i) & 1;
                int mn1 = 0;
                int mx1 = 0;
                if (i <= l1 - 2) mx1 = l1 - 1 - i;
                int mn2 = 0;
                int mx2 = 0;
                if (i <= l2 - 2) mn2 = 1, mx2 = l2 - i;
                else if (i == l2 - 1) mn2 = 1, mx2 = 1;
                for (int i1 = mn1; i1 <= mx1; ++i1) for (int i2 = mn2; i2 <= mx2; ++i2)
                for (int per = i > 0 ? (i1 + i2) / 2 : 0; per <= min(111, i1 + i2 + 10); ++per)
                {
                    int sum = per + i1 + i2;
                    if (sum % 2 != want) continue;
                    if (i > 0)
                    {
                        forn(di, 2) forn(dj, 2)
                        {
                            d[i + 1][sum / 2][i1][i2] -= d[i][per][i1 + di][i2 + dj];
                        }
                    }
                    else
                    {
                        d[i + 1][sum / 2][i1][i2] -= d[i][per][i1][i2];
                    }
                }
            }
        }
    }
}
ll smart(ll s)
{
    RES = 0;
    solve2(s);
    return RES;
}
ll stupid(ll s)
{
    ll res = 0;
    for (int i = 1; i <= s; ++i) for (int j = i; j <= s; ++j)
    {
        ll sum = 0;
        int x = i, y = j;
        while (x != y)
        {
            if (x > y)
            {
                sum += x;
                x >>= 1;
            }
            else
            {
                sum += y;
                y >>= 1;
            }
        }
        sum += x;
        if (s == sum)
        {
            res++;
        }
    }
    return res;
}
int main()
{
    if (0)
    {
        for (int i = 3; i <= 1000; ++i)
        {
            eprintf("i = %d\n", i);
            ll r1 = stupid(i);
            ll r2 = smart(i);
            if (r1 != r2)
            {
                eprintf("fail %d :: %I64d vs %I64d\n", i, r1, r2);
                return 0;
            }
        }
    }
    ll s;
    scanf("%I64d", &s);
    ll res = smart(s);
    printf("%I64d\n", res);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll read(){
	ll x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}

ll n,ans;
ll f[140][2],g[140][2];

ll dp(int one,int lena,int lenb,ll sum){
	for (int j=0;j<=one;++j)
		f[j][0]=f[j][1]=0;
	f[0][0]=1;
	for (int i=0;(1ll<<i)<=sum;++i){
		for (int j=0;j<=one;++j)
			g[j][0]=f[j][0],f[j][0]=0,
			g[j][1]=f[j][1],f[j][1]=0;
		for (int j=0;j<=1;++j) if (i<lena||!j)
			for (int k=0;k<=1;++k) if (i<lenb||!k)
				for (int l=0;l<=1;++l){
					int d=j+k+l;
					if (((sum>>i)&1)^(d&1)) continue;
					for (int m=0;m+j+k<=one;++m)
						f[m+j+k][d>>1]+=g[m][l];
				}
	}
	return f[one][0];
}

int main(){
	n=read();
	for (int i=0;i<=58;++i)
		for (int j=0;j<=58;++j){
			ll mul=(1ll<<i+1)+(1ll<<j+1)-3;
			if (n<mul) break;
			ll now=n%mul-(1ll<<j)+1;
			if (now<0) continue;
			int cnt=i+j;
			for (int k=now&1;k<=cnt;k+=2){
				ll tot=now+k;
				ans+=dp(k,i-1,j-1,tot>>1);
			}
		}
	printf("%I64d\n",ans);
}

#include<bits/stdc++.h>
#define o 1000005
#define re register ll
#define ll long long
#define g0(a) memset(a,0,sizeof(a))
#define gc(a,b) memcpy(a,b,sizeof(a))
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define REP(i,a,b) for(ll i=a;i>=b;i--)
#define pa pair<ll,ll>
#define mpp make_pair
#define s1 first
#define s2 second
using namespace std;
inline ll read()
{
	register ll data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar();
	return data*w;
}
const ll N=53;
ll f[N][N<<1][2];
int main()
{
	ll s=read(),ans=0;
	for(ll h=1;(1ll<<h)-1<=s;h++)
	{
		ll x=s/((1ll<<h)-1),ret=s%((1ll<<h)-1);
		REP(j,h-1,1)if(ret>=(1ll<<j)-1)ret-=(1ll<<j)-1;
		ans+=(!ret);
	}
	for(ll h0=1;(1ll<<h0+1)-1<=s;++h0)
	{
		for(ll h1=1;(1ll<<h1+1)+(1ll<<h0+1)-3+(1ll<<h1)-1<=s;++h1)
		{
			ll A=s-((1ll<<h1)-1),B=(1ll<<h1+1)+(1ll<<h0+1)-3;
			ll x=A/B,ret=A%B;
			if(!ret){++ans;continue;}
			if(h0==1&&h1==1){ans+=(s==5*x+1);continue;}
			for(ll n=1;n<=h0+h1-2;n++)
			{
				ll C=ret+n,L=log2(C);
				if(C&1)continue;
				memset(f[0],0,sizeof(f[0]));f[0][0][0]=1;
				for(ll i=1;i<=L;i++)
				{
					memset(f[i],0,sizeof(f[i]));
					for(ll j=0;j<=2*i-2&&j<=n;j++)
					FOR(k,0,1)
						if(f[i-1][j][k])
						FOR(x,0,(i<h0))
							FOR(y,0,(i<h1))
								if((k+x+y&1)==(C>>i&1))f[i][j+x+y][k+x+y>>1]+=f[i-1][j][k];
				}
				ans+=f[L][n][0];
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}

//test
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
typedef double db;
ll bit[65],f[65][120][2];//在{2,2^2,2^3...2^h1}∪{2,2^2,...2^h2}之间选tot个数，其和==s，
inline ll dp(ll s,int tot,int h1,int h2){//应该是{2-1,2^2-1,2^3-1...2^h1-1}∪{2-1,2^2-1,...2^h2-1},但是已经把减一移过去s了
	memset(f,0,sizeof f);f[0][0][0]=1;//在{2，2^2...}中选，2^min(h1,h2)和之前的数可以选两个，f[i][j][k]表示做到第i个数，之前（包括i）选了j个数，对下一位的进位为k
	int ed=log2(s);//能选的最大的数
	rep(i,1,ed){
		ll d=(s>>i)&1;
		int ed=i*2-2;//在 i之前最多能选多少个
		rep(j,0,ed) rep(k,0,1)/*上一位是否进位*/rep(p1,0,1)/*左链是否向右走即是否选一个2^i*/rep(p2,0,1)/*右链同理*/if((i<h1||p1==0)&&(i<h2||p2==0)&& (p1+p2+k)%2==d)/*因为x的左右儿子即2^h1和2^h2是肯定要选的*/
		f[i][j+p1+p2][(k+p1+p2)/2]+=f[i-1][j][k];
	}
	return f[ed][tot][0];
}
int main(){
	ll x,s,res,ans=0;
	int ed=0;
	scanf("%lld",&s);
	bit[0]=1;while(bit[ed]<=s) bit[++ed]=bit[ed-1]<<1;
	rep(i,1,ed){//统计一条链的情况
		if(bit[i]-1>s) break;
		x=s%(bit[i]-1);
		for(int j=i;j>=1;--j) if(x>=bit[j]-1) x-=bit[j]-1;
		if(!x) ++ans;
	}
	rep(h1,1,ed-1){//统计有分叉的情况
		for(int h2=1;bit[h2]-1<=s&&h2<ed;++h2){//枚举两边的链长 h1  h2
			x=(s-bit[h2]+1)/(bit[h1+1]+bit[h2+1]-3);
			if(x>0){
				res=(s-bit[h2]+1)%(bit[h1+1]+bit[h2+1]-3);
				if(res==0){//不用向右走
					++ans;continue;
				}
				if(h1==1&&h2==1){//x只选了左儿子x*2和右儿子x*2+1 ,所以是x*5+1
					ans+=(s==x*5+1);continue;
				}//有余数说明在某些点要往右走
				rep(i,1,h1+h2) if((res+i)%2==0) ans+=dp(res+i,i,h1,h2);//相当于把减掉的 i个一挪到等式另一边变成加 i个一
			}
		}
	}
	printf("%lld",ans);
}

#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    void clear() { *this = hash_map_t(mod); }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 55;

ll f[N][N * 2][2], pw[N];
ll s, ans;

int main() {
    read(s);
    pw[0] = f[0][0][0] = 1;
    for(register int i = 1; i <= 50; i++) pw[i] = pw[i - 1] + pw[i - 1];
    for(register int a = 0; a <= 49; a++) {
        for(register int b = 0; b <= 49; b++) {
            if(!a && !b) { ++ans; continue; }
            ll x = (s - pw[b] + 1) / (pw[a + 1] + pw[b + 1] - 3);
            if(x <= 0) break;
            // if(!a && b == 1) { ans += (s == x * 3 + 1); continue; }
            // if(!b && a == 1) { ans += (s == x * 3); continue; }
            // if(a == 1 && b == 1) { ans += (s == 5 * x + 1); continue; }
            // fprintf(stderr, "a = %d, b = %d, %I64d, %I64d\n", a, b, s - pw[b + 1] + 1, pw[a + 1] + pw[b + 1] - 3);
            ll last = s - (pw[a + 1] + pw[b + 1] - 3) * x - pw[b] + 1;
            if(!last) { ++ans; continue; }
            for(register int i = 0; i <= a + b - (a != 0) - (b != 0); i++) {
                ll now = last + i;
                if(now & 1) continue;
                int lim = max(a - 1, b - 1) + 1;
                if(now >= (1ll << (lim + 1))) continue;
                for(register int j = 1; j <= lim; j++) {
                    int zt = (now >> j) & 1;
                    memset(f[j], 0, sizeof(f[j]));
                    for(register int k = 0; k <= i; k++) {
                        for(register int t = 0; t <= 1; t++) {
                            if(f[j - 1][k][t]) {
                                for(register int x = 0; x <= 1; x++) {
                                    for(register int y = 0; y <= 1; y++) {
                                        if(x && j >= a) continue;
                                        if(y && j >= b) continue;
                                        if(((t + x + y) & 1) ^ zt) continue;
                                        f[j][k + x + y][(t + x + y) >> 1] += f[j - 1][k][t];
                                    }
                                }
                            }
                        }
                    }
                }
                ans += f[lim][i][0];
                // if(f[lim][i][0]) fprintf(stderr, "i = %d, a = %d, b = %d, val = %I64d, x = %I64d, now = %I64d\n", i, a, b, f[lim][i][0], x, now);
            }
            // fprintf(stderr, "a = %d, b = %d, ans = %I64d\n", a, b, ans);
        }
    }
    print(ans, '\n');
    return 0;
}

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll s,bit[66],cnt,ans,f[66][155][2];
ll dp(ll s,ll tot,ll h1,ll h2){
	memset(f,0,sizeof(f));
	f[0][0][0]=1;
	int ed=log2(s);
	for(ll i=1;i<=ed;i++)
		for(ll j=0;j<=i*2-2;j++)
			for(ll k=0;k<=1;k++)
				for(ll p1=0;p1<=1;p1++){
					if(i>=h1 && p1) break;
					for(ll p2=0;p2<=1;p2++){
						if(i>=h2 && p2) break;
						if((p1+p2+k)%2==((s>>i)&1))
							f[i][j+p1+p2][(p1+p2+k)/2]+=f[i-1][j][k];
					}
				}
	return f[ed][tot][0];
}
int main(){
	scanf("%lld",&s);
	bit[0]=1;
	for(;bit[cnt]<=s;)
		cnt++,bit[cnt]=bit[cnt-1]*2;
	bit[cnt+1]=bit[cnt]*2;
	for(ll i=1;i<=cnt;i++){
		if(s<(bit[i]-1)) break;
		ll ret=s%(bit[i]-1);
		for(ll j=i;j>=1;j--) if(ret>=bit[j]-1) ret-=bit[j]-1;
		if(!ret) ans++;
	}
	for(ll h1=1;h1<=cnt;h1++)
		for(ll h2=1;h2<=cnt;h2++){
			if((s-bit[h2]+1)<(bit[h1+1]+bit[h2+1]-3)) break;
			ll ret=(s-bit[h2]+1)%(bit[h1+1]+bit[h2+1]-3);
			if(ret==0) {ans++; continue;}
			for(ll n=1;n<=h1+h2;n++)
				if((ret+n)%2==0)
					ans+=dp(ret+n,n,h1,h2);
			}
	printf("%lld",ans);
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define MAX 105
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    x+=y; if (x>=mod) x-=mod;
    assert(x>=0 && x<mod);
}
void et() {
    puts("-1"); exit(0);
}

ll S;
int len(ll x) {
    for(int i=51;i>=0;i--) {
        if (x & (1LL<<i)) return i;
    }
    return -1;
}
ll ans =0, dp[MAX][MAX][2];
void cal(int la, int lb, ll tt, int pc, ll X, int lenX) {
    memset(dp,0,sizeof dp);
    dp[0][0][0]=1;

    ll tarA = la == lenX ? X : X<<1;
    ll tarB = lb==lenX ? X : X<<1|1;
    int tla = la - (len(tarA)+1);
    int tlb = lb - (len(tarB) + 1);
    while(len(tarA)+1 < la) tarA <<= 1;
    while(len(tarB)+1 < lb) tarB <<= 1;
    tt -= tarA + tarB;
    pc -= __builtin_popcountll(tarA) + __builtin_popcountll(tarB);
    if (tt<0  || pc<0) return;
    int L = len(tt)+1;
    la=tla; lb=tlb;
    L=max(L, max(la,lb));

    REQ(i,L) {
        for(int j=0;j<=pc;j++) REP(k,2)
            if (dp[i-1][j][k] != 0) {
            REP(p,2) REP(q,2) {
                if (p==1 && i>la) continue;
                if (q==1 && i>lb) continue;

                if (p+q+j>pc) continue;
                if (((p+q+k) & 1) != ((tt >> (i-1))&1) ) continue;

                dp[i][j+p+q][(p+q+k)>>1] += dp[i-1][j][k];
            }
        }
    }

    ans += dp[L][pc][0];

}
void fmain(int tid) {
    scanf("%lld", &S);
    for(int L=0;L<=50;L++) {
        for(int R=0;R<=50;R++) {
            ll x = (S - (1LL<<R) + 1) / ((1LL<<(L+1)) + (1LL<<(R+1)) - 3);
            if (x<=0) continue;
            int le = len(x);
            ll tmp = S - __builtin_popcountll(x) * 2 + 3*x;
            int la = le + L+1, lb = le + R+1;
            for(int c=2; c<=la+lb; c++) {
                if ((tmp+c) > 0 && (tmp+c)%2==0) {
                    cal(la, lb, (tmp+c)/2, c, x, le+1);
                }
            }
        }
    }

    printf("%lld\n", ans );
}

int main() {
    int t=1;
//    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
void dec(ll &x, ll y) {
    if (x >= y)
        x -= y;
}
ll p(int x) {
    return 1ll << x;
}

ll f[51][101][2];
ll calc(ll s, ll x, int a, int b, int n) {
    if (s & 1)
        return 0;
    if (n == 0)
        return s == 0 ? 1 : 0;
    if (a == 1 && b == 1)
        return ((s - n) == (x * 5 + 1)) ? 1 : 0;
    memset(f, 0, sizeof f);
    f[0][0][0] = 1;
    for (int i = 1; i <= 50; ++i) {
        int d = (s >> i) & 1;
        for (int j = 0; j <= 2 * (i - 1); ++j) {
            for (int aa = 0; aa <= 1; ++aa) {
                if (aa == 1 && i >= a)
                    continue;
                for (int bb = 0; bb <= 1; ++bb) {
                    if (bb == 1 && i >= b)
                        continue;
                    for (int k = 0; k <= 1; ++k) {
                        if ((k + aa + bb) % 2 == d)
                            f[i][j + aa + bb][(k + aa + bb) / 2] += f[i - 1][j][k];
                    }
                }
            }
        }
    }
    return f[50][n][0];
}

int main() {
	#ifndef ONLINE_JUDGE
		freopen("s.in","r",stdin);
		freopen("t.out","w",stdout);
	#endif
    ll s;
    cin >> s;
    ll num = 0;
    for (int i = 1; i <= 50; ++i) {
        ll x = s / (p(i) - 1);
        if (x > 0) {
            ll last = s % (p(i) - 1);
            for (int j = i - 1; j >= 1; --j)
                dec(last, p(j) - 1);
            if (last == 0)
                ++num;
        }
    }
    for (int h1 = 1; h1 <= 50; ++h1) {
        for (int h2 = 1; p(h2) - 1 <= s; ++h2) {
            ll x = (s - p(h2) + 1) / (p(h1 + 1) + p(h2 + 1) - 3);
            if (x > 0) {
                ll last = (s - p(h2) + 1) % (p(h1 + 1) + p(h2 + 1) - 3);
                for (int n = 0; n <= h1 + h2; ++n) {
                    ll temp = calc(last + n, x, h1, h2, n);
                    num += temp;
                }
            }
        }
    }

    cout << num << endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
ll n,ans;
map<ll,ll> mp[55][55];
ll Func(ll L,ll R,ll v){
	if (L>R) swap(L,R);
	if (!L&&!R) return !v;
	if (mp[L][R].find(v)!=mp[L][R].end()) return mp[L][R][v];
	if (v<0||v>(1ll<<L)+(1ll<<R)-L-R-2) return 0;
	return mp[L][R][v]=Func(L,R-1,v)+(R==1?0:Func(L,R-1,v-(1ll<<(R-1))+1));
}
/*
0  2
1  4
3  8
11 16
26 32
x 2x 4x 8x
*/
int main(){
	scanf("%lld",&n);
	for (int L=0;1ll<<(L+1)<=n+1;++L)
		for (int R=0;(1ll<<(L+1))+(3ll<<R)<=n+4;++R){
			ll s1=(1ll<<(L+1))+(1ll<<(R+1))-3,s2=(1ll<<R)-1;
			ll f=(n-s2)/s1,g=n-s1*f-s2;
			//cout<<L<<' '<<R<<' '<<f<<' '<<g<<' '<<ans<<endl;
			ans+=Func(L,R,g);
		}
	printf("%lld\n",ans);
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <ctime>
#include <iomanip>
using namespace std;
#define fi firstu77777
#define se second
#define mp make_pair
#define pb push_back
#define FORU(i, a, b) for (int i = a, nn = int(b); i <= nn; ++i)
#define FORD(i, a, b) for (int i = a, nn = int(b); i >= nn; --i)
#define REP(i, b) for (int i = 0, nn = int(b); i < nn; ++i)
#define sz(x) (int)(x).size()
#define mmst(a, x) memset(a, x, sizeof(a))
#define DEBUG(x) cout << #x << " : " << (x) << endl;
#define LOOK(x, a, b) {cout << #x << " : ";FORU(i, a, b) cout << x[i] << ' '; cout << endl; }
#define Tgetw(a, w) ((a >> w) & 1)
typedef long long ll;
typedef double ff;
typedef unsigned long long ull;
typedef long double lff;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int N = 150;
ll s, ans;
inline ll dp(int ot, int la, int lb, ll sm) {
    static ll f[N][2], las[N][2];
    REP(a, ot + 1) REP(re, 2) f[a][re] = 0;
    f[0][0] = 1;
    for (int i = 0; (1LL << i) <= sm; ++i) {
        REP(a, ot + 1) REP(re, 2) {
            las[a][re] = f[a][re];
            f[a][re] = 0;
        }
        REP(ca, 2) if (i < la || ca == 0)
            REP(cb, 2) if (i < lb || cb == 0) {
                REP(re, 2) {
                    int dg = ca + cb + re;
                    if ((dg & 1) != Tgetw(sm, i))
                        continue;
                    for (int al = 0; al + ca + cb <= ot; ++al)
                        f[al + ca + cb][dg / 2] += las[al][re];
                }
        }
    }
    return f[ot][0];
}
int main() {
    cin >> s, ans = 0;
    REP(a, 59) REP(b, 59) {
        ll mul = (1LL << a + 1) + (1LL << b + 1) - 3;
        ll lca = s / mul ; if (!lca) continue;
        ll res = s - lca * mul - ( (1LL << b) - 1);
        REP(ones, a + b + 1) {
            ll aandb = res + ones;
            if (aandb < 0 || aandb % 2 == 1) continue;
            aandb /= 2;
            ans += dp(ones, max(a-1, 0), max(b-1, 0), aandb);
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

LL s,ans;
LL f[2][150][2];

inline LL dp(int c,int a,int b,LL s){
	int i;
	memset(f,0,sizeof(f));
	f[1][0][0]=1;
	for(i=0;(1ll<<i)<=s;i++){
		memset(f[i&1],0,sizeof(LL)*300);
		for(int k=0;k<=c;k++)
			for(int aa=0;!aa || aa<=1 && i<a;aa++)
				for(int bb=0;!bb || bb<=1 && i<b;bb++){
					int t=(s>>i)&1^aa^bb;
					f[i&1][k+aa+bb][t+aa+bb>>1]+=f[(i&1)^1][k][t];
				}
	}
	return f[(i&1)^1][c][0];
}
int main()
{
	cin >> s;
	for(int a=0;a<60;a++)
		for(int b=0;b<60;b++){
			LL tt=(1ll<<a+1)+(1ll<<b+1)-3;
			if(tt>s) break;
			LL r=s%tt-(1ll<<b)+1;
			for(int c=0;c<=a+b;c++) if(r+c>=0 && !((r+c)%2))
				ans+=dp(c,a-1,b-1,r+c>>1);
		}
	cout << ans << endl;;
	return 0;
}

//in the name of allahi
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=50;
ll s , dp[2*N][2][2];
ll eval(ll num , int h1 , int h2 , int cnt){
        memset(dp , 0LL , sizeof dp);
        dp[0][0][0] = 1;
        for(int i=1 ; i<N ; i++){
                int d = (i&1);
                ll mul[3] = {1 , (h1>=i)+(h2>=i) , (h1>=i && h2>=i)};
                int hv = (((1LL<<i)&num)>0);
                for(int j=0 ; j<=cnt ; j++){
                        dp[j][0][d] = dp[j][1][d] = 0;
                        for(int t1=0 ; t1<2 ; t1++)
                                for(int t2=0 ; t2<=2 ; t2++){
                                        int f = (t1 + t2)&1 , s = (t1 + t2 - hv)/2;
                                        if(f != hv || j<t2)
                                                continue;
                                        dp[j][s][d] += dp[j-t2][t1][d^1] * mul[t2];
                                }
                }
        }
        return dp[cnt][0][ (N-1)&1 ];
}

int main(){
        cin >> s;
        ll ans=0;
        for(int h1=0 ; h1<N ; h1++)
                for(int h2=0 ; h2<N ; h2++){
                        ll sum = (1LL<<(h1+1)) + (1LL<<(h2+1)) - 3;
                        if(s<sum)
                                continue;
                        ll rem = s%sum;
                        rem = rem - (1LL<<h2) + 1;
                        for(int k=0 ; k<=(h1+h2) ; k++)
                                if(rem+k>=0 && (rem+k)%2 == 0)
                                        ans += eval(rem+k , h1-1 , h2-1 , k);
                }
        cout << ans << "\n";
}

#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull usigned ll
using namespace std;
inline ll read(){
	ll s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return s*t;
}
const int N=60;
int m;
ll n,S,T,R,Ans,h[N],f[N][N*2][2];
bool Calc(ll A,ll B){
	if(A<B||A<=0||B<=0)return 0;
	return T=A/B,R=A%B,1;
}
ll Solve(ll R,int a,int b,int n){
	int lim=log2(R);
	memset(f[0],0,sizeof(f[0])),f[0][0][0]=1;
	for(int i=1;i<=lim;i++){
		int t=(R>>i&1);
		memset(f[i],0,sizeof(f[i]));
		for(int j=0;j<=2*i-2;j++)
		for(int k=0;k<=1;k++)if(f[i-1][j][k])
		for(int x=0;x<=1;x++)if(!x||i<a)
		for(int y=0;y<=1;y++)if(!y||i<b)
		if((k+x+y)%2==t)f[i][j+x+y][(k+x+y)/2]+=f[i-1][j][k];
	}return f[lim][n][0];
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	S=read(),m=log2(S)+1;
	for(int i=0;i<=m;i++)h[i]=1ll<<i;
	for(int i=1;i<=m;i++)if(Calc(S,h[i]-1)){
		for(int j=i-1;j>=0;j--)if(R>=h[j]-1)R-=h[j]-1;
		if(!R)Ans++;
	}
	for(int i=1;i<m;i++)
	for(int j=1;j<m;j++)
	if(Calc(S-h[j]+1,h[i+1]+h[j+1]-3)){
		if(!R){Ans++;continue;}
		for(int k=1;k<=i+j;k++)
		if(!(R+k&1))Ans+=Solve(R+k,i,j,k);
	}printf("%lld",Ans);
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>

using namespace std;
using namespace __gnu_pbds;

template<class T, class U>
ostream& operator<<(ostream& out, const pair<T, U>& a) {out << "[" << a.first << " " << a.second << "]"; return out;}
template<class T>
ostream& operator<<(ostream& out, const vector<T>& a) {out << "[ "; for (auto &it : a)out << it << " "; out << "]"; return out;}
template<class T>
ostream& operator<<(ostream& out, const set<T>& a) {out << "[ "; for (auto &it : a)out << it << " "; out << "]"; return out;}
template<class T, class U>
ostream& operator<<(ostream& out, const map<T, U>& a) {for (auto &it : a)out << it.first << " -> " << it.second << " | "; return out;}

#define cerr cout

#define pra(a,n) cerr<<#a<<" : ";for(int i=0;i<n;++i)cerr<<a[i]<<" ";cerr<<endl;
#define praa(a,n,m) cerr<<#a<<" : "<<endl;for(int i=0;i<n;++i){for(int j=0;j<m;++j)cerr<<a[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {
    cerr << str << " : " << t << "\n";
}
template <class T, class... S> void dbs(string str, T t, S... s) {
    int idx = str.find(',');
    cerr << str.substr(0, idx) << " : " << t << " | ";
    dbs(str.substr(idx + 1), s...);
}
#undef cerr

#define inc_stack_limit const rlim_t kStackSize = 128 * 1024 * 1024;struct rlimit rl;rl.rlim_cur = kStackSize;setrlimit(RLIMIT_STACK, &rl);
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define NFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define TCASE int __T;cin>>__T;FOR(Tc,1,__T)

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef vector<vector<pair<int, int> > > vvii;

const ll inf2 = 1e18;
const int inf = 1e9 + 7;

inline int add(int a, int b, int m = inf) {if ((a += b) >= m)a -= m; return a;}
inline int sub(int a, int b, int m = inf) {if ((a -= b) < 0)a += m; return a;}
inline int mul(int a, int b, int m = inf) {return (int)(((ll)a * (ll)b) % m);}

ll S;
int l1, l2;
ll dp[51][101][2];
int vis[51][101][2];
int tc;

ll f(int pos, int bc, bool c) {
	if (pos == 51) return bc == 0 and c == 0;

	ll & ans = dp[pos][bc][c];
	if (vis[pos][bc][c] == tc) return ans;
	vis[pos][bc][c] = tc;
	ans = 0;

	bool now = ((S >> pos) & 1LL);
	if (c == now) ans = f(pos + 1, bc, 0);

	if (pos and pos <= l1 and c != now and bc >= 1)
		ans += f(pos + 1, bc - 1, c);

	if (pos and pos <= l2 and c != now and bc >= 1)
		ans += f(pos + 1, bc - 1, c);

	if (pos and pos <= l1 and pos <= l2 and c == now and bc >= 2)
		ans += f(pos + 1, bc - 2, 1);

	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);	cin.tie(NULL);

	ll s; cin >> s;
	ll ans = 0;

	FOR (h1, 1, 50) {
		FOR (h2, 1, 50) {
			FOR (bc, 0, 100) {
				if (s < ((1LL << h1) + (1LL << h2) - 3)) continue;
				S = (s % ((1LL << h1) + (1LL << h2) - 3)) - (1LL << (h2 - 1)) + 1;
				if (S < 0) continue;
				S += bc;
				++tc;
				l1 = h1 - 2;
				l2 = h2 - 2;
				ans += f(0, bc, 0);
			}
		}
	}
	cout << ans;

	return 0;
}

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 60
long long qpow[N],f[N][N<<1][2];
long long calc1(long long a,long long b)
{
	long long lca=a,tmp=b,sum=0;
	int la=log2(a),lb=log2(b);
	for(int i=la;i<lb;i++) tmp>>=1;
	for(int i=lb;i<la;i++) lca>>=1;
	while(tmp!=lca) tmp>>=1,lca>>=1;
	int LLCA=log2(lca);
	if(a==lca&&b==lca) return lca;
	if(a==lca||b==lca)
	{
		if(b==lca) swap(a,b),swap(la,lb);
		sum=lca*((1ll<<(lb-LLCA+1))-1);
		for(int i=1;b>lca;i++,b>>=1)
			sum+=(b&1)*((1ll<<i)-1);
	}
	else
	{
		if((a>>(la-LLCA-1))&1) swap(a,b),swap(la,lb);
		sum=lca*((1ll<<(la-LLCA+1))+(1ll<<(lb-LLCA+1))-3)+(1ll<<(lb-LLCA))-1;
		lca=lca<<1|1;
		for(int i=1;a>lca;i++,a>>=1) sum+=(a&1)*((1ll<<i)-1);
		for(int i=1;b>lca;i++,b>>=1) sum+=(b&1)*((1ll<<i)-1);
	}
	return sum;
}
long long calc2(long long S,int d)
{
	// printf("S: %lld\n",S);
	long long ans=0; int L=min((int)log2(S+1),d);
	for(int h=1;h<=L;h++)
	{
		long long x=S/(qpow[h]-1);
		if(h+(int)log2(x)>d) continue;
		x=S%(qpow[h]-1);
		for(int i=h;i;i--) if(x>=qpow[i]-1) x-=qpow[i]-1;
		ans+=(!x);
	}
	// printf("Ans: %lld\n",ans);
	for(int h0=1;h0<L;h0++) for(int h1=1;S+1-qpow[h1]>=qpow[h0+1]+qpow[h1+1]-3;h1++)
	{
		long long x=(S+1-qpow[h1])/(qpow[h0+1]+qpow[h1+1]-3);
		long long r=(S+1-qpow[h1])%(qpow[h0+1]+qpow[h1+1]-3);
		if(max(h0,h1)+1+(int)log2(x)>d) continue;
		if(!r) {ans++;continue;}
		if(h0==1&&h1==1) {ans+=(S==x*5+1);continue;}
		for(int n=1;n<=h0+h1;n++)
		{
			long long C=r+n,L=log2(C);
			if(C&1) continue;
			memset(f[0],0,sizeof f[0]);
			f[0][0][0]=1;
			for(int i=1;i<=L;i++)
			{
				int d=(C>>i)&1;
				memset(f[i],0,sizeof f[i]);
				for(int j=0;j<=i*2-2&&j<=n;j++)
					for(int k=0;k<2;k++) if(f[i-1][j][k])
						for(int x=0;x<2;x++) if(!x||i<h0)
							for(int y=0;y<2;y++) if(!y||i<h1)
								if(((k+x+y)&1)==d) f[i][j+x+y][(k+x+y)>>1]+=f[i-1][j][k];
			}
			ans+=f[L][n][0];
			// printf("%lld\n",f[L][n][0]);
		}
	}
	return ans;
}
int main()
{
	qpow[0]=1;
	for(int i=1;i<N;i++) qpow[i]=qpow[i-1]<<1;
	long long S;scanf("%lld\n",&S);
	printf("%lld\n",calc2(S,100));
}

/*
 * 5513.cpp
 * This file is part of 5513
 *
 * Copyright (C) 2019 - ViXbob
 *
 * 5513 is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 5513 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with 5513. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * There is no end though there is a start in space. ---Infinity.
 * It has own power, it ruins, and it goes though there is a start also in the star. ---Finite.
 * Only the person who was wisdom can read the most foolish one from the history.
 * The fish that lives in the sea doesn't know the world in the land.
 * It also ruins and goes if they have wisdom.
 * It is funnier that man exceeds the speed of light than fish start living in the land.
 * It can be said that this is an final ultimatum from the god to the people who can fight.
 *
 * Steins;Gate
 */
#include <bits/stdc++.h>
#define rep(i, j, k) for(int i = j; i <= k; ++i)
#define dep(i, j, k) for(int i = j; i >= k; --i)
#define SIZE(x) ((int)x.size())
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int maxn = 1e5 + 5;
const int P = 998244353;
const int inf = 0x3f3f3f3f;

int T;
ll d, a, b, c, k, S, mi[maxn], ans;
unordered_map<ll, ll> f[60][60];

inline ll read() {
	char ch = getchar(); ll u = 0, f = 1;
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch))  { u = u * 10 + ch - 48; ch = getchar(); } return u * f;
}

inline int pls(int x, int y) { x += y; return x >= P ? x - P : x; }
inline int dec(int x, int y) { x -= y; return x < 0 ? x + P : x; }

inline ll dfs(int L, int R, ll S) {
	if(S < 0) return 0;
	if(L <= 0 && R <= 0) return S == 0;
	if(mi[L + 1] - L - 2 + mi[R + 1] - R - 2 < S) return 0;
	if(L < R) swap(L, R);
	if(f[L][R].count(S)) return f[L][R][S];
	return f[L][R][S] = dfs(L - 1, R, S) + dfs(L - 1, R, S - mi[L] + 1);
}

int main() {
//	freopen("1.in", "r", stdin);
//	freopen("my.out", "w", stdout);
	mi[0] = 1; S = read();
	rep(i, 1, 55) mi[i] = mi[i - 1] << 1;
	d = 55; ans = 0;
	rep(i, 0, d - 1) rep(j, 0, d - 1) if(mi[i + 1] + 3 * mi[j] - 4 <= S) {
		ll x = (S - mi[j] + 1) / (mi[i + 1] + mi[j + 1] - 3);
		ans += dfs(i - 1, j - 1, S - mi[j] + 1 - x * (mi[i + 1] + mi[j + 1] - 3));
	}
	printf("%lld\n", ans);
	return 0;
}

#include<stdio.h>
#include<map>
#include<algorithm>
#define it register int
#define ct const int
#define il inline
using namespace std;
const int N=1000005;
typedef long long ll;
#define rll register ll
#define cll const ll
ll s,ans;
map<ll,ll> mp[55][55];
il void sp(int &p,int &q){ct x=p;p=q,q=x;}
il ll dfs(it x,it y,cll ans){
	if(ans<0||ans>(2ll<<x)+(2ll<<y)-x-y-4ll) return 0;
	if(!x&&!y) return !ans;
	if(x<y) sp(x,y);
	if(mp[x][y].count(ans)) return mp[x][y][ans];
	return mp[x][y][ans]=dfs(x-1,y,ans)+dfs(x-1,y,ans-(1ll<<x)+1);
}
il ll cal(rll x){
	rll k=x;
	while(x) k+=(x>>=1);
	return k;
}
int main(){
	scanf("%lld",&s);rll k,x;it l,r;
	for(l=1;(2ll<<l)<=s+1;++l){
		k=s%((2ll<<l)-1),x=k>>1;
		while(x<(1ll<<l)-1&&cal(x)<k) ++x;
		while(x&&cal(x)>k) --x;
		ans+=(cal(x)==k);
	}
	for(l=1;(2ll<<l)<=s-2;++l)
		for(r=1;(2ll<<l)+(3ll<<r)-4<=s;++r)
			k=(2ll<<l)+(2ll<<r)-3,x=(1ll<<r)-1,ans+=dfs(l-1,r-1,(s-x)%k);
	printf("%lld",ans+1);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL s;

// L + 1 位的二进制数 a
// R + 1 位的二进制数 b

// a 的第 L + 1 位和 b 的第 R + 1 位都是 1
// a 的第 L 位是 0；b 的第 R 位是 1
// a + b = s
// popcount(a) + popcount(b) = t

LL solve(int L, int R, int t, LL s) {
	LL dp[55][110][2] = {};
	dp[0][0][0] = 1;
	for (int i = 0; i <= 51; ++i)
		for (int j = 0; j <= i * 2 && j <= t; ++j)
			for (int k = 0; k < 2; ++k)
				if (dp[i][j][k])
					for (int a = 0; a < 2; ++a) {
						if ((i == L - 1|| i > L) && a) continue;
						if (i == L && !a) continue;
						for (int b = 0; b < 2; ++b) {
							if ((i == R - 1 || i == R) && !b) continue;
							if (i > R && b) continue;
							if ((a + b + k & 1) == (s >> i & 1))
								dp[i + 1][j + a + b][a + b + k >= 2] += dp[i][j][k];
						}
					}
	return dp[52][t][0] + dp[52][t][1];
}

int main() {
	cin >> s;
	LL ans = 0;
	for (int L = 0; L <= 50; ++L)
		for (int R = 0; R <= 50; ++R) {
			LL x = (s + R + 1 - (1LL << R)) / ((1LL << L + 1) + (1LL << R + 1) - 3);
			if (x == 0) break;
			LL tmp = s - (x - 1) * ((1LL << L + 1) + (1LL << R + 1) - 3) + 1;
			for (int t = tmp & 1 ? 3 : 2; t <= L + R + 2; t += 2)
				ans += solve(L, R, t, (tmp + t) / 2);
		}
	cout << ans << endl;
	return 0;
}

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
/**
 *    author:  [itmo] enot.1.10
 *    created: 30.12.2016 17:48:25
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int L = 55;

ll d[66][111][66][66];

ll RES = 0;

void solve2(ll s)
{
    memset(d, 0, sizeof d);
    for (int l1 = 0; l1 < L; ++l1)
    {
        for (int l2 = 0; l2 < L; ++l2)
        {
            ll xs = 1;
            for (int i = 1; i <= l1; ++i) xs += pw(i);
            for (int i = 1; i <= l2; ++i) xs += pw(i);
            if (xs > s) break;
            ll rem = s % xs;

            ll smallest = pw(l2) - 1;
            ll largest = 0;
            for (int i = 1; i < l1; ++i) largest += pw(i) - 1;
            for (int i = 1; i <= l2; ++i) largest += pw(i) - 1;

            if (!(smallest <= rem && rem <= largest)) continue;

            for (int i1 = 0; i1 <= l1; ++i1) for (int i2 = 0; i2 <= l2; ++i2) d[0][0][i1][i2] =1;

            for (int i = 0; i < L; ++i)
            {
                int want = (rem >> i) & 1;

                int mn1 = 0;
                int mx1 = 0;
                if (i <= l1 - 2) mx1 = l1 - 1 - i;

                int mn2 = 0;
                int mx2 = 0;
                if (i <= l2 - 2) mn2 = 1, mx2 = l2 - i;
                else if (i == l2 - 1) mn2 = 1, mx2 = 1;

                for (int i1 = mn1; i1 <= mx1; ++i1) for (int i2 = mn2; i2 <= mx2; ++i2)
                for (int per = i > 0 ? (i1 + i2) / 2 : 0; per <= min(111, i1 + i2 + 10); ++per)
                //forn(per, 111)
                {
                    int sum = per + i1 + i2;
                    if (sum % 2 != want) continue;
                    if (i > 0)
                    {
                        forn(di, 2) forn(dj, 2)
                        {
                            d[i + 1][sum / 2][i1][i2] += d[i][per][i1 + di][i2 + dj];
                        }
                    }
                    else
                    {
                        d[i + 1][sum / 2][i1][i2] += d[i][per][i1][i2];
                    }
                }
            }
            if (d[L][0][0][0])
            {
                //eprintf("l1 = %d, l2 = %d, += %I64d\n", l1, l2, d[L][0][0][0]);
            }
            RES += d[L][0][0][0];

            for (int i = L - 1; i >= 0; --i)
            {
                int want = (rem >> i) & 1;

                int mn1 = 0;
                int mx1 = 0;
                if (i <= l1 - 2) mx1 = l1 - 1 - i;

                int mn2 = 0;
                int mx2 = 0;
                if (i <= l2 - 2) mn2 = 1, mx2 = l2 - i;
                else if (i == l2 - 1) mn2 = 1, mx2 = 1;

                for (int i1 = mn1; i1 <= mx1; ++i1) for (int i2 = mn2; i2 <= mx2; ++i2)
                for (int per = i > 0 ? (i1 + i2) / 2 : 0; per <= min(111, i1 + i2 + 10); ++per)
                //forn(per, 111)
                {
                    int sum = per + i1 + i2;
                    if (sum % 2 != want) continue;
                    if (i > 0)
                    {
                        forn(di, 2) forn(dj, 2)
                        {
                            d[i + 1][sum / 2][i1][i2] -= d[i][per][i1 + di][i2 + dj];
                        }
                    }
                    else
                    {
                        d[i + 1][sum / 2][i1][i2] -= d[i][per][i1][i2];
                    }
                }
            }

        }
    }
}

ll smart(ll s)
{
    RES = 0;
    solve2(s);
    return RES;
}

ll stupid(ll s)
{
    ll res = 0;
    for (int i = 1; i <= s; ++i) for (int j = i; j <= s; ++j)
    {
        ll sum = 0;
        int x = i, y = j;
        while (x != y)
        {
            if (x > y)
            {
                sum += x;
                x >>= 1;
            }
            else
            {
                sum += y;
                y >>= 1;
            }
        }
        sum += x;
        if (s == sum)
        {
            res++;
            //eprintf("%d %d\n", i, j);
        }
    }
    return res;
}

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    if (0)
    {
        for (int i = 3; i <= 1000; ++i)
        {
            eprintf("i = %d\n", i);
            ll r1 = stupid(i);
            ll r2 = smart(i);
            if (r1 != r2)
            {
                eprintf("fail %d :: %I64d vs %I64d\n", i, r1, r2);
                return 0;
            }
        }
    }

    ll s;
    scanf("%I64d", &s);
    ll res = smart(s);
    printf("%I64d\n", res);
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

LL s;

LL tot = 0, ans = 0;

LL d[15][15][40000];

LL solve(int a, int b, LL s) {
    if (s < 0) {
        return 0;
    }
    if (s == 0) {
        return 1;
    }
    if ((2ll << a) - a + (2ll << b) - b - 4 < s) {
        return 0;
    }
    if (a == 0) {
        return 0;
    }
    bool ok = (a < 15 && b < 15 && s < 40000);
    if (ok && d[a][b][s] != -1) {
        return d[a][b][s];
    }
    if (a == b) {
        LL res = solve(a - 1, b - 1, s) + 2ll * solve(a - 1, b - 1, s - (1ll << a) + 1) + solve(a - 1, b - 1, s - (2ll << a) + 2);
        if (ok) d[a][b][s] = res;
        return res;
    }
    LL res = solve(a - 1, b, s - (1ll << a) + 1) + solve(a - 1, b, s);
    if (ok) d[a][b][s] = res;
    return res;
}

LL calc(LL x, int h) {
    LL res = x;
    forn(i, h) {
        x >>= 1;
        res += x;
    }
    return res;
}

int main() {
    memset(d, -1, sizeof d);
    //freopen("input.txt", "r", stdin);
    cin >> s;
    for (int i = 1; i <= 55; ++i) {
        for (int j = 1; j <= 55; ++j) {
            LL x = 2 * ((1ll << i) + (1ll << j) - 2) + 1;
            LL mn = (1ll << j) - 1;
            LL mx = mn + (1ll << i) - i + (1ll << j) - j - 2;
            mn = s - mn;
            mx = s - mx;
            swap(mn, mx);
            mn = max(mn, x);
            if (mx < x) {
                continue;
            }
            mx /= x;
            mn = (mn + x - 1) / x;
            tot += max(0ll, mx - mn + 1);
            for (LL a = mn; a <= mx; ++a) {
                LL b = s - a * x - (1ll << j) + 1;
                ans += solve(max(i - 1, j - 1), min(i - 1, j - 1), b);
                cerr << i << ' ' << j << ' ' << a << ": " << ans << endl;
            }
        }
    }
    cerr << ans << endl;
    //cerr << tot << endl;
    forn(h, 55) {
        LL lo = (1ll << h), hi = s, mid;
        while (lo < hi) {
            mid = (lo + hi) >> 1;
            LL x = calc(mid, h);
            if (x >= s) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        if (calc(lo, h) == s) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define watch(x) std::cout << "$ LINE @" << __LINE__ << " FUNC @" << __FUNCTION__ << "\n$ " \
                           << (#x) << ": " << x << std::endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <typename Tp>
inline void read(Tp &x)
{
    static char c;
    static bool neg;
    x = 0, c = getchar(), neg = false;
    for (; !isdigit(c); c = getchar())
    {
        if (c == '-')
        {
            neg = true;
        }
    }
    for (; isdigit(c); c = getchar())
    {
        x = x * 10 + c - '0';
    }
    if (neg)
    {
        x = -x;
    }
}

// 一颗无穷个节点的完全二叉树，编号规律为 x（自身），2 * x（左儿子），2 * x + 1（右儿子）
// 求有多少条树上的简单路径编号和为 s

#define pow2(x) (1LL << (x))

const int MX = 50 * 2 + 5;

ll f[MX][MX * 2][2];

inline ll dp(ll s, int all, int h1, int h2)
{
    memset(f, 0, sizeof(f));
    f[0][0][0] = 1;
    int n = log2(s);
    for (int i = 1, d, m; i <= n; ++i)
    {
        d = (s >> i) % 2;
        m = (i - 1) * 2;
        for (int j = 0; j <= m; ++j)
        {
            for (int k = 0; k < 2; ++k)
            {
                for (int a = 0; a < 2; ++a)
                {
                    for (int b = 0; b < 2; ++b)
                    {
                        if ((i < h1 || a == 0) && (i < h2 || b == 0) && ((a + b + k) % 2 == d))
                        {
                            f[i][j + a + b][(a + b + k) / 2] += f[i - 1][j][k];
                        }
                    }
                }
            }
        }
    }
    return f[n][all][0];
}

int main()
{
    ll s, x, res, calc, cald, ans = 0;
    scanf("%lld", &s);
    int n = 0;
    while ((1LL << n) <= s)
    {
        ++n;
    }
    for (int i = 1; i <= n; ++i)
    {
        calc = pow2(i) - 1;
        if (calc > s)
        {
            break;
        }
        x = s % calc;
        for (int j = i; j >= 1; --j)
        {
            calc = pow2(j) - 1;
            if (x >= calc)
            {
                x -= calc;
            }
        }
        if (x == 0)
        {
            ++ans;
        }
    }
    for (int h1 = 1; h1 < n; ++h1)
    {
        for (int h2 = 1; pow2(h2) - 1 <= s && h2 < n; ++h2)
        {
            calc = pow2(h1 + 1) + pow2(h2 + 1) - 3;
            cald = s - (pow2(h2) - 1);
            x = cald / calc; //  (s - (pow2(h2) - 1)) / (pow2(h1 + 1) + pow2(h2 + 1) - 3)
            if (x > 0)
            {
                res = cald % calc;
                if (res == 0)
                {
                    ++ans;
                }
                else
                {
                    if (h1 == 1 && h2 == 1)
                    {
                        ans += (s == /* 左儿子 */ 2 * x + /* 右儿子 */ 2 * x + 1);
                    }
                    else
                    {
                        for (int i = 1; i <= h1 + h2; ++i)
                        {
                            if ((res + i) % 2 == 0)
                            {
                                ans += dp(res + i, i, h1, h2);
                            }
                        }
                    }
                }
            }
        }
    }
    printf("%lld\n", ans);
}

#undef pow2

//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    ll dp[60][110][2];
	void main()
	{
        ll S=qread(),ans=0;
        fo(L1,0,50) fo(L2,0,50)
        {
            ll tt=bin(L1+1)+bin(L2+1)-3,ul=max((S-bin(L1)-bin(L2+1)+L1+L2+3)/tt,1ll),ur=(S-bin(L2)+1)/tt;
            for(ll LCA=ul;LCA<=ur;LCA++) fo(cnt,0,L1+L2)
            {
                ll wt=S-LCA*tt-bin(L2)+1+cnt;if(wt<0 or wt&1) continue;
                memset(dp,0,sizeof dp);dp[1][0][0]=1;int ln=ceil(log2(max(1ll,wt)));
                fo(i,1,ln) fo(c,0,min(i+i,L1+L2))
                {
                    if(i>=max(L1,L2)) {dp[i+1][c][0]+=dp[i][c][(wt&bin(i))>0];continue;}//0
                    if(wt&bin(i))
                    {
                        dp[i+1][c+1][0]+=dp[i][c][0]*(1+(i<min(L1,L2)));//1
                        dp[i+1][c][0]+=dp[i][c][1],dp[i+1][c+2][1]+=dp[i][c][1]*(i<min(L1,L2));//0/2
                    }
                    else
                    {
                        dp[i+1][c+1][1]+=dp[i][c][1]*(1+(i<min(L1,L2)));//1
                        dp[i+1][c][0]+=dp[i][c][0],dp[i+1][c+2][1]+=dp[i][c][0]*(i<min(L1,L2));//0/2
                    }
                }
                ans+=dp[ln+1][cnt][0];
            }
        }write(ans);
	}
};//(ans+MOD)%MOD
signed main()
{
    // freopen("a.in","r",stdin);
    srand(time(0));
    mine::main();
}

#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#include <assert.h>
#include <set>

using namespace std;

#define REP(i,fn_) for(int i=0; i<(fn_); ++i)
#define RREP(i,fn_) for(int i=(fn_)-1; i>=0; --i)
#define FOR(i,fa_,fb_) for(int i=(fa_); i<=(fb_); ++i)
#define RFOR(i,fa_,fb_) for (int i=(fa_); i>=(fb_); --i)
#define ALL(fc_) (fc_).begin(), (fc_).end()
#define MEMALL(fe_,fv_) memset((fe_), (fv_),sizeof((fe_)))
#define MEM(fe_,fv_,fs_) memset((fe_),(fv_), sizeof((fe_)[0])*(fs_))

typedef long long lld;
typedef vector<int> VI;
typedef vector<lld> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<lld,lld> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

const lld MOD=1e9+7;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }
template<typename T> void add(T &a, T b)
{
    a+=b;
    if(a<0)a+=MOD;
    if(a>=MOD)a-=MOD;
}
void FastIn(int &T)
{
	char C;bool F=0;
	for(;C=getchar(),C<'0'||C>'9';)if(C=='-')F=1;
	for(T=C-'0';C=getchar(),C>='0'&&C<='9';T=T*10+C-'0');
	F&&(T=-T);
}

int in() { int x; scanf("%d", &x); return x; }
lld lin() { lld x; scanf("%lld", &x); return x; }
double din(){double x; scanf("%lf",&x); return x;}
lld p2[64];
void initP2()
{
    p2[0]=1;
    FOR(i, 1, 63)
    {
        p2[i]=p2[i-1]*2;
    }
}

int countBitsBaseB(lld n, lld b)
{
    if(n==0)return 1;
    int ret=0;
    while(n)
    {
        ret++;
        n/=b;
    }

    return ret;
}

int count1(lld n)
{
    int ret=0;
    while(n)
    {
        ret+=n&1;
        n>>=1;
    }

    return ret;
}

lld c[1024][1024]={0};

void initC()
{
    REP(i,1024)
    {
        REP(j,i+1)
        {
            if(j==0||j==i)
            {
                c[i][j]=1;
            }
            else
            {
                c[i][j]=c[i-1][j-1];
                add(c[i][j], c[i-1][j]);
            }
        }
    }
}

bool IsPrime(int n)
{
    if(n<2)return false;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)return false;
    }

    return true;
}

void init()
{
    initP2();
    initC();
}

#define MAXN 310000
const lld INF=1000000000;

map<pair<int,lld>,int > sg;

int DFS(int sum, lld mask)
{
    if(sum==0) return 0;
    pair<int,lld> p=make_pair(sum,mask);

    if(sg.find(p)!=sg.end())
    {
        return sg[p];
    }

    vector<int> v;

    FOR(i,1,sum)
    {
        if(p2[i]&mask)continue;

        v.push_back(DFS(sum-i,mask|p2[i]));
    }

    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());

    int ans=-1;
  //  printf("v.size=%u",v.size());
    if(v.empty()||v[0]>0)ans=0;

    REP(i,(int)v.size()-1)
    {
        if(v[i]+1<v[i+1])
        {
            ans=v[i]+1;
            break;
        }
    }
    if(ans==-1)ans=v.back()+1;

    sg[p]=ans;
//    printf("ans=%d\n",ans);
    //printf("sg.size()=%u\n",sg.size());
    return ans;
}

int base[71][32]={0};
int dp[16]={0};

int pos[1024];

void Split(int n)
{
    int mask=0;
    for(int i=2;i*i<=70;i++)
    {
        while(n%i==0)
        {
            mask^=p2[pos[i]];
            n/=i;
        }
    }

    int* v=base[n];
    int z[32]={0};

/*    printf("n=%d,mask=%d\n",n,mask);
    cout<<"before"<<endl;
    REP(i,32)
    {
        printf("z[%d]=%d\n",i,z[i]);
    }*/
    REP(i,32)
    {
        int tmp=i;
        tmp^=p2[4];
        tmp^=mask;
        add(z[tmp],v[i]);
    }
 /* cout<<"after"<<endl;
    REP(i,32)
    {
        printf("z[%d]=%d\n",i,z[i]);
    }*/

    REP(i,32)
    {
        add(v[i],z[i]);
    }
}

lld calc(lld deepL,lld deepR, lld totalBits,lld sum)
{
    if(p2[deepL-1]+p2[deepR-1]>sum)return 0;
    if(p2[deepL]-1+p2[deepR]-1<sum)return 0;
    //printf("deepL=%lld,deepR=%lld,bits=%lld,sum=%lld\n",
      //      deepL,deepR,totalBits,sum);
    lld dp[64][128][2]={0};
    dp[0][0][0]=1;

    int len=max(deepL,deepR);
    RREP(i,63)
    {
        if(p2[i]&sum)
        {
            len=i+1;
            break;
        }
    }
    if(max(deepL,deepR)>len)return 0;
    REP(i,len)
    {
        REP(j,totalBits+1)
        {
            REP(mask,2)
            {
                if(dp[i][j][mask]==0)continue;
                REP(add,4)
                {
                    int add0=(add&1)>0;
                    int add1=(add&2)>0;
                    if(i+1>deepL && add0){continue;}
                    if(i+1==deepL&& add0==0){continue;}
                    if(i+1==deepL-1 && add0==1){continue;}

                    if(i+1>deepR && add1){continue;}
                    if(i+1==deepR && add1==0){continue;}
                    if(i+1==deepR-1&& add1 == 0){continue;}

                    if(add0+add1+j>totalBits)continue;
                    lld tot=mask+add0+add1;
                    lld bb=(tot&1)*p2[i];
                    if((p2[i]&sum)==bb)
                    {
                    dp[i+1][j+add0+add1][tot>>1]+=dp[i][j][mask];
                    }
                }
            }
        }
    }

    //cout<<"dp="<<dp[len][totalBits][0]<<endl;
    return dp[len][totalBits][0];
}

int main()
{
    init();
    //freopen("a.in","r",stdin);
    lld s; cin>>s;
    clock_t start=clock();
    lld ans=0;
    REP(L,64)
    {
        if(p2[L+1]-3>s)break;
        REP(R,64)
        {
            lld down=p2[L+1]+p2[R+1]-3;
            if(down>s){break;}
            lld x=(s-(p2[R]-1))/down;
            if(x<1)continue;
            lld newS=s-down*(x-1);
            if(newS<1)continue;
            REP(bits,L+R+2+1)
            {
                if((newS+1+bits)%2==0)
                {
                    ans+=calc(L+1,R+1,bits,(newS+1+bits)/2);
                }
            }
        }
    }

    cout<<ans<<endl;
    clock_t end=clock();
//cout<<CLOCKS_PER_SEC<<endl;
    //printf("%f ms\n",(double)(end-start)/CLOCKS_PER_SEC);
    return 0;
}
/*
 */

#include <bits/stdc++.h>
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define NAME ""
using namespace std;
typedef long long ll;
typedef long double ld;
const int C = 58;
const int MAXN = 3001;
int c[3][3] = {{1, 0, 0}, {1, 1, 0}, {1, 2, 1}};
int gh(int x){
	int hh = 0;
	while ((1 << hh) <= x) hh++;
	return hh;
}
int tot[1000];
int an[101][101];
pair <ll, ll> pos[MAXN];
int pc = 0;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll s;
	cin >> s;
	ll ans = 0;
	for (int lc = 0; lc < C; lc++){
		for (int rc = 0; rc < C; rc++){
			ll vv = (1ll << (lc + 1)) + (1ll << (rc + 1)) - 3;
			ll ad = (1ll << rc) - 1;
			if (s < ad + vv) continue;
			ll a = (s - ad) / vv;
			ll b = s - a * vv - ad;
			ll f1 = 1, f2 = 0;
			pc = 1;
			pos[0] = mp(b, 1);
			for (int i = C; (i >= 0); i--){
				int cn = 0;
				if (lc > i + 1) cn++;
				if (rc > i + 1) cn++;
				if (cn == 0) continue;
				ll cur = (1ll << (i + 1)) - 1;
				ll lf = (cur - (i + 1)) * 2;
				int dpc = pc;
				for (int j = 0; j < dpc; j++){
					for (int cc = 1; (cc <= cn) && (cur * cc <= pos[j].first); cc++){
						pos[pc++] = mp(pos[j].first - cur * cc, pos[j].second * c[cn][cc]);
					}
				}
				sort(pos, pos + pc);
				dpc = pc;
				if ((dpc == 0) || (pos[0].first > lf)) break;
				pc = 0;
				for (int i = 1; i < dpc; i++){
					if (pos[i].first > lf) break;
					if (pos[i].first == pos[i - 1].first) pos[pc].second += pos[i].second;
					else pos[++pc] = pos[i];
				}
				pc++;
			}
			if ((pc != 0) && (pos[0].first == 0))
				ans += pos[0].second;
		}
	}
	cout << ans << "\n";
}

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

typedef long long LL;

LL s, dp[66][122][2];
int vis[66][122][2], cur, tab[66], pa, pb;

inline LL dfs(int x, int c, bool up) {
  if (!x) return !c && !up;
  if (vis[x][c][up] == cur)
    return dp[x][c][up];
  vis[x][c][up] = cur;
  int s = (up << 1) + tab[x];
  LL ans = 0;
  bool tc = (c && x < pa), td = (c && x < pb);
  if (s == 0) ans = dfs(x - 1, c, 0);
  else if (s == 1) {
    if (tc) ans = dfs(x - 1, c - 1, 0);
    if (td) ans += dfs(x - 1, c - 1, 0);
    ans += dfs(x - 1, c, 1);
  }
  else if (s == 2) {
    if (tc) {
      if (td && c >= 2) ans = dfs(x - 1, c - 2, 0);
      ans += dfs(x - 1, c - 1, 1);
    }
    if (td) ans += dfs(x - 1, c - 1, 1);
  }
  else if (tc && td && c >= 2) ans = dfs(x - 1, c - 2, 1);
  return dp[x][c][up] = ans;
}

inline LL calc(int a, int b) {
  if (!a && !b) return 1;
  pa = a; pb = b;
  int len;
  LL res = 0, sum = s % ((2LL << a) + (2LL << b) - 3);
  if (sum == s) return 0;
  for (int c = !!b; c <= a + b; c ++) {
    if ((sum + c) & 1) continue;
    res += !b && c < a && __builtin_popcountll(sum + c) == c && (1LL << a) > sum + c;
    if (!c || !b) continue;
    if (sum + c < (1LL << b)) continue;
    LL tmp = (sum + c - (1LL << b)) >> 1;
    cur ++; len = 0;
    memset(tab, 0, sizeof tab);
    for (; tmp; tmp >>= 1) tab[++ len] = tmp & 1;
    res += dfs(len, c - 1, 0);
  }
  return res;
}

int main() {
  LL ans = 0;
  scanf("%lld", &s);
  for (int i = 0; (1LL << i) <= s; i ++)
    for (int j = 0; (1LL << j) <= s; j ++) ans += calc(i, j);
  printf("%lld\n", ans);
  return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
const int MAXN = 55;
ll s,f[MAXN][MAXN*2][2],pw[MAXN];
inline ll dp(ll s, int a, int b, int t)
{
	memset(f,0,sizeof(f));
	f[1][0][0] = 1;
	for(int i = 1; i<=log2(s)+1; i++)
	{
        int v = (s>>i)&1;
        for(int j = 0; j<=2*i-2; j++)
            for(int k = 0; k<=1; k++)
                if(f[i][j][k])
                    for(int x = 0; x<=1; x++)
                        if(!x||i<a)
                            for(int y = 0; y<=1; y++)
                                if(!y||i<b)
                                    if((k+x+y)%2==v)
                                        f[i+1][j+x+y][(k+x+y)/2] += f[i][j][k];
	}
	return f[(int)log2(s)+2][t][0];
}

int main()
{
	cin >> s;
	pw[0] = 1;
	for(int i = 1; i<=60; i++)
	    pw[i] = pw[i-1]<<1;
	ll ans = 0;
	// case 1
	for(int h = 1; (pw[h]-1)<=s; h++)
	{
        ll x = s/(pw[h]-1);
        ll y = s-x*(pw[h]-1);
	    for(int i = 60; i>=1; i--)
		    if(y>=pw[i]-1)
			    y -= pw[i]-1;
		if(!y)
		    ans++;
	}
	// case 2
	for(int i = 1; (pw[i]-1)<=s; i++)
	    for(int j = 1; (pw[j]-1)<=s; j++)
	    {
	        ll x = (s-pw[j]+1)/(pw[i+1]+pw[j+1]-3);
	        if(!x)
			    continue;
			ll y = (s-pw[j]+1)-x*(pw[i+1]+pw[j+1]-3);
			if(!y)
			{
	            ans++;
	            continue;
			}
			if(i==1&&j==1)
		    {
		        if(y==5*x+1)
		            ans++;
		        continue;
			}
			for(int k = 1; k<=i+j; k++)
			    if((y+k)%2==0)
			        ans += dp(y+k,i,j,k);
	    }
	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int i,j,k,l,r,cnt,a,b;
long long s,p[52],f[52][102][2],ans;
int count(long long x)
{
	int ans=0;
	for(long long i=0;(1LL<<i)<=x;i++){
		if(x&(1LL<<i)) ans++;
	}
	return ans;
}
signed main()
{
	scanf("%lld",&s);
	int h=log2(1.0*s)+1;
	for(i=p[0]=1;i<=h;i++) p[i]=p[i-1]*2;
	for(l=1;l<=h;l++){
		long long x=s/(p[l]-1);
		if(x==0) break;
		for(cnt=0;cnt<=l-1;cnt++){
			long long tmp=s-x*(p[l]-1)+cnt;
			if(tmp%2==0&&count(tmp)==cnt) ans++;
		}
	}
	for(l=2;l<=h;l++){
		for(r=2;r<=h;r++){
			long long x=(s-p[r-1]+1)/(p[l]+p[r]-3);
			if(x==0) break;
			for(cnt=0;cnt<=l+r-4;cnt++){
				long long tmp=s-x*(p[l]+p[r]-3)-p[r-1]+1+cnt;
				if(tmp%2!=0) continue;
				memset(f,0,sizeof(f));
				f[0][0][0]=1;
				for(i=1;i<=max(l,r);i++){
					for(j=0;j<=min(cnt,2*(i-1));j++){
						for(k=0;k<=1;k++){
							for(a=0;a<=1;a++){
								for(b=0;b<=1;b++){
									if((k+a+b)%2==(tmp>>i)%2&&(a==0||i<l-1)&&(b==0||i<r-1)){
										f[i][j+a+b][(k+a+b)/2]+=f[i-1][j][k];
									}
								}
							}
						}
					}
				}
				ans+=f[max(l,r)][cnt][0];
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
//#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef pair<int,int> pa;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;typedef double db;
const int N=5e5+5,M=2e6+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
ll n,ans,f[140][2],g[140][2];
#define pw(a) (1ll<<(a))
ll dp(int one,int la,int lb,ll sum){
	rep(j,0,one)f[j][0]=f[j][1]=0;
	f[0][0]=1;
	for(int i=0;pw(i)<=sum;i++){
		rep(j,0,one)rep(o,0,1)g[j][o]=f[j][o],f[j][o]=0;
		rep(j,0,1)if(i<la||!j)
			rep(k,0,1)if(i<lb||!k)
				rep(l,0,1){
					int d=l+j+k;
					if(((sum>>i)&1)^(d&1))continue;
					for(int m=0;m+j+k<=one;m++)
						f[m+j+k][d>>1]+=g[m][l];
				}
	}
	return f[one][0];
}
int main(){
	read(n);
	rep(i,0,58)rep(j,0,58){
		ll mul=(pw(i+1)+pw(j+1)-3);
		if(n<mul)break;
		ll now=n%mul-(pw(j)-1);
		if(now<0)continue;
		int cnt=i+j;
		for(int k=now&1;k<=cnt;k+=2){
			ll tot=now+k;
			ans+=dp(k,i-1,j-1,tot>>1);
		}
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

LL s,ans;
LL f[2][150][2];

inline LL dp(int c,int a,int b,LL s){
	int i;
	memset(f,0,sizeof(f));
	f[1][0][0]=1;
	for(i=0;(1ll<<i)<=s;i++){
		memset(f[i&1],0,sizeof(LL)*300);
		for(int k=0;k<=c;k++)
			for(int aa=0;!aa || aa<=1 && i<a;aa++)
				for(int bb=0;!bb || bb<=1 && i<b;bb++){
					int t=(s>>i)&1^aa^bb;
					f[i&1][k+aa+bb][t+aa+bb>>1]+=f[(i&1)^1][k][t];
				}
	}
	return f[(i&1)^1][c][0];
}
int main()
{
	cin >> s;
	for(int a=0;a<60;a++)
		for(int b=0;b<60;b++){
			LL tt=(1ll<<a+1)+(1ll<<b+1)-3;
			if(tt>s) break;
			LL r=s%tt-(1ll<<b)+1;
			for(int c=0;c<=a+b;c++) if(r+c>=0 && !((r+c)%2))
				ans+=dp(c,a-1,b-1,r+c>>1);
		}
	cout << ans << endl;;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,dp[55][105][2];
int calc(int cnt,int l,int r,int res)
{
    memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;
    int maxn=0;
    for (int i=1;(1ll<<i)<=res;i++)
    {
        maxn=i;
        for (int j=0;j<=min(cnt,2*i);j++)
        {
            for (int p1=0;p1<=(i<l);p1++)
            {
                for (int p2=0;p2<=(i<r);p2++)
                {
                    if (j+p1+p2>cnt) continue;
                    int k=(res>>i)&1;
                    k^=p1;
                    k^=p2;
                    dp[i][j+p1+p2][(k+p1+p2)/2]+=dp[i-1][j][k];
                }
            }
        }
    }
    return dp[maxn][cnt][0];
}
signed main()
{
    cin>>n;
    int ans=0;
    for (int i=0;(1ll<<i)<=n;i++)
    {
        for (int j=0;(1ll<<j)<=n;j++)
        {
            int tmp1=(1ll<<i)-1,tmp2=(1ll<<j)-1;
            int tmp=2*tmp1+2*tmp2+1;
            int tot=n-(1ll<<j)+1;
            int x=tot/tmp;
            if (x<=0) continue;
            int res=tot-tmp*x;
            if (res<0) continue;
            if (!res)
            {
                ans++;
                continue;
            }
            int anss=ans;
            for (int k=0;k<=i+j-(!i)-(!j);k++)
                if ((res+k)%2==0) ans+=calc(k,i,j,res+k);
        }
    }
    cout<<ans;
}

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;

int K;
ll twos[110];
map <pair <ll, pair <int, int> >, ll> mp;

ll dfs(ll sum, int pos, int cnt){
	pair <ll, pair <int, int> > st = make_pair(sum, make_pair(pos, cnt));
	if(mp.find(st) != mp.end()) return mp[st];

	if(pos == K){
		return (mp[st] = ((cnt == 0 && sum == 0) ? 1 : 0));
	}

	ll ans = 0;
	int i;

	REP(i,2){
		ll sum2 = sum - twos[pos] * i;
		int pos2 = pos + 1;
		int cnt2 = cnt - i;

		if(cnt2 < 0 || sum2 < 0) continue;
		if(pos2 < K && sum2 % twos[pos2] != 0) continue;

		ans += dfs(sum2, pos2, cnt2);
	}

	return mp[st] = ans;
}

ll func(ll target, int p2, int q2){ // cerr << target << ' ' << p2 << ' ' << q2 << endl;
	int i;

	K = 0;
	REP(i,p2){
		twos[K] = (2ll<<i);
		K++;
	}
	REP(i,q2){
		twos[K] = (2ll<<i);
		K++;
	}
	sort(twos, twos + K);

	mp.clear();

	ll ans = 0;
	REP(i,K+1){
	//	mp.clear();
		ans += dfs(target + i, 0, i);
	}

	return ans;
}

ll main2(ll N, int p, int q){
	int i;

	ll coef = (2ll<<p) + (2ll<<q) - 3;

	int p2 = max(p-1, 0);
	int q2 = max(q-1, 0);

	ll max_sum = 0;
	REP(i,p2) max_sum += (2ll<<i) - 1;
	REP(i,q2) max_sum += (2ll<<i) - 1;

	ll c = 0;
	if(q > 0) c = (1ll<<q) - 1;

	ll ans = 0;
	for(ll x=N/coef;x>=1;x--){
		ll target = N - x * coef - c;
		if(target > max_sum) break;
		if(target >= 0) ans += func(target, p2, q2);
	}

	return ans;
}

int lca(int p, int q){
	if(p == q) return p;
	if(p > q) swap(p, q);
	return q + lca(p, q/2);
}

int brute(int N){
	int ans = 0;
	for(int i=1;i<=N;i++) for(int j=i;j<=N;j++) if(lca(i, j) == N) ans++;
	return ans;
}

int main(void){
	ll N;
	cin >> N;

	ll ans = 1;
	int p,q;
	REP(p,50) REP(q,50) if(p > 0 || q > 0) ans += main2(N, p, q);
	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr ll B = 52;
ll dp[2][B+1][B+B+1];

ll solve(ll sum, ll bits, ll dmax, ll emax) {
	ll lastbit = 1;
	while ((1LL<<lastbit) <= sum) ++lastbit;

	for (int b = 0; b <= bits; ++b)
		dp[0][0][b] = dp[1][0][b] = 0;
	dp[0][0][0] = 1;

	for (int b = 1; b < lastbit; ++b) {
		sum >>= 1;
		for (int bt = 0; bt <= bits; ++bt) {
			// turn nothing on
			dp[0][b][bt] = dp[sum&1][b-1][bt];
			dp[1][b][bt] = 0; // reset for ease
			// turn d on
			if (bt > 0 && b <= dmax) dp[1^sum&1][b][bt] += dp[1^sum&1][b-1][bt-1];
			// turn e on
			if (bt > 0 && b <= emax) dp[1^sum&1][b][bt] += dp[1^sum&1][b-1][bt-1];
			// turn d,e on
			if (bt > 1 && b <= dmax && b <= emax)
				dp[1][b][bt] += dp[sum&1][b-1][bt-2];
		}
	}
	ll r = dp[0][lastbit - 1][bits];
	return r;
}

int main() {
	ll s, ans = 0;
	cin >> s;

	for (ll d = 1; d <= B; ++d)
		for (ll e = 1; e <= B; ++e) {
			ll G = ((1LL << d) + (1LL << e) - 3LL);
			ll x = s/G;
			if (x < 1) continue;
			ll r = s - x * G;
			r -= ((1LL << (e - 1)) - 1LL);
			if (r < 0) continue;
			if (r > (1LL << d) + (1LL << e) - d - e - 2LL)
				continue;
//			cerr << "Trying " << d << ' ' << e << ", making " << r << ", starting at " << x << endl;
			for (ll bits = r % 2; bits < max(2LL, d + e - 2LL); bits += 2)
				ans += solve(r+bits, bits, d-2, e-2);
		}

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il ll gi(){
    ll x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch))f^=ch=='-',ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f?x:-x;
}
ll p2[51];
il int Log2(ll n){
    int ret=0;while(n>1)n>>=1,++ret;
    return ret;
}
std::unordered_map<ll,ll>calced[51][51];
il ll dfs(int a,int b,ll n){
    if(n<0)return 0;
    if(a<b)std::swap(a,b);
    if(a<=0)return!n;
    if(p2[a+1]+p2[b+1]-a-b-4<n)return 0;
    if(calced[a][b].count(n))return calced[a][b][n];
    return calced[a][b][n]=dfs(a-1,b,n)+dfs(a-1,b,n-p2[a]+1);
}
int main(){
    p2[0]=1;for(int i=1;i<=50;++i)p2[i]=p2[i-1]<<1;
    ll n=gi(),ans=0;
    for(ll L=0;L<50;++L)
        for(ll R=0;R<50;++R)
            if(p2[L+1]+3*p2[R]-4<=n){
                ll p=(n-p2[R]+1)/(p2[L+1]+p2[R+1]-3);
                ans+=dfs(L-1,R-1,n-p2[R]+1-p*(p2[L+1]+p2[R+1]-3));
            }
    printf("%lld\n",ans);
    return 0;
}

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

LL ret, ans;
LL dp[55][105][2];

int cnt_w(int cho, int cb)
{
	if(cb < 0 || cho < cb) return 0;
	if(cb == 1) return cho;
	else return 1;
}

void gen_dp(int id, int a, int b, int mc, LL targ)
{
	for(int i = 0; i <= mc; i ++) rep(j, 2) dp[id][i][j] = 0;
	int cho = (id >= 1 && id < a) + (id >= 1 && id < b);
	int cb = (targ >> id) & 1;
	for(int i = 0; i <= mc; i ++) rep(j, 2) {
		if(cb + (j << 1) >= 0 && cb + (j << 1) <= 2)
		dp[id][i + (cb + (j << 1))][0] += dp[id + 1][i][j] * cnt_w(cho, cb + (j << 1));
		if(cb + (j << 1) - 1 >= 0 && cb + (j << 1) - 1 <= 2)
		dp[id][i + (cb + (j << 1) - 1)][1] += dp[id + 1][i][j] * cnt_w(cho, cb + (j << 1) - 1);
	}
}

LL solve(int a, int b, LL targ)
{
	int mc = max(a - 1, 0) + max(b - 1, 0);
	int len = targ + mc == 0 ? 0 : 64 - __builtin_clzll(targ + mc);

	memset(dp, 0, sizeof(dp));
	dp[len][0][0] = 1;

	for(int i = len - 1; i >= 0; i --) gen_dp(i, a, b, mc, targ);

	LL res = 0;

	for(int c = 0; c <= mc; c ++) {
		res += dp[0][c][0];

		targ ++;
		for(int i = __builtin_ctzll(targ); i >= 0; i --) gen_dp(i, a, b, mc, targ);
	}

	return res;
}

int main()
{
	scanf("%I64d", &ret);

	for(int a = 0; (1LL << a + 1) - 1 <= ret; a ++)
	for(int b = 0; (1LL << a + 1) + (1LL << b + 1) + (1LL << b) - 4 <= ret; b ++)
	ans += solve(a, b, (ret - (1LL << b) + 1) % ((1LL << a + 1) + (1LL << b + 1) - 3));

	printf("%I64d\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

long long dp[2][120][2];
long long b[60];
int s[3];

long long calc1(int A, int C, long long N) {
	if (N > bitl(A+1)-2) return 0;
	if (cntl(N) == C) return 1;
	return 0;
}

long long calc(int A, int B, int C, long long N) {
	if (N > bitl(A+1)-2 + bitl(B+1)-2) return 0;
	int now = 0, max_cnt = 0;
	dp[0][0][0] = 1;
	dp[0][0][1] = 0;
	for (int i = max(A, B)+1; i >= 1; i--) {
		now ^= 1;
		int cur_cnt = (i <= A) + (i <= B);
		for (int j = 0; j <= min(C, max_cnt + cur_cnt); j++) dp[now][j][0] = dp[now][j][1] = 0;
		s[0] = s[1] = s[2] = 0;
		s[0] = s[cur_cnt] = 1;
		if (cur_cnt == 2) s[1] = 2;
		int cur_bit = N >> i & 1;
		for (int j = 0; j <= max_cnt; j++) {
			if (dp[!now][j][0]) {
				dp[now][j+cur_bit][0] += dp[!now][j][0] * s[cur_bit];
				if (cur_bit) dp[now][j][1] += dp[!now][j][0];
			}
			if (dp[!now][j][1]) {
				dp[now][j+cur_bit+1][1] += dp[!now][j][1] * s[cur_bit+1];
				if (!cur_bit) dp[now][j+cur_bit+2][0] += dp[!now][j][1] * s[2];
			}
		}
		max_cnt = min(max_cnt + cur_cnt, C);
	}
	return (C > max_cnt ? 0 : dp[now][C][0]);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	long long n; cin >> n;
	for (int i = 0; i <= 50; i++) b[i] = (1LL<<i)-1;
	long long ans = 0;
	for (int i = 0; i < 50; i++) {
		if (b[i+1] > n) break;
		for (int j = 0; j < 50; j++) {
			if (b[i+1]+b[j+1]-1 > n) break;
			long long mod = b[i+1] + b[j+1] - 1;
			long long ret = n - b[j];
			if (ret < mod) continue;
			ret %= mod;
			if (i == 0 && j == 0) {
				ans++;
				continue;
			}
			if (i == 0) {
				for (int k = 0; k <= j-1; k++) {
					if (ret + k & 1) continue;
					ans += calc1(j-1, k, ret+k);
				}
			} else if (j == 0) {
				for (int k = 0; k <= i-1; k++) {
					if (ret + k & 1) continue;
					ans += calc1(i-1, k, ret+k);
				}
			} else {
				for (int k = 0; k <= i-1+j-1; k++) {
					if (ret + k & 1) continue;
					ans += calc(i-1, j-1, k, ret+k);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

ll s;

bool read() {
  if (scanf("%lld", &s) < 1) {
    return false;
  }
  return true;
}

const int maxn = 110;

ll dp[2][maxn], ndp[2][maxn];

void solve() {
  ll res = 0;
  for (int left = 0; left < maxn / 2; left++) {
    for (int right = 0; right < maxn / 2; right++) {
      ll a = 1;
      a += (1ll << (left + 1)) - 2;
      a += (1ll << (right + 1)) - 2;
      if (s < a) {
        continue;
      }
      ll rem = s % a;
      if (right) {
        rem -= (1ll << right) - 1;
        if (rem < 0) {
          continue;
        }
      }
      //eprintf("left = %d, right = %d, rem = %lld\n", left, right, rem);
      memset(dp, 0, sizeof(dp));
      dp[0][rem & 1] = 1;
      for (int i = 1; i < maxn / 2; i++) {
        memset(ndp, 0, sizeof(ndp));
        for (int r = 0; r < 2; r++) {
          for (int j = 0; j < maxn; j++) {
            if (!dp[r][j]) {
              continue;
            }
            ll real = (rem & ((1ll << i) - 1)) + j;
            real = (real & ((1ll << i) - 1));
            if (r) {
              real += (1ll << i);
            }
            int mx1 = 0, mx2 = 0;
            if (i <= left - 1) {
              mx1++;
            }
            if (i <= right - 1) {
              mx2++;
            }
            for (int x = 0; x <= mx1; x++) {
              for (int y = 0; y <= mx2; y++) {
                ll cur = real + ((1ll << i) - 1) * (x + y);
                ll val = (cur - rem) & ((1ll << (i + 1)) - 1);
                if (val >= maxn) {
                  continue;
                }
                ndp[!!(cur & (1ll << (i + 1)))][val] += dp[r][j];
              }
            }
          }
        }
        swap(dp, ndp);
      }
      res += dp[0][0];
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
ll n,ans;
map<ll,ll> mp[55][55];
ll Func(ll L,ll R,ll v){
	if (L>R) swap(L,R);
	if (!L&&!R) return !v;
	if (mp[L][R].find(v)!=mp[L][R].end()) return mp[L][R][v];
	if (v<0||v>(1ll<<L)+(1ll<<R)-L-R-2) return 0;
	return mp[L][R][v]=Func(L,R-1,v)+(R==1?0:Func(L,R-1,v-(1ll<<(R-1))+1));
}
/*
0  2
1  4
3  8
11 16
26 32
x 2x 4x 8x
*/
int main(){
	scanf("%lld",&n);
	for (int L=0;1ll<<(L+1)<=n+1;++L)
		for (int R=0;(1ll<<(L+1))+(3ll<<R)<=n+4;++R){
			ll s1=(1ll<<(L+1))+(1ll<<(R+1))-3,s2=(1ll<<R)-1;
			ll f=(n-s2)/s1,g=n-s1*f-s2;
			//cout<<L<<' '<<R<<' '<<f<<' '<<g<<' '<<ans<<endl;
			ans+=Func(L,R,g);
		}
	printf("%lld\n",ans);
}

#include <bits/stdc++.h>

#define pw2(a) (1LL<<(a))
#define BIT(a,x) (((a)>>(x))&1)

using namespace std;

typedef long long LL;

const int BASE = 70;

LL dataf[BASE][BASE*2][2];

int main() {
    LL s;
    scanf("%lld", &s);

    LL ans = 0;

    LL (*f)[BASE*2][2] = dataf+1;

    for (int le = 0; ; le++) {
        LL t1 = pw2(le+1);
        if (t1-1 > s) break;
        for (int ri = 0; ; ri++) {
            LL t2 = pw2(ri+1);
            if (t1+t2-3 > s) break;
            LL v = s / (t1+t2-3);
            LL tg = s - (v-1) * (t1+t2-3) + 1;

//            cout << le << ' ' << ri << ' ' << v << ' ' << tg << endl;

            int maxbase = max(le+1,ri+1);
            int maxc = le+ri;
            // init
            for (int sumc = 0; sumc <= maxc; sumc++)
                f[-1][sumc][0] = f[-1][sumc][1] = 0;

            f[-1][0][0] = 1;

            // solve
            for (int dsumc = 0; dsumc <= maxc; dsumc++) {
                LL tg2 = tg + dsumc + 2;
                if (tg2 & 1) continue;
                tg2 >>= 1;
                tg2 -= pw2(le) + pw2(ri);
                if (tg2 < 0) continue;
                for (int i = -1; i < maxbase; i++) {
                    for (int sumc = 0; sumc <= maxc; sumc++)
                        f[i+1][sumc][0] = f[i+1][sumc][1] = 0;

                    for (int sumc = 0; sumc <= maxc; sumc++)
                    for (int nho = 0; nho < 2; nho++) {
                        if (f[i][sumc][nho] == 0) continue;
                        int tgbit = BIT(tg2,i+1);
                        for (int b1 = 0; b1 < 2; b1++) {
                            if (b1 == 1 && i+1 >= le) continue;
                            if (i+1 == le-1 && b1 != 0) continue;
                            for (int b2 = 0; b2 < 2; b2++) {
                                if (b2 == 1 && i+1 >= ri) continue;
                                if (i+1 == ri-1 && b2 != 1) continue;
                                int kq = (b1+b2+nho);
                                if ((kq&1) != tgbit) continue;
                                if (sumc + b1 + b2 > maxc) continue;
                                kq >>= 1;
                                f[i+1][sumc+b1+b2][kq] += f[i][sumc][nho];
                            }
                        }
                    }
                }
//                cout << "sumc = " << dsumc << ", tg2 = " << tg2 << ": " << f[maxbase][dsumc][0] << endl;
                ans += f[maxbase][dsumc][0];
            }
        }
    }

    printf("%lld", ans);
}

#include <sstream>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cassert>
#include <bitset>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef long long LL;
typedef long long ll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=1e9+7;
const LL maxn=1e6+7;
const double pi=acos(-1.0);
const double eps=0.00000001;
LL gcd(LL a, LL b) {return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a, T b) {
    T ret=1;
    for (; b; b>>=1ll,a=(LL)a*a%M)
        if (b&1) ret=(LL)ret*a%M;
    return ret;
}

//a+b-c=now
ll f[67][67][2];
ll solve(int a,int b,int cnt,ll now){
    if (now<0) return 0;
    int t=0,i,j,k,l,p;
    while ((1ll<<t)<=now) t++;
    if (t>max(a,b)+1) return 0;
    FOR(l,0,cnt) f[0][l][0]=f[0][l][1]=0;
    f[0][0][0]=1;
    REP(k,t){
        FOR(l,0,cnt) f[k+1][l][1]=f[k+1][l][0]=0;
        int maxi=(k<a),maxj=(k<b),o=(now>>k)&1;
        FOR(i,0,maxi) FOR(j,0,maxj) FOR(p,0,1){
            int O=(i+j+p-o); if (O<0||(O&1)) continue;
            FOR(l,0,cnt) f[k+1][l+i+j][O]+=f[k][l][p];
        }
    }
//    debug("%d %d %d %I64d:  %I64d\n",a,b,cnt,now,f[t][cnt][0]);
    return f[t][cnt][0];
}
int TaskA(){
    int m,i,j,k; ll n;
    scanf("%I64d",&n);
    ll ans=0;
    FOR(i,0,50) FOR(j,0,50){
        ll mul=(1ll<<(i+1))-1+(1ll<<(j+1))-1-1;
        if (n<mul) break;
        ll now=n%mul-(1ll<<j)+1;
        if (now<0) continue;
        //a<(1<<i); b<(1<<j)
        //a+b-popcnt=now
//        debug("calc: %d(len) + %d(len) - popcnt = %I64d(now); %I64d(mul)\n",i,j,now,mul);
        for (k=now&1;k<=(i+j);k+=2)
            ans+=solve(i-1,j-1,k,(now+k)/2);
    }printf("%I64d\n",ans);
    return 0;
}
void initialize(){}
int main() {
	int startTime=clock();
	//initialize
	initialize();
	debug("/--- initializeTime: %ld milliseconds ---/\n",clock()-startTime);
	int T=1;
//	scanf("%d",&T);
	startTime=clock();
	while (T--) TaskA();
	debug("/--- computeTime: %ld milliseconds ---/\n",clock()-startTime);
}
/*
*/

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<unordered_set>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
typedef unsigned uint;
typedef unsigned long long uLL;
const double pi=acos(-1);
template<class T>
void Read(T &x){
	char c;
	bool f(0);
	while(c=getchar(),c!=EOF){
		if(c=='-')
			f=1;
		else if(c>='0'&&c<='9'){
			x=c-'0';
			while(c=getchar(),c>='0'&&c<='9')
				x=x*10+c-'0';
			ungetc(c,stdin);
			if(f)
				x=-x;
			return;
		}
	}
}
//
LL s,f[2][140][2],ans;
LL dp(int ones,int len1,int len2,LL tot){
	memset(f,0,sizeof f);
	int i,now=0,a,b,d,j;
	f[0][0][0]=1;
	for(i=0;(1ll<<i)<=tot;i++){
		now^=1;
		memset(f[now],0,sizeof f[now]);
		for(a=0;a<2;a++)
			if(!a||i<len1)
				for(b=0;b<2;b++)
					if(!b||i<len2)
						for(d=0;d<2;d++)
							if(((a+b+d)&1)==((tot>>i)&1))
								for(j=0;j+a+b<=ones;j++)
									f[now][j+a+b][(a+b+d)>>1]+=f[now^1][j][d];
	}
	return f[now][ones][0];
}
int main()
{
	Read(s);
	int a,b,i;
	LL lca,cnt,rm,tot;
	for(a=1;a<=58;a++)
		for(b=1;b<=58;b++){
			cnt=(1ll<<(a+1))-1+(1ll<<(b+1))-1-1;
			lca=s/cnt;
			if(!lca)
				continue;
			rm=s%cnt-(1ll<<b)+1;
			for(i=0;i<=a+b;i++){
				tot=rm+i;
				if(tot<0||(tot&1))
					continue;
				ans+=dp(i,a-1,b-1,tot>>1);
			}
		}
	printf("%I64d\n",ans);
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXDEP = 58;
LL f[2][140][2];
LL solve(int ones, int len1, int len2, LL tot){
    memset(f, 0, sizeof f);
    f[0][0][0] = 1;
    for(int i=0;(1LL<<i)<=tot;i++){
        swap(f[0], f[1]);
        memset(f[0], 0, sizeof f[0]);
        for(int a=0;a<2;a++) if(!a || i<len1){
            for(int b=0;b<2;b++) if(!b || i<len2){
                for(int d=0;d<2;d++) if(((a+b+d)&1) == (tot&(1LL<<i))){
                    for(int j=0;j+a+b<=ones;j++){
                        f[0][j+a+b][(j+a+b)>>1] += f[1][j][d];
                    }
                }
            }
        }
    }
    return f[0][ones][0];
}
int main(){
    LL s, lca, ct, rm, tot, ans = 0;
    scanf("%I64d", &s);
    for(int a=0;a<=MAXDEP;a++){
        for(int b=0;b<=MAXDEP;b++){
            ct = (1LL<<(a+1))+(1LL<<(b+1))-3;
            lca = s/ct;
            if(lca == 0) continue;
            rm = s%ct-(1LL<<b)+1;
            for(int i=0;i<=(a+b);i++){
                tot = rm+i;
                if(tot < 0 || (tot&1)) continue;
                ans += solve(i, max(a-1, 0), max(b-1, 0), tot>>1);
            }
        }
    }
    printf("%I64d\n", ans);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define repd(i,j,k) for(int i=j;i>=k;--i)
#define pb push_back
#define db double
#define pii pair<int,int>
#define piii pair<pair<ll,int>,int>
#define fr first
#define mp(a,b) make_pair(a,b)
#define mp3(a,b,c) mp(mp(a,b),c)
#define se second
#define ll long long
#define ull unsigned long long
#define pbc(x) __builtin_popcount(x)
#define clr(x) memset(x,0,sizeof x)
#define SIZE(x) (int)(x.size())
#define int ll
const int mod=998244353;
IL int pls(int x,int y){x+=y;return x>=mod?x-mod:x;}
IL int dec(int x,int y){x-=y;return x<0?x+mod:x;}
IL int mul(int x,int y){return 1ll*x*y%mod;}
IL int mul(int x,int y,int z){return mul(mul(x,y),z);}
IL int mul(int x,int y,int z,int p){return mul(mul(x,y),mul(z,p));}
IL void add(int &x,int y){x+=y;x=(x>=mod)?x-mod:x;}
IL int fpw(int x,int y,int r=1){for(;y;y>>=1,x=mul(x,x))if(y&1)r=mul(r,x);return r;}
IL int inv(int x){return fpw(x,mod-2);}
IL int gi(){int x;int _w=scanf("%lld",&x);return x;}
IL void gi(int &x){int _w=scanf("%lld",&x);}
IL void write(int x){printf("%lld\n",x);}
void chkmax(int &x,int y){x=(x>y)?x:y;}
void chkmin(int &x,int y){x=(x<y)?x:y;}
const int INF=0x3f3f3f3f;
template<typename T>IL void debug(T x){cerr<<x;return;}
/* --------------------------------------------------------------------------------------------------------- */
const int maxn=100;
int pw2[maxn];
map<int,int>F[maxn][maxn];
int path(int a,int b){
	int sum=0;
	while(a!=b){
		if(a<b)swap(a,b);
		sum+=a;
		a=a>>1;
	}return sum+a;
}
int calc(int x,int y,int val){
	if(val<0)return 0;
	if(x<=0&&y<=0)return val==0;
	if(pw2[x+1]-x-2+pw2[y+1]-y-2<val)return 0;
	if(x<y)swap(x,y);
	if(F[x][y].count(val))return F[x][y][val];
	return F[x][y][val]=calc(x-1,y,val)+calc(x-1,y,val-pw2[x]+1);
}
#undef int
int main(){
#define int long long
#ifdef LOCAL
	freopen("input.txt","r",stdin);
#endif
	int S;
	gi(S);
	pw2[0]=1ll;
	for(int i=1;pw2[i-1]<=S;++i)pw2[i]=pw2[i-1]<<1ll;

	int sum=0;
	int d=log(S)+1;
	rep(i,0,d-1)rep(j,0,d-1){
		if(pw2[i+1]+pw2[j]*3-4<=S){
			int pos=(S-pw2[j]+1)/(pw2[i+1]+pw2[j+1]-3);
			int MaxDeep=(int)(log2(pos+0.1))+1+max(i,j);
			sum+=calc(i-1,j-1,S-pw2[j]+1-pos*(pw2[i+1]+pw2[j+1]-3));
		}
	}
	printf("%lld\n",sum);
	return 0;
}
// Code by EDT : 2019-05-07 15:07:46
// Last update : 2019-05-07 16:52:25

#include<bits/stdc++.h>
#define maxn
using namespace std;
typedef long long LL;
#define G c=getchar()
inline LL read()
{
	LL x=0,f=1;char G;
	while(c>57||c<48){if(c=='-')f=-1;G;}
	while(c>47&&c<58)x=x*10+c-48,G;
	return x*f;
}
LL s,ans;
LL f[140][2],g[140][2];
LL solve(int o,int l0,int l1,LL tot)
{
	memset(f,0,sizeof(f));
	f[0][0]=1;
	for(int i=0;1LL<<i<=tot;i++)
	{
		memcpy(g,f,sizeof(f));
		for(int d0=0;d0<=1;d0++)if(d0==0||i<l0)
			for(int d1=0;d1<=1;d1++)if(d1==0||i<l1)
				for(int jw=0;jw<=1;jw++)
				{
					int dig=d0+d1+jw;
					if(dig%2!=((tot>>i)&1))continue;
					for(int k=0;k+d0+d1<=o;k++)
						f[k+d0+d1][dig/2]+=g[k][jw];
				}
	}
	return f[o][0];
}
int main()
{
	s=read();
	for(int a=0;a<=58;a++)
		for(int b=0;b<=58;b++)
		{
			LL mul=(1LL<<(a+1))-1+(1LL<<(b+1))-1-1;
			LL lca=s/mul;
			if(lca==0)continue;
			LL rem=s-lca*mul-(1LL<<b)+1;
			for(int o=0;o<=a+b;o++)
			{
				LL tot=rem+o;
				if(tot<0||(tot&1))continue;
				tot/=2;
				ans+=solve(o,max(a-1,0),max(b-1,0),tot);
			}
		}
	printf("%I64d",ans);
	return 0;
}

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

ll s;

bool read() {
  if (scanf("%lld", &s) < 1) {
    return false;
  }
  return true;
}

const int maxn = 110;

ll dp[2][maxn], ndp[2][maxn];

void solve() {
  ll res = 0;
  for (int left = 0; left < maxn / 2; left++) {
    for (int right = 0; right < maxn / 2; right++) {
      ll a = 1;
      a += (1ll << (left + 1)) - 2;
      a += (1ll << (right + 1)) - 2;
      if (s < a) {
        continue;
      }
      ll rem = s % a;
      if (right) {
        rem -= (1ll << right) - 1;
        if (rem < 0) {
          continue;
        }
      }
      //eprintf("left = %d, right = %d, rem = %lld\n", left, right, rem);
      memset(dp, 0, sizeof(dp));
      dp[0][rem & 1] = 1;
      for (int i = 1; i < 2; i++) {
        memset(ndp, 0, sizeof(ndp));
        for (int r = 0; r < 2; r++) {
          for (int j = 0; j < maxn; j++) {
            if (!dp[r][j]) {
              continue;
            }
            ll real = (rem & ((1ll << i) - 1)) + j;
            real = (real & ((1ll << i) - 1));
            if (r) {
              real += (1ll << (i + 1));
            }
            int mx1 = 0, mx2 = 0;
            if (i <= left - 1) {
              mx1++;
            }
            if (i <= right - 1) {
              mx2++;
            }
            for (int x = 0; x <= mx1; x++) {
              for (int y = 0; y <= mx2; y++) {
                ll cur = real + ((1ll << i) - 1) * (x + y);
                ll val = (cur - rem) & ((1ll << (i + 1)) - 1);
                if (val > maxn) {
                  continue;
                }
                ndp[!!(cur & (1ll << (i + 1)))][val] += dp[r][j];
              }
            }
          }
        }
        swap(dp, ndp);
      }
      res += dp[0][0];
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

#include <cstdio>
#include <cstring>
#include <cinttypes>
#include <functional>

#define BIT(p) ((1LL << ((p))))
#define SUM_BITS(p) (((1LL << (((p)) + 1)) - 1))
#define SUM_SUMS(p) (((1LL << (((p)) + 2)) - ((p)) - 3))

int main()
{
    std::function<int64_t(int64_t, int, int)> count_combinaions = [&count_combinaions](int64_t sum, int l, int r) {
        // std::printf("%" PRId64 "\t%d\t%d\n", sum, l, r);

        if (sum < 0)
            return (int64_t) 0;
        else if (sum == 0)
            return (int64_t) 1;
        else if (l == 0)
        {
            if (r == 0)
                return (int64_t) 0;
            else
            {
                int64_t max_right_sum = SUM_SUMS(r - 1);

                if (sum < max_right_sum)
                    return (int64_t) 0;
                else
                    return count_combinaions(sum, l, r - 1) + count_combinaions(sum - SUM_BITS(r - 1), l, r - 1);
            }
        }
        else if (r == 0)
        {
            int64_t max_left_sum = SUM_SUMS(l - 1);

            if (sum < max_left_sum)
                return (int64_t) 0;
            else
                return count_combinaions(sum, l - 1, r) + count_combinaions(sum - SUM_BITS(l - 1), l - 1, r);
        }
        else
        {
            int64_t max_left_sum = SUM_SUMS(l - 1);
            int64_t max_right_sum = SUM_SUMS(r - 1);

            if (sum < max_left_sum + max_right_sum)
                return (int64_t) 0;
            else
                return count_combinaions(sum, l - 1, r) + count_combinaions(sum - SUM_BITS(l - 1), l - 1, r);
        }
    };

    int64_t s;
    std::scanf("%" SCNd64, &s);

    int fls = sizeof(s) * 8 - __builtin_clzll(s);
    int64_t count = (s == SUM_BITS(fls - 1) ? fls : fls - 1);

    for (int l = 0; ; l++)
    {
        for (int r = 0; ; r++)
        {
            int64_t d = 2 * (SUM_BITS(l) + SUM_BITS(r)) + 1;
            if (d > s)
                goto FINISH;

            int64_t remainder = (s % d) - SUM_BITS(r);
            int64_t case_count = count_combinaions(remainder, l, r);

            if (case_count == 0)
            {
                if (r == 0)
                {
                    if (l == 0)
                        continue;
                    else
                        goto FINISH;
                }
                else
                    break;
            }
            else
                count += case_count;
        }
    }

FINISH:
    std::printf("%" PRId64 "\n", count);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 128;

LL f[2][N][2];
LL cal(int lx , int ly , int one , LL sum) {
  memset(f , 0 , sizeof(f));
  f[0][0][0] = 1;
  int cur = 0 , nxt = 1;
  for (int i = 0 ; (sum >> i) ; ++ i) {
    memset(f[nxt] , 0 , sizeof(f[nxt]));
    for (int dx = 0 ; dx < 2 ; ++ dx) {
      for (int dy = 0 ; dy < 2 ; ++ dy) {
        if (i >= lx && dx) continue;
        if (i >= ly && dy) continue;
        for (int j = 0 ; j < 2 ; ++ j) {
          int num = dx + dy + j;
          if ((sum >> i & 1) != (num & 1)) continue;
          for (int k = 0 ; k + dx + dy <= one ; ++ k) {
            f[nxt][k + dx + dy][num >> 1] += f[cur][k][j];
          }
        }
      }
    }
  }
  return f[cur][one][0];
}

int main() {
  LL s;
  cin >> s;
  LL res = 0;
  for (int a = 0 ; a <= 60 ; ++ a) {
    for (int b = 0 ; b <= 60 ; ++ b) {
      LL coff = (1LL << a + 1) + (1LL << b + 1) - 3;
      LL lca = s / coff , rem = s % coff - (1LL << b) + 1;
      if (lca < 1) continue;
      // 2(x + y) == rem + popcount(x) + popcount(y)
      // x < 2^{a-1} , y < 2^{b-1}
      for (int c = 0 ; c <= 120 ; ++ c) {
        LL sum = rem - c;
        if (sum < 0 || sum % 2 == 1) continue;
        sum >>= 1;
        res += cal(max(0 , a - 1) , max(0 , b - 1) , c , sum);
      }
    }
  }
  cout << res << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
typedef double db;
ll bit[65],f[65][120][2];//��{2,2^2,2^3...2^h1}��{2,2^2,...2^h2}֮��ѡtot���������==s��
inline ll dp(ll s,int tot,int h1,int h2){//Ӧ����{2-1,2^2-1,2^3-1...2^h1-1}��{2-1,2^2-1,...2^h2-1},�����Ѿ��Ѽ�һ�ƹ�ȥs��
	memset(f,0,sizeof f);f[0][0][0]=1;//��{2��2^2...}��ѡ��2^min(h1,h2)��֮ǰ��������ѡ������f[i][j][k]��ʾ������i������֮ǰ������i��ѡ��j����������һλ�Ľ�λΪk
	int ed=log2(s);//��ѡ��������
	rep(i,1,ed){
		ll d=(s>>i)&1;
		int ed=i*2-2;//�� i֮ǰ�����ѡ���ٸ�
		rep(j,1,ed) rep(k,0,1)/*��һλ�Ƿ��λ*/rep(p1,0,1)/*�����Ƿ������߼��Ƿ�ѡһ��2^i*/rep(p2,0,1)/*����ͬ��*/if((i<h1||p1==0)&&(i<h2||p2==0)&& (p1+p2+k)%2==d)/*��Ϊx�����Ҷ��Ӽ�2^h1��2^h2�ǿ϶�Ҫѡ��*/
		f[i][j+p1+p2][(k+p1+p2)/2]+=f[i-1][j][k];
	}
	return f[ed][tot][0];
}
int main(){
	ll x,s,res,ans=0;
	int ed=0;
	scanf("%lld",&s);
	bit[0]=1;while(bit[ed]<=s) bit[++ed]=bit[ed-1]<<1;
	rep(i,1,ed){//ͳ��һ���������
		if(bit[i]-1>s) break;
		x=s%(bit[i]-1);
		for(int j=i;j>=1;--j) if(x>=bit[j]-1) x-=bit[j]-1;
		if(!x) ++ans;
	}
	rep(h1,1,ed-1){//ͳ���зֲ�����
		for(int h2=1;bit[h2]-1<=s&&h2<ed;++h2){//ö�����ߵ����� h1  h2
			x=(s-bit[h2]+1)/(bit[h1+1]+bit[h2+1]-3);
			if(x>0){
				res=(s-bit[h2]+1)%(bit[h1+1]+bit[h2+1]-3);
				if(res==0){//����������
					++ans;continue;
				}
				if(h1==1&&h2==1){//xֻѡ�������x*2���Ҷ���x*2+1 ,������x*5+1
					ans+=(s==x*5+1);continue;
				}//������˵����ĳЩ��Ҫ������
				rep(i,1,h1+h2) if((res+i)%2==0) ans+=dp(res+i,i,h1,h2);//�൱�ڰѼ����� i��һŲ����ʽ��һ�߱�ɼ� i��һ
			}
		}
	}
	printf("%lld",ans);
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}
template <typename T> void add(T &x, T y, T mod) {x = x + y > mod ? x + y - mod : x + y;}
template <typename T> void sub(T &x, T y, T mod) {x = x - y < 0 ? x - y + mod : x - y;}
template <typename T> void multi(T &x, T y, T mod) {x = 1ll * x * y % mod;}

typedef long long ll;
typedef unsigned long long ull;

const int INF = (1ll << 30);

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

template <typename T> void read (T &x) {
    x = 0; bool f = 1; char ch;
    do {ch = getchar(); if (ch == '-') f = 0;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0'; ch = getchar();} while (ch >= '0' && ch <= '9');
    x = f ? x : -x;
}

template <typename T> void write (T x) {
    if (x < 0) x = ~x + 1, putchar ('-');
    if (x > 9) write (x / 10);
    putchar (x % 10 + '0');
}

const int N = 50 + 5;

ll s, ans, f[N][N << 1][2];
int n;

inline bool check(ll res, ll x) {
    // cout << "res = " << res << " x = " << x << endl;
    for(int i = x - 1; i >= 0; i--) if(res >= ((1ll << i) - 1)) res -= ((1ll << i) - 1);
    // cout << "res = " << res << " x = " << x << endl;
    return res == 0;
}

inline ll dp(ll bit, ll n, ll m, ll ret) {
    memset(f, 0, sizeof(f));
    if(ret % 2 != 0) return 0;
    f[0][0][0] = 1; int pos = 1;
    for(int i = 1; (1ll << i) <= ret; i++) {
        pos = i;
        for(int j = 0; j <= bit; j++) {
            for(int x = 0; x < 2; x++) {
                if(!x || i < n)
                for(int y = 0; y < 2; y++) {
                    if(!y || i < m) {
                        if((x + y) % 2 == (ret & (1 << i))) f[i][j + x + y][(x + y) % 2] += f[i - 1][j][0];
                        else f[i][j + x + y][(x + y + 1) % 2] += f[i - 1][j][1];
                    }
                }
            }
        }
    }
    return f[pos - 1][bit][0];
}

int main() {
    read(s);
    for(int i = 1; i < 55; i++) {
        ll x = s / ((1ll << i) - 1);
        ll res = s - ((1ll << i) - 1) * x;
        if(!x) continue;
        if(check(res, i)) ans ++ ;
    }
    // cout << "ans = " << ans << endl;
    for(int h1 = 1; h1 < 55; h1++) {
        for(int h2 = 1; h2 < 55; h2++) {
            // if(n < ((1ll << (h1 + 1)) + (1ll << (h2 + 1)))) break;
            ll x = (s - (1ll << h2) + 1) / ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3);
            ll ret = s - (1ll << h2) + 1 - x * ((1ll << (h1 + 1)) + (1ll << (h2 + 1)) - 3);
            if(!ret) {
                ans ++ ; continue;
            }
            for(int k = 1; k <= h1 + h2; k++) ans += dp(k, h1, h2, ret + k);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    void clear() { *this = hash_map_t(mod); }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 55;

ll f[N][N * 2][2], pw[N];
ll s, ans;

int main() {
    read(s);
    pw[0] = f[0][0][0] = 1;
    for(register int i = 1; i <= 50; i++) pw[i] = pw[i - 1] + pw[i - 1];
    for(register int a = 0; a <= 49; a++) {
        for(register int b = 0; b <= 49; b++) {
            if(!a && !b) { ++ans; continue; }
            ll x = (s - pw[b] + 1) / (pw[a + 1] + pw[b + 1] - 3);
            if(x <= 0) break;
            if(!a && b == 1) { ans += (s == x * 3 + 1); continue; }
            if(!b && a == 1) { ans += (s == x * 3); continue; }
            if(a == 1 && b == 1) { ans += (s == 5 * x + 1); continue; }
            // fprintf(stderr, "a = %d, b = %d, %I64d, %I64d\n", a, b, s - pw[b + 1] + 1, pw[a + 1] + pw[b + 1] - 3);
            ll last = s - (pw[a + 1] + pw[b + 1] - 3) * x - pw[b] + 1;
            if(!last) { ++ans; continue; }
            for(register int i = 0; i <= a + b - 2; i++) {
                ll now = last + i;
                if(now & 1) continue;
                int lim = max(a - 1, b - 1) + 1;
                if(now >= (1ll << (lim + 1))) continue;
                for(register int j = 1; j <= lim; j++) {
                    int zt = (now >> j) & 1;
                    memset(f[j], 0, sizeof(f[j]));
                    for(register int k = 0; k <= i; k++) {
                        for(register int t = 0; t <= 1; t++) {
                            if(f[j - 1][k][t]) {
                                for(register int x = 0; x <= 1; x++) {
                                    for(register int y = 0; y <= 1; y++) {
                                        if(x && j >= a) continue;
                                        if(y && j >= b) continue;
                                        if(((t + x + y) & 1) ^ zt) continue;
                                        f[j][k + x + y][(t + x + y) >> 1] += f[j - 1][k][t];
                                    }
                                }
                            }
                        }
                    }
                }
                ans += f[lim][i][0];
                // if(f[lim][i][0]) fprintf(stderr, "i = %d, a = %d, b = %d, val = %I64d, x = %I64d, now = %I64d\n", i, a, b, f[lim][i][0], x, now);
            }
            // fprintf(stderr, "a = %d, b = %d, ans = %I64d\n", a, b, ans);
        }
    }
    print(ans, '\n');
    return 0;
}

//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) (x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\n');x=c;}
inline void writes(string s){puts(s.c_str());}
inline void writeln(){writes("");}
inline void writei(int x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
inline void writell(ll x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)
#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define rep0(i,x) forup ((i),0,(x))
#define rep1(i,x) forup ((i),0,(x)-1)
#define rep2(i,x) forup ((i),(x)-1,0)
#define repd(i,x) fordo ((i),(x),1)
#define itr iterator
#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x1bbbbbbbbbbbbbbbll
#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
long long n,m,i,j,k,t,ans,pw[65],d,a,b,c,dp[65][105][2];
long long qry(long long x,long long y)
{
	long long s=0;
	while(x!=y){
		if(x<y) swap(x,y);
		s+=x;x/=2;
	}
	return s+x;
}
long long solve(long long rem,long long rt,long long h1,long long h2,long long num)
{
	memset(dp,0,sizeof(dp));
	long long i,j,k,x,y;
	dp[0][0][0]=1;
	rep(i,d){
		long long dig=((rem>>i)&1);
		rep0(j,num)rep1(k,2)if(dp[i-1][j][k]){
			rep1(x,2)if(!x||i<h1)rep1(y,2)if(!y||y<h2){
				long long t=k+x+y;
				if(t%2!=dig) continue;
				dp[i][j+x+y][(k+x+y)/2]+=dp[i-1][j][k];
			}
		}
	}
	return dp[d][num][0];
}
int main()
{
	pw[0]=1;
	rep(i,60){
		pw[i]=pw[i-1]*2ll;
	}
	{
		d=60;
		cin>>n;
		ans=0;
		rep(i,d){
			long long rt=(n/(pw[i]-1));
			if(rt<=0) continue;
			long long rem=n-rt*(pw[i]-1);
			rep2(j,i){
				if(rem>=(pw[j]-1)){
					rem-=pw[j]-1;
				}
			}
			if(!rem) ans++;
		}
		rep(i,d)rep(j,d){
			long long rt=((n-pw[j]+1)/(pw[i+1]+pw[j+1]-3));
			if(rt<=0) continue;
			long long rem=(n-pw[j]+1)-rt*(pw[i+1]+pw[j+1]-3);
			if(!rem){
				ans++;
				continue;
			}
			if(i==1&&j==1){
				ans+=(rem==(rt*5+1));
				continue;
			}
			rep(k,i+j)if((rem+k)%2==0){
				ans+=solve(rem+k,rt,i,j,k);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 400 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;
#define SUM(a, b) (( (a) % MOD + (b) % MOD ) % MOD )
#define MUL(a, b) (((i64)((a) % MOD) * ((b) % MOD)) % MOD)
const double EPS = 1e-7;

int main(){

   /* if(!freopen("data.in", "r", stdin)){
        return 0;
    }*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    i64 s;
    cin >> s;
    i64 ans = 0;
    for(int t1 = 0; t1 <= 60; t1++)
        for(int t2 = 0; t2 <= 60; t2++){
            i64 fac = (1LL << (t1 + 1)) + (1LL << (t2 + 1)) - 3;
            i64 a = s / fac;
            if(a == 0)continue;

            i64 r = s - a * fac;

            if(t1 == 0 && t2 == 0){
                ans += 1;
                continue;
            }

            if(t1 == 0){
                if(r <= ((1LL << t2) - 1) && r > 0)ans += 1;
                continue;
            }

            if(t2 == 0){
                if(r <= ((1LL << (t1 - 1)) - 1))ans += 1;
                continue;
            }

            i64 mn = max(0LL, r - ((1LL << (t2 - 1)) - 1));
            i64 mx = min(((1LL << (t1 - 1)) - 1), r - 1);
            //cout << a <<" " << mn << " " << mx << " " << t1 << " " << t2 << endl;
            ans += mx - mn + 1;
        }
    cout << ans << endl;

}

#include<bits/stdc++.h>
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define dec(i,j,k) for(re int i=j;i>=k;i--)
#define re register
#define ll long long
using namespace std;
const int N=52;
ll s,ans,base[N],f[N][2*N][2],x,ret;
int m;
ll cal(ll s,ll q,int a,int b){
	memset(f,0,sizeof(f)),f[0][0][0]=1;
	int ed=log2(s);
	inc(i,1,ed){
		int d=(s>>i)&1;
		inc(j,0,2*i-1){
			inc(k,0,1){
				inc(x,0,1){
					inc(y,0,1){
						if((i<a||x==0)&&(i<b||y==0)&&(x+y+k)%2==d) f[i][j+x+y][(k+x+y)/2]+=f[i-1][j][k];
					}
				}
			}
		}
	}
	return f[ed][q][0];
}
int main(){
	scanf("%lld",&s);base[0]=1;
	while(base[m]<=s) m++,base[m]=base[m-1]<<1;
	inc(i,1,m){
		if((x=s/(base[i]-1))==0) continue;
		ret=s-x*(base[i]-1);
		dec(j,i-1,0) if(ret>=base[j]-1) ret-=base[j]-1;
		if(!ret) ans++;
	}
	inc(i,1,m-1){
		for(re int j=1;base[j]-1<=s;j++){
			if((x=(s-base[j]+1)/(base[i+1]+base[j+1]-3))==0) continue;
			ret=(s-base[j]+1)-x*(base[i+1]+base[j+1]-3);
			if(!ret){ans++;continue;}
			if(i==1&&j==1){ans+=(5*x+1==s);continue;}
			inc(k,1,i+j) if((ret+i)%2==0) ans+=cal(ret+k,x,i,j);
		}
	}
	printf("%lld\n",ans);
}

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define maxn 64
ll n;
ll dp[maxn][2*maxn][2];
int m,p;
ll ans,mi[maxn];
ll calc(ll s,ll q,int a,int b,int t)
{
	memset(dp[p],0,sizeof(dp[p]));
	dp[p][0][0]=1;
	for(int i=2;i<=log2(s)+1;i++)
	{
		int d=(s>>i)&1;
		p^=1;
		memset(dp[p],0,sizeof(dp[p]));
		for(int j=0;j<=2*i-2;j++)
		{
			for(int k=0;k<=1;k++)
			{
				if(dp[p^1][j][k])
				{
					for(int x=0;x<=1;x++)
					{
						if(!x||i<a)
						{
							for(int y=0;y<=1;y++)
							{
								if(!y||i<b)
								{
									if((k+x+y)%2==d)
									{
										dp[p][j+x+y][(k+x+y)/2]+=dp[p^1][j][k];
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return dp[p][t][0];
}
int main()
{
	scanf("%lld",&n);
	mi[0]=1;
	ll x,ret;
	while(mi[m]<=n)
	{
		mi[m+1]=mi[m]<<1;
		m++;
	}
	mi[m+1]=mi[m]<<1;
	for(int i=1;i<=m;i++)
	{
		if((x=n/(mi[i]-1))>0)
		{
			ret=n-x*(mi[i]-1);
			for(int j=i-1;j;j--)
			{
				if(ret>=mi[j]-1)
				{
					ret-=mi[j]-1;
				}
			}
			if(!ret)
			{
				ans++;
			}
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;mi[j]-1<=n;j++)
		{
			if((x=(n-mi[j]+1)/(mi[i+1]+mi[j+1]-3))>0)
			{
				ret=(n-mi[j]+1)-x*(mi[i+1]+mi[j+1]-3);
				if(!ret)
				{
					ans++;
					continue;
				}
				if(i==1&&j==1)
				{
					ans+=(ret==5*x+1);
					continue;
				}
				for(int k=1;k<=i+j;k++)
				{
					if(~(ret+k)&1)
					{
						ans+=calc(ret+k,x,i,j,k);
					}
				}
			}
		}
	}
	printf("%I64d\n",ans);
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>
#define y1 y11
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define NAME ""

using namespace std;

typedef long long ll;
typedef long double ld;

const ld PI = acos(-1.0);

const int C = 58;

int c[3][3] = {{1, 0, 0}, {1, 1, 0}, {1, 2, 1}};

int main()
{
	ll s;
	cin >> s;
	ll ans = 0;
	for (int lc = 0; lc < C; lc++)
	{
		for (int rc = 0; rc < C; rc++)
		{
			ll vv = (1ll << (lc + 1)) + (1ll << (rc + 1)) - 3;
			ll ad = (1ll << rc) - 1;
			if (s < ad + vv) continue;
			ll a = (s - ad) / vv;
			ll b = s - a * vv - ad;
			ll f1 = 1, f2 = 0;
			for (int i = 0; (1 << i) <= b; i++)
			{
				int cn = 0;
				if (lc > i + 1) cn++;
				if (rc > i + 1) cn++;
				int nd = (b >> i) & 1;
				ll n1, n2;
				if (nd == 0)
				{
					n1 = f1 * c[cn][0];
					n2 = f2 * c[cn][1] + f1 * c[cn][2];
				}
				else
				{
					n1 = f1 * c[cn][1] + f2 * c[cn][0];
					n2 = f2 * c[cn][2];
				}
				f1 = n1, f2 = n2;
			}
			if (f1 != 0)
				ans += f1;
		}
	}
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il ll gi(){
    ll x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch))f^=ch=='-',ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f?x:-x;
}
ll sa[233],sb[233],A,B,p2[51];
il int Log2(ll n){
    int ret=0;while(n>1)n>>=1,++ret;
    return ret;
}
std::unordered_map<ll,ll>calced[51][51];
il ll dfs(int a,int b,ll n){
    if(n<0)return 0;
    if(a<b)std::swap(a,b);
    if(a<=0)return!n;
    if(p2[a+1]+p2[b+1]-a-b-4<n)return 0;
    if(calced[a][b].count(n))return calced[a][b][n];
    return calced[a][b][n]=dfs(a-1,b,n)+dfs(a-1,b,n-p2[a]+1);
}
int main(){
    ll n=gi(),ans=0;
    for(ll L=0;L<50;++L)
        for(ll R=0;R<50;++R)
            if(p2[L+1]+3*p2[R]-4<=n){
                ll p=(n-p2[R]+1)/(p2[L+1]+p2[R+1]-3);
                ans+=dfs(L-1,R-1,n-p2[R]+1-p*(p2[L+1]+p2[R+1]-3));
            }
    printf("%lld\n",ans-1);
    return 0;
}

// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;
#define int long long
const int N = (int) 60;
int p[N], dp[120][2];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    p[0] = 1;
    for (int j = 1; j < N; ++j)
        p[j] = p[j - 1] << 1;
    int s, res = 0;
    cin >> s;
    for (int l = 0; l <= 52; ++l)
        for (int r = 0; r <= 52; ++r) {
            int mod = p[l + 1] + p[r + 1] - 3, mn = p[r] - 1;
            for (int choose = 0; choose <= l + r + 5; ++choose) {
                if (s - mn + choose < mod) continue;
                int len = max(l + 2, r + 2);
                int rem = (s - mn + mod) % mod;
                rem += choose;
                if (rem & 1) continue;
                memset(dp, 0, sizeof dp);
                dp[0][0] = 1;
                for (int j = 1; j <= len; ++j) {
                    for (int chose = choose; chose >= 0; --chose) for (int a = 0; a <= (j >= l? 0: 1); ++a)
                        for (int b = 0; b <= (j >= r? 0: 1); ++b) {
                            for (int c = 1; c >= 0; --c) {
                                int nc = (a + b + c) >> 1;
                                int dig = (a + b + c) & 1;
                                if (dig == (rem >> j & 1)) {
                                    if (a || b) dp[chose + a + b][nc] += dp[chose][c];
                                } else {
                                    if (!a && !b) dp[chose][c] = 0;
                                }

                            }
                        }
                }
                res += dp[choose][0];
            }
        }
    cout << res << endl;
}

//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x;
#define SZ size()
#define p2(x) (1LL<<x)
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........
ll s,g,rt,x,dp[60][200][2],v,re;
//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mn(ll a,ll b)
{
    return(a-b+MD)%MD;
}
ll solve(ll h1,ll h2,ll pc,ll su)
{
    memset(dp,0,sizeof(dp));
    dp[0][pc][0]=1;
    rep(i,1,60)rep(j,0,pc)
    {
        if(p2(i-1)>s)
        {
            return dp[i-1][0][0];
        }
        if(su&(p2(i-1)))
        {
            if(i<h1-1&&i<h2-1)
            {
                dp[i][j][0]+=dp[i-1][j][1];
                dp[i][j][0]+=2*(dp[i-1][j+1][0]);
                dp[i][j][1]+=dp[i-1][j+2][1];
            }
            if(i<h1-1&&i==h2-1)
            {
                dp[i][j][1]+=dp[i-1][j+2][1];
                dp[i][j][0]+=dp[i-1][j+1][0];
            }
            if(i<h1-1&&i==h2)
            {
                dp[i][j][1]+=dp[i-1][j+2][1];
                dp[i][j][0]+=dp[i-1][j+1][0];
            }
            if(i<h1-1&&i>h2)
            {
                dp[i][j][0]+=dp[i-1][j+1][0]+dp[i-1][j][1];
            }
            if(i==h1-1&&i<h2-1)
            {
                dp[i][j][0]+=dp[i-1][j+1][0]+dp[i-1][j][1];
            }
            if(i==h1-1&&i==h2-1)
            {
                dp[i][j][0]+=dp[i-1][j+1][0];
            }
            if(i==h1-1&&i==h2)
            {
                dp[i][j][0]+=dp[i-1][j+1][0];
            }
            if(i==h1-1&&i>h2)
            {
                dp[i][j][0]+=dp[i-1][j][1];
            }
            if(i==h1&&i<h2-1)
            {
                dp[i][j][0]+=dp[i-1][j+1][0];
                dp[i][j][1]+=dp[i-1][j+2][1];
            }
            if(i==h1&&i==h2-1)
            {
                dp[i][j][1]+=dp[i-1][j+2][1];
            }
            if(i==h1&&i==h2)
            {
                dp[i][j][1]+=dp[i-1][j+2][1];
            }
            if(i==h1&&i>h2)
            {
                dp[i][j][0]+=dp[i-1][j+1][0];
            }
            if(i>h1&&i<h2-1)
            {
                dp[i][j][0]+=dp[i-1][j+1][0]+dp[i-1][j][1];
            }
            if(i>h1&&i==h2-1)
            {
                dp[i][j][0]+=dp[i-1][j+1][0];
            }
            if(i>h1&&i==h2)
            {
                dp[i][j][0]+=dp[i-1][j+1][0];
            }
            if(i>h1&&i>h2)
            {
                dp[i][j][0]+=dp[i-1][j][1];
            }
        }
        else
        {
            if(i<h1-1&&i<h2-1)
            {
                dp[i][j][1]+=2*(dp[i-1][j+1][1]);
                dp[i][j][0]+=dp[i-1][j][0];
                dp[i][j][1]+=dp[i-1][j+2][0];
            }
            if(i<h1-1&&i==h2-1)
            {
                dp[i][j][1]+=dp[i-1][j+1][1]+dp[i-1][j+2][0];
            }
            if(i<h1-1&&i==h2)
            {
                dp[i][j][1]+=dp[i-1][j+1][1]+dp[i-1][j+2][0];
            }
            if(i<h1-1&&i>h2)
            {
                dp[i][j][0]+=dp[i-1][j][0];
                dp[i][j][1]+=dp[i-1][j+1][1];
            }
            if(i==h1-1&&i<h2-1)
            {
                dp[i][j][0]+=dp[i-1][j][0];
                dp[i][j][1]+=dp[i-1][j+1][1];
            }
            if(i==h1-1&&i==h2-1)
            {
                dp[i][j][1]+=dp[i-1][j+1][1];
            }
            if(i==h1-1&&i==h2)
            {
                dp[i][j][1]+=dp[i-1][j+1][1];
            }
            if(i==h1-1&&i>h2)
            {
                dp[i][j][0]+=dp[i-1][j][0];
            }
            if(i==h1&&i<h2-1)
            {
                dp[i][j][1]+=dp[i-1][j+1][1]+dp[i-1][j+2][0];
            }
            if(i==h1&&i==h2-1)
            {
                dp[i][j][1]+=dp[i-1][j+2][0];
            }
            if(i==h1&&i==h2)
            {
                dp[i][j][1]+=dp[i-1][j+2][0];
            }
            if(i==h1&&i>h2)
            {
                dp[i][j][1]+=dp[i-1][j+1][1];
            }
            if(i>h1&&i<h2-1)
            {
                dp[i][j][0]+=dp[i-1][j][0];
                dp[i][j][1]+=dp[i-1][j+1][1];
            }
            if(i>h1&&i==h2-1)
            {
                dp[i][j][1]+=dp[i-1][j+1][1];
            }
            if(i>h1&&i==h2)
            {
                dp[i][j][1]+=dp[i-1][j+1][1];
            }
            if(i>h1&&i>h2)
            {
                dp[i][j][0]+=dp[i-1][j][0];
            }
        }
    }
}
//......Code.............
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>s;
    rep(h1,1,60)rep(h2,1,60)
    {
        if(h1==0&&h2==0)
        {
            re++;
            continue;
        }
        g=p2(h1)+p2(h2)-3;
        rt=s/g;
        if(rt==0)continue;
        x=g+s%g+1;
        rep(pc,2,h1+h2)
        {
            if((pc+x)%2)continue;
            v=solve(h1,h2,pc,(pc+x)/2);
            re+=v;
            //cout<<h1<<' '<<h2<<' '<<rt<<' '<<g<<' '<<x<<' '<<pc+x<<' '<<v<<endl;
        }
    }
    cout<<re;
    return 0;
}

#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
#define int long long
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
    char ch;x=0;bool fl=false;
    while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
    for(x=numb;isdigit(ch=getchar());x=x*10+numb);
    (fl==true)&&(x=-x);
}
template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');}
template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Miracle{
const int N=53;
ll mi[N],ans,s,f[N][2*N][2];
ll calc(int h1,int h2,int us,ll p){
    // cout<<" calc "<<h1<<" "<<h2<<" "<<us<<" = "<<p<<endl;
    memset(f,0,sizeof f);
    f[0][0][0]=1;
    int tmp=log2(p);
    for(reg i=0;i<tmp;++i){
        int now=p>>(i+1)&1;
        for(reg j=0;j<=us;++j){
            for(reg k=0;k<=1;++k){
                for(reg a=0;a<=1;++a){
                    for(reg b=0;b<=1;++b){
                        if(a==1&&(i+1)>h1) continue;
                        if(b==1&&(i+1)>h2) continue;
                        if((a+b+k)%2!=now) continue;
                        if(j+a+b>us) continue;
                        f[i+1][j+a+b][(a+b+k)/2]+=f[i][j][k];
                    }
                }
            }
        }
    }
    return f[tmp][us][0];
}
int main(){
    rd(s);
    mi[0]=1;
    for(reg i=1;i<=52;++i) mi[i]=mi[i-1]*2;
    for(reg h1=0;h1<=50;++h1){
        for(reg h2=0;h2<=50;++h2){
            ll tmp=s-mi[h2]+1;
            if(tmp<0) break;
            tmp=tmp/(mi[h1+1]+mi[h2+1]-3);
            ll x=tmp;
            tmp=(mi[h1+1]+mi[h2+1]-3)*x+mi[h2]-1;
            // if(tmp<0) cout<<" oh no "<<endl;
            ll ret=s-tmp;
            if(ret==0) {
                ++ans;continue;
            }

            if(ret<0||x<=0) break;
            // cout<<" h1 "<<h1<<" h2 "<<h2<<" : "<<ret<<" "<<x<<" "<<tmp<<endl;
            for(reg j=0;j<=max((ll)0,h1-1)+max((ll)0,h2-1);++j){
                if((ret+j)&1) continue;
                ll lp=calc(max((ll)0,h1-1),max((ll)0,h2-1),j,ret+j);
                // cout<<" h1 "<<h1<<" h2 "<<h2<<" j "<<j<<" x "<<x<<" = "<<ret+j<<" : "<<lp<<endl;
                ans+=lp;
            }
        }
    }
    ot(ans);
    return 0;
}

}
signed main(){
	Miracle::main();
	return 0;
}

/*
   Author: *Miracle*
*/

#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int M = 300;

llint f[55][M][2];

int main(void) {
  llint s;
  scanf("%lld", &s);
  llint ans = 0;
  REP(la, 50) REP(lb, 50) {
    // s = (2^(la+1) - 1)v + b + (2^(lc+1) - 1)v + c - v
    // s = (2^(la+1) + 2^(lb+1) - 3)v + b + c

    llint k = (1LL<<(la+1)) + (1LL<<(lb+1)) - 3;
    llint v = s / k;
    if (v == 0) continue;

    llint rem = s - v * k;
    int n = max(la, lb);
    REP(i, n+1) REP(d, M) REP(c, 2) f[i][d][c] = 0;

    int off = M/2;
    f[0][off + (rem&1)][0] = 1;
    REP(i, n) REP(d, M) REP(c, 2) {
      llint diff = d - off;

      REP(bit_a, 2) REP(bit_b, 2) {
        if (i >= la && bit_a) continue;
        if (i >= lb && bit_b) continue;
        if (i == la-1 && bit_a) continue;
        if (i == lb-1 && !bit_b) continue;

        llint bit_sum = (bit_a + bit_b + c) % 2;
        llint bit_rem = (bit_a + bit_b + c) / 2;

        llint ndiff = diff + (rem & (1LL<<(i+1))) - ((bit_sum << (i+1)) - bit_a - bit_b);
        if (i == n-1 && bit_rem) {
          ndiff -= (bit_rem << (i+2));
          bit_rem = 0;
        }

        if (-M/2 < ndiff && ndiff < M/2) {
          f[i+1][ndiff+off][bit_rem] += f[i][d][c];
        }
      }
    }

    ans += f[n][off+0][0];
  }

  printf("%lld\n", ans);
  return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (125)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
LL n,ans,f[2][N][2];
LL calc(int x,int lena,int lenb,LL sum){
	memset(f,0,sizeof(f)),f[0][0][0]=1;
	for(int i=0,now=1,pre=0;(1ll<<i)<=sum;i++,now^=1,pre^=1){
		for(int j=0;j<=x;j++)
		f[now][j][0]=f[now][j][1]=0;
		for(int j=0;j<2;j++)
		if(i<lena||!j)
		for(int k=0;k<2;k++)
		if(i<lenb||!k)
		for(int l=0;l<2;l++){
			int S=j+k+l;
			if(((sum>>i)&1)^(S&1))continue;
			for(int m=0;m+j+k<=x;m++)
			f[now][m+j+k][S>>1]+=f[pre][m][l];
		}
	}
	return f[x&1][x][0];
}
int main(){
	read(n);
	for(int i=0;i<=60;i++)
	for(int j=0;j<=60;j++){
		LL mul=(1ll<<i+1)+(1ll<<j+1)-3;
		if(n<mul)break;
		LL ret=n%mul-(1ll<<j)+1;
		if(ret<0)continue;
		for(int k=(ret&1);k<=i+j;k+=2)
			ans+=calc(k,i-1,j-1,(ret+k)>>1);
	}
	cout<<ans;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

LL s;
const int MAXN = 50+5;
LL pw[MAXN];
LL f[MAXN][MAXN*2][2];

inline LL work(LL h1,LL h2,LL n,LL r){
	if(r&1) return 0;
	f[0][0][0] = 1;
	FOR(i,0,MAXN-2){
		FOR(j,0,std::min(2ll*i,n)){
			FOR(k,0,1){
				if(!f[i][j][k]) continue;
				FOR(a,0,(i+1<=h1)){
					FOR(b,0,(i+1<=h2)){
						if(((r>>(i+1))&1) == (a+b+k)%2){
							f[i+1][j+a+b][(k+a+b)/2] += f[i][j][k];
						}
					}
				}
			}
		}
	}
	return f[MAXN-1][n][0]+f[MAXN-1][n][1];
}

int main(){
	scanf("%lld",&s);
	FOR(i,0,MAXN-1) pw[i] = 1ll<<i;
	LL ans = 1;
	FOR(h,1,MAXN-1){
		LL x = s/(pw[h]-1);
		LL r = ans-x*(pw[h]-1);
		ROF(i,h-1,1){
			LL gx = pw[i]-1;
			if(r >= gx) r -= gx;
		}
		ans += (!r);
	}
	// DEBUG(work(1,0,0,0));
	// exit(0);
	FOR(h1,1,MAXN-1){
		FOR(h2,1,MAXN-1){
			LL x = s-pw[h2]+1;
			if(x < 0) break;
			x = x/(pw[h1+1]+pw[h2+1]-3);
			if(x > 0){
				FOR(n,0,h1+h2-2){
					LL r = s-((pw[h1+1]+pw[h2+1]-3)*x+pw[h2]-1)+n;
					ans += work(h1-1,h2-1,n,r);
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#include<bits/stdc++.h>
#define o 1000005
#define re register int
#define ll long long
#define g0(a) memset(a,0,sizeof(a))
#define gc(a,b) memcpy(a,b,sizeof(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define pa pair<int,int>
#define mpp make_pair
#define s1 first
#define s2 second
using namespace std;
inline int read()
{
	register int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar();
	return data*w;
}
const int N=53;
int f[N][N<<1][2];
int main()
{
	int s=read(),ans=0;
	for(int h=1;(1ll<<h)-1<=s;h++)
	{
		int x=s/((1ll<<h)-1),ret=s%((1ll<<h)-1);
		REP(j,h-1,1)if(ret>=(1ll<<j)-1)ret-=(1ll<<j)-1;
		ans+=(!ret);
	}
	for(int h0=1;(1ll<<h0+1)-1<=s;++h0)
	{
		for(int h1=1;(1ll<<h1+1)+(1ll<<h0+1)-3+(1ll<<h1)-1<=s;++h1)
		{
			int A=s-((1ll<<h1)-1),B=(1ll<<h1+1)+(1ll<<h0+1)-3;
			int x=A/B,ret=A%B;
			if(!ret){++ans;continue;}
			if(h0==1&&h1==1){ans+=(s==5*x+1);continue;}
			for(int n=1;n<=h0+h1-2;n++)
			{
				int C=ret+n,L=log2(C);
				if(C&1)continue;
				memset(f[0],0,sizeof(f[0]));f[0][0][0]=1;
				for(int i=1;i<=L;i++)
				{
					memset(f[i],0,sizeof(f[i]));
					for(int j=0;j<=2*i-2&&j<=n;j++)
					FOR(k,0,1)
						if(f[i-1][j][k])
						FOR(x,0,(i<h0))
							FOR(y,0,(i<h1))
								if((k+x+y&1)==(C>>i&1))f[i][j+x+y][k+x+y>>1]+=f[i-1][j][k];
				}
				ans+=f[L][n][0];
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

long long dp[2][120][2];
long long b[60];
int s[3];

long long calc1(int A, int C, long long N) {
	if (N > bitl(A+1)-2) return 0;
	if (cntl(N) == C) return 1;
	return 0;
}

long long calc(int A, int B, int C, long long N) {
	if (N > bitl(A+1)-2 + bitl(B+1)-2) return 0;
	int now = 0, max_cnt = 0;
	dp[0][0][0] = 1;
	dp[0][0][1] = 0;
	for (int i = max(A, B); i >= 1; i--) {
		now ^= 1;
		int cur_cnt = (i <= A) + (i <= B);
		for (int j = 0; j <= min(C, max_cnt + cur_cnt); j++) dp[now][j][0] = dp[now][j][1] = 0;
		s[0] = s[1] = s[2] = 0;
		s[0] = s[cur_cnt] = 1;
		if (cur_cnt == 2) s[1] = 2;
		int cur_bit = N >> i & 1;
		for (int j = 0; j <= max_cnt; j++) {
			if (dp[!now][j][0]) {
				dp[now][j+cur_bit][0] += dp[!now][j][0] * s[cur_bit];
				if (cur_bit) dp[now][j][1] += dp[!now][j][0];
			}
			if (dp[!now][j][1]) {
				dp[now][j+cur_bit+1][1] += dp[!now][j][1] * s[cur_bit+1];
				if (!cur_bit) dp[now][j+cur_bit+2][0] += dp[!now][j][1] * s[2];
			}
		}
		max_cnt = min(max_cnt + cur_cnt, C);
	}
	return dp[now][C][0];
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	long long n; cin >> n;
	for (int i = 0; i <= 50; i++) b[i] = (1LL<<i)-1;
	long long ans = 0;
	for (int i = 0; i < 50; i++) {
		if (b[i+1] > n) break;
		for (int j = 0; j < 50; j++) {
			if (b[i+1]+b[j+1]-1 > n) break;
			long long mod = b[i+1] + b[j+1] - 1;
			long long ret = n - (b[j]-1);
			if (ret < 0) continue;
			ret %= mod;
			if (i == 0 && j == 0) {
				ans++;
				continue;
			}
			if (i == 0) {
				for (int k = 0; k <= j-1; k++) {
					if (ret + k & 1) continue;
					ans += calc1(j-1, k, ret+k);
				}
			} else if (j == 0) {
				for (int k = 0; k <= i-1; k++) {
					if (ret + k & 1) continue;
					ans += calc1(i-1, k, ret+k);
				}
			} else {
				for (int k = 0; k <= i-1+j-1; k++) {
					if (ret + k & 1) continue;
					ans += calc(i-1, j-1, k, ret+k);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

const int N=50+3;

ll s,res;

void dp(int a,int b,int x,int y,ll val){
	static ll f[N][N][N][2];
	if (val&1) return;
	val/=2;
	if (val>(1ll<<max(a,b)+1)-2) return;
	For(i,0,max(a,b)+1) For(j,0,x+1) For(k,0,y+1) For(l,0,2) f[i][j][k][l]=0;
	f[0][0][0][0]=1;
	For(i,0,max(a,b)) For(j,0,x+1) For(k,0,y+1) For(l,0,2)
		if (f[i][j][k][l]){
			For(u,0,2) if (i<a||!u)
				For(v,0,2) if (i<b||!v)
					if ((u+v+l)%2==(val>>i&1)){
						f[i+1][j+u][k+v][(u+v+l)/2]+=f[i][j][k][l];
					}
		}
	res+=f[max(a,b)][x][y][val>>max(a,b)&1];
}
void work(int a,int b){
	ll t,z;
	t=s-((1ll<<a+1)+(1ll<<b+1)-3);
	if (t<0) return;
	z=t/((1ll<<a+1)+(1ll<<b+1)-3)+1;
	t=s-(z-1)*((1ll<<a+1)+(1ll<<b+1)-3);
	for (int i=1;i<=a+1;i++)
		for (int j=1;j<=b+1;j++){
			dp(max(a-1,0),max(b-1,0),i-(!a?1:1),j-(!b?1:2),t+i+j+1-2*((!a?1ll<<a:2ll<<a-1)+(!b?1ll<<b:3ll<<b-1)));
		}
}

int main(){
	cin>>s;
	For(a,0,50) For(b,0,50) work(a,b);
	cout<<res<<endl;
}

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

LL s;

LL tot = 0, ans = 0;

LL d[12][12][5000];

LL solve(int a, int b, LL s) {
    if (s < 0) {
        return 0;
    }
    if (s == 0) {
        return 1;
    }
    if ((2ll << a) - a + (2ll << b) - b - 4 < s) {
        return 0;
    }
    if (a == 0) {
        return 0;
    }
    bool ok = (a < 12 && b < 12 && s < 5000);
    if (ok && d[a][b][s] != -1) {
        return d[a][b][s];
    }
    if (a == b) {
        LL res = solve(a - 1, b - 1, s) + 2ll * solve(a - 1, b - 1, s - (1ll << a) + 1) + solve(a - 1, b - 1, s - (2ll << a) + 2);
        if (ok) d[a][b][s] = res;
        return res;
    }
    LL res = solve(a - 1, b, s - (1ll << a) + 1) + solve(a - 1, b, s);
    if (ok) d[a][b][s] = res;
    return res;
}

LL calc(LL x, int h) {
    LL res = x;
    forn(i, h) {
        x >>= 1;
        res += x;
    }
    return res;
}

int main() {
    memset(d, -1, sizeof d);
    //freopen("input.txt", "r", stdin);
    cin >> s;
    for (int i = 1; i <= 55; ++i) {
        for (int j = 1; j <= 55; ++j) {
            LL x = 2 * ((1ll << i) + (1ll << j) - 2) + 1;
            LL mn = (1ll << j) - 1;
            LL mx = mn + (1ll << (i - 1)) + (1ll << (j - 1)) - 2;
            mn = s - mn;
            mx = s - mx;
            swap(mn, mx);
            mn = max(mn, x);
            if (mx < x) {
                continue;
            }
            mx /= x;
            mn = (mn + x - 1) / x;
            tot += max(0ll, mx - mn + 1);
            for (LL a = mn; a <= mx; ++a) {
                LL b = s - a * x - (1ll << j) + 1;
                ans += solve(max(i - 1, j - 1), min(i - 1, j - 1), b);
                //cerr << ans << endl;
            }
        }
    }
    cerr << ans << endl;
    //cerr << tot << endl;
    forn(h, 55) {
        LL lo = (1ll << h), hi = s, mid;
        while (lo < hi) {
            mid = (lo + hi) >> 1;
            LL x = calc(mid, h);
            if (x >= s) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        if (calc(lo, h) == s) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;

int f[55][110][2];

int work(LL s, int l1, int l2, int tot) {
	if (l1 == -1) l1 = 0;
	memset(f, 0, sizeof(f));
	f[0][0][0] = 1;
	rep(i,1,max(l1,l2)) rep(j,0,tot) rep(k,0,1) if (f[i - 1][j][k]) {
		int cnt = (i <= l1) + (i <= l2);
		rep(t,0,2) if (t <= cnt && ((t + k) & 1) == (s >> i & 1)) {
			int w = 1; if (t == 1 && cnt == 2) w = 2;
			f[i][j + t][(k + t) >> 1] += w * f[i - 1][j][k];
		}
	}
	return f[max(l1, l2)][tot][s >> max(l1 + 1, l2 + 1) & 1];
}

int main() {
	LL s, ans = 0; cin >>s;
	rep(lc,1,50) {
		rep(rc,2,50) {
			LL t = (1LL << lc) + (1LL << rc) - 3;
			LL s0 = s / t; if (!s0) continue;
			rep(tot,0,lc + rc - 2) {
				LL sum = s % t + tot; int k = max(lc - 1, rc - 1);
				if (sum & 1) continue;
				LL s2 = sum - (1LL << (rc - 1));
				if (0 <= s2 && s2 < 1LL << (k + 1)) { if (tot) ans += work(s2, lc - 2, rc - 2, tot - 1); }
				if (lc == 1) {
					LL s1 = sum;
					if (s1 < 0 || s1 > 1LL << (k + 1)) continue;
					ans += work(s1, lc - 2, rc - 2, tot);
				}
			}
		}
	}
	cout <<ans + 1<<endl;
	return 0;
}

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

ll s;

bool read() {
  if (scanf("%lld", &s) < 1) {
    return false;
  }
  return true;
}

const int maxn = 110;

ll dp[2][maxn], ndp[2][maxn];

void solve() {
  ll res = 0;
  for (int left = 0; left < maxn / 2; left++) {
    for (int right = 0; right < maxn / 2; right++) {
      ll a = 1;
      a += (1ll << (left + 1)) - 2;
      a += (1ll << (right + 1)) - 2;
      if (s < a) {
        continue;
      }
      ll rem = s % a;
      if (right) {
        rem -= (1ll << right) - 1;
        if (rem < 0) {
          continue;
        }
      }
      //eprintf("left = %d, right = %d, rem = %lld\n", left, right, rem);
      memset(dp, 0, sizeof(dp));
      dp[0][rem & 1] = 1;
      for (int i = 1; i < maxn / 2; i++) {
        memset(ndp, 0, sizeof(ndp));
        for (int r = 0; r < 2; r++) {
          for (int j = 0; j < maxn; j++) {
            if (!dp[r][j]) {
              continue;
            }
            ll real = (rem & ((1ll << i) - 1)) + j;
            real = (real & ((1ll << i) - 1));
            if (r) {
              real += (1ll << (i + 1));
            }
            int mx1 = 0, mx2 = 0;
            if (i <= left - 1) {
              mx1++;
            }
            if (i <= right - 1) {
              mx2++;
            }
            for (int x = 0; x <= mx1; x++) {
              for (int y = 0; y <= mx2; y++) {
                ll cur = real + ((1ll << i) - 1) * (x + y);
                ll val = (cur - rem) & ((1ll << (i + 1)) - 1);
                if (val > maxn) {
                  continue;
                }
                ndp[!!(cur & (1ll << (i + 1)))][val] += dp[r][j];
              }
            }
          }
        }
        swap(dp, ndp);
      }
      res += dp[0][0];
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cassert>

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

const int INF = 2000000000;
const ll LLINF = 9000000000000000000;

#define W(x) cerr << #x << ": " << x << endl;

constexpr ll B = 50;

int dp[2][B+1][B+1][B+1];
ll solve(ll sum, ll dbits, ll dmax, ll ebits, ll emax) {
	// write sum=a+b with:
	//	- popc(a) == dbits
	//	- popc(b) == ebits
	//	- a < 2^dmax
	//	- b < 2^emax

//	W(sum);
//	W(dbits);
//	W(dmax);
//	W(ebits);
//	W(emax);
	int lastbit = 1;
	while ((1LL << lastbit) <= sum) ++lastbit;
//	W(lastbit);

	// dp[carry][bit in sum][dbits used][ebits used]
	for (int c = 0; c < 2; ++c)
	for (int b = 0; b <= lastbit; ++b)
	for (int i = 0; i <= dbits; ++i)
	for (int j = 0; j <= ebits; ++j)
		dp[c][b][i][j] = 0;

	if (sum&1) {
//		dp[0][0][1][0] = 1;
//		dp[0][0][0][1] = 1;
	} else {
		dp[0][0][0][0] = 1;
//		dp[1][0][1][1] = 1;
	}
	sum >>= 1;
	for (int b = 1; b < lastbit; ++b) {
		if (sum&1) for (int du = 0; du <= dbits; ++du)
			for (int eu = 0; eu <= ebits; ++eu) {
				// turn on nothing
				dp[0][b][du][eu] += dp[1][b-1][du][eu];
				// turn on d
				if (b < dmax && du > 0) dp[0][b][du][eu] += dp[0][b-1][du-1][eu];
				// turn on e
				if (b < emax && eu > 0) dp[0][b][du][eu] += dp[0][b-1][du][eu-1];
				// turn on d,e
				if (b < dmax && b < emax && du > 0 && eu > 0)
					dp[1][b][du][eu] += dp[1][b-1][du-1][eu-1];
			}
		else for (int du = 0; du < dbits; ++du)
			for (int eu = 0; eu < ebits; ++eu) {
				// turn on nothing
				dp[0][b][du][eu] += dp[0][b-1][du][eu];
				// turn on d
				if (b < dmax && du > 0) dp[0][b][du][eu] += dp[1][b-1][du-1][eu];
				// turn on e
				if (b < emax && eu > 0) dp[0][b][du][eu] += dp[1][b-1][du][eu-1];
				// turn on d,e
				if (b < dmax && b < emax && du > 0 && eu > 0)
					dp[1][b][du][eu] += dp[0][b-1][du-1][eu-1];
			}
		sum /= 2;
	}
	ll r = dp[0][lastbit-1][dbits][ebits];
//	if (r > 0) {
//		cerr << "Returning "<< r << endl;
//	}
	return r;
}

int main() {
	ll s;
	cin >> s;

	ll ans = 1LL; // Single node (S)

	// One child:
	//  path starting at x with a length of d > 1 vertices
	// Iterate over d (2^B > 10^15):
	for (int d = 2; d <= B; ++d) {
		ll x = s / ((1LL << d) - 1LL);
		if (x < 1) continue;
		ll rem = s - x * ((1LL << d) - 1LL);
		if (rem >= (1LL << d) - d) continue;
		for (int b = rem % 2; b < d; b += 2)
			if (__builtin_popcountll((rem + b)&((1LL<<d)-1LL)) == b) {
				++ans;
//				cerr << "s " << d << ' '<< x << ' ' << b << endl;
			}
	}

	// Two children:
	// paths starting at x with a length of d, e > 1 vertices
	//  (including x), with d the left path and e the right path
	// Iterate over d,e
	for (int d = 2; d <= B; ++d) {
		for (int e = 2; e <= B; ++e) {
			ll x = s / ((1LL << d) + (1LL << e) - 3LL);
			if (x < 1) continue;
			ll rem = s - x * ((1LL << d) + (1LL << e) - 3LL);
			if (rem > ((1LL << (d - 1)) + (1LL << e) - d - e - 1LL))
				continue;
			rem -= (1LL << (e - 1)) - 1LL;
			if (rem < 0) continue;
//			cerr <<  "trying " << d << ' ' << e << ", need to make " << rem << endl;
			for (int bd = 0; bd < d - 1; ++bd)
				for (int be = 0; be < e - 1; ++be) {
					ll add = solve(rem+bd+be, bd, d-1, be, e-1);
					if (add > 0) {
						ans += add;
//						cerr << "Adding " << add << " for " << d << ' ' << e << endl;
					}
				}
		}
	}

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define D isdigit(c=getchar())
inline int getint(){
    int c,l=0,x;
    for (;!D;l=c)if(c==EOF)return 1<<31;
    for (x=c-'0';D;x=x*10+c-'0')if(c==EOF) break;
    return l=='-'?-x:x;
}
int buf[100];
inline int putint(int x){
    int i=0;
    x=x<0?putchar('-'),-x:x;
    for (;buf[i++]=x%10,x;x/=10);
    for (i=i-1?i-1:1;i--;putchar(buf[i]+'0'));
    return 1;
}
//LaJiIOYouHua

//Define&Const
typedef long long ll;
ll f[60][120][2];
ll n,L,R;
//Struct&Class
long long now;

//Var
long long dfs(int ws,int res,bool jw){
	if(res<0)return 0;
	if(~f[ws][res][jw])return f[ws][res][jw];
	long long&t=f[ws][res][jw];t=0;
	if((1ll<<ws)>now){
		if(res==0&&jw==0)t=1;
		return t;
	}
	if((1<<ws)&now){
		if(jw){
			t=dfs(ws+1,res,0);
			if(ws<L&&ws<R)t+=dfs(ws+1,res-2,1);
		}else{
			if(ws<L)t+=dfs(ws+1,res-1,0);
			if(ws<R)t+=dfs(ws+1,res-1,0);
		}
	}else{
		if(jw){
			if(ws<L)t+=dfs(ws+1,res-1,1);
			if(ws<R)t+=dfs(ws+1,res-1,1);
		}else{
			t=dfs(ws+1,res,0);
			if(ws<L&&ws<R)t+=dfs(ws+1,res-2,1);
		}
	}
	return t;
}
ll ans;
int main(){
	cin>>n;
	for(ll a=0;(1ll<<a)<=n;a++){
		for(ll b=0;(1ll<<b)<n;b++){
			ll lca=(n-(1ll<<b)+1)/((1ll<<a+1)+(1ll<<b+1)-3);
			if(lca==0)continue;
			ll nn=n-lca*((1ll<<a+1)+(1ll<<b+1)-3)+1-(1ll<<b);
			for(int i=0;i<=a+b;i++){
				memset(f,-1,sizeof(f));
				L=a-1;R=b-1;
				now=nn+i;
				if(now&1)continue;now/=2;
				ans+=dfs(0,i,0);
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}
//MainFunction

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxOnes 111

ll s, act_sum, a, b, total, ones;
ll solution;

ll dp[maxOnes][2];
ll old[maxOnes][2];

ll solve(ll total, ll ones, ll a, ll b) {
    ll i, j;

    memset(dp, 0, sizeof(dp));
    memset(old, 0, sizeof(old));

    dp[0][0] = 1;
    for (int bit = 0; (1 << bit) <= total; bit++) {
        memcpy(old, dp, sizeof(dp));
        memset(dp, 0, sizeof(dp));

        for (int d1 = 0; d1 <= 1; d1++) {
            if (d1 == 1 && bit >= a) continue;

            for (int d2 = 0; d2 <= 1; d2++) {
                if (d2 == 1 && bit >= b) continue;

                for (int bonus = 0; bonus <= 1; bonus++) {
                    if ( (bonus + d1 + d2) % 2 != ((total >> bit) & 1) ) continue;

                    for (int bef = 0; bef <= 2 * bit; bef++) {
                        if (bef + d1 + d2 > ones) continue;
                        dp[bef + d1 + d2][(bonus + d1 + d2) % 2] += old[bef][bonus];
                    }
                }
            }
        }
    }

    return dp[ones][0];
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%lld", &s);

    for (a = 0; a <= 50; a++) {
        for (b = 0; b <= 50; b++) {
            ll base = (1LL << (a + 1)) + (1LL << (b + 1)) - 3;
            ll lca = s / base;

            if (lca <= 0) continue;
            act_sum = s - lca * base - ((1LL << b) - 1);

            // way 1 -> x = 2 * x - pop_count(x)
            // 2 * le - pop_count(le) + 2 * ri - pop_count(ri) = act_sum
            for (ones = 0; ones <= a + b; ones++) {
                total = act_sum + ones;
                if (total < 0 || total % 2 == 1) continue;
                total >>= 1;

                solution += solve(total, ones, max(0LL, a - 1), max(0LL, b - 1));
            }
        }
    }

    printf("%lld", solution);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll dp[60][120][2];
ll solve(ll sum, int lena, int lenb, int bit) {
	memset(dp, 0, sizeof(dp));
	int i;
	dp[0][0][0] = 1;
	for(i = 1; 1LL << i <= sum; ++i) {
		int d = sum >> i & 1;
		for(int j = 0; j <= bit; ++j)
			for(int x = 0; x < 2; ++x) if(!x || i < lena)
				for(int y = 0; y < 2; ++y) if(!y || i < lenb) {
					if((x + y) & 1 == d) dp[i][j + x + y][x + y >> 1] += dp[i - 1][j][0];
					else dp[i][j + x + y][x + y + 1 >> 1] += dp[i - 1][j][1];
				}
	}
	return dp[i - 1][bit][0];
}
int main() {
	cin >> n;
	ll ans = 0;
	for(int i = 0; i <= 58; ++i) {
		for(int j = 0; j <= 58; ++j) {
			ll x = (n - (1LL << j) + 1) / ((1LL << i + 1) + (1LL << j + 1) - 3);
			if(!x) continue;
			ll res = n - (1LL << j) + 1 - x * ((1LL << i + 1) + (1LL << j + 1) - 3);
			if(!res) {
				++ans;
				continue;
			}
			for(int k = 1; k <= i + j - (!i) - (!j); ++k)
				if(!(res + k) & 1)
					ans += solve(res + k, i, j, k);
		}
	}
	cout << ans;
	return 0;
}

/*AMETHYSTS*/
//#pragma comment(linker, "/STACK:1000000000")
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>
//#include <unordered_map>
//#include <random>
//#include <unordered_set>

#define ll long long
#define ld double
#define pii pair <int, int>
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define mp make_pair
#define ui unsigned ll
#define pll pair <ll, ll>

using namespace std;

const int maxn = 110;

ll sum[maxn];

int dp[maxn][maxn][2];
int lena, lenb;

int go(ll s, int pos, int x, int o) {
	if (x < 0) {
		return 0;
	}

	if (dp[pos][x][o] != -1) {
		return dp[pos][x][o];
	}

	if (pos >= lena && pos >= lenb) {
		if (x == 0 && s == o) {
			dp[pos][x][o] = 1;
		} else {
			dp[pos][x][o] = 0;
		}

		return dp[pos][x][o];
	}

	dp[pos][x][o] = 0;

	for (int i = 0; i < 2; i++) {
		int j = (s & 1) ^ i ^ o;

		if (i == 1 && pos >= lena) {
			continue;
		}

		if (j == 1 && pos >= lenb) {
			continue;
		}

		dp[pos][x][o] += go(s >> 1, pos + 1, x - i - j, (o + i + j) >> 1);
	}

	return dp[pos][x][o];
}

int main() {
	sum[0] = 0;
	for (int i = 1; i < 52; i++) {
		sum[i] = (sum[i - 1] + (1ll << (i - 1)));
	}

	ll s;

	cin >> s;

	ll ans = 0;

	for (int l = 0; l <= 50; l++) {
		for (int r = 0; r <= 50; r++) {
			lena = l;
			lenb = r;

			if (s < sum[r]) {
				break;
			}

			ll now = s - sum[r];

			ll mod = 2 * sum[l] + 2 * sum[r] + 1;

			if (now < mod) {
				break;
			}

			now %= mod;

			for (int x = 0; x <= l + r - (l != 0) - (r != 0); x++) {
				if ((now + x) & 1) {
					continue;
				}

				memset(dp, -1, sizeof dp);
				ans += go((now + x) >> 1, 1, x, 0);
				//cout << l << ' ' << r << ' ' << now + x << ' ' << x << ' ' << go(now + x, 1, x, 0) << endl;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

#include<iostream>
#include<vector>
#include<map>
using namespace std;

long long path(long long pos) {
	long long result = 0;
	while(pos > 0) {
		result += pos;
		pos /= 2;
	}
	return result;
}

long long count(int lev, long long pos) {
	map<pair<int, long long>, long long > solved;

	long long size = path((1LL<<lev)-1) + 1, hsz = (size - lev) / 2;

	if(pos < 0 || pos > 2*size-2)
		return 0;
	if(lev == 0)
		return 1;
	if(solved.count({lev, pos}))
		return solved[{lev, pos}];

	long long result = count(lev-1, pos) + 2*count(lev-1, pos - (size-hsz) ) + count(lev-1, pos - 2*(size-hsz) );
	solved[{lev, pos}] = result;
	return result;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	long long s, result = 0;
	cin >> s;

	for(int lsz = 0; (1LL<<(lsz+1)) - 1 <= s; lsz++)
		for(int rsz = 0; (1LL<<(rsz+1)) - 1 <= s; rsz++) {
			long long vm = (1LL<<(lsz+1)) + (1LL<<(rsz+1)) - 3;
			long long cs = s - (1LL<<rsz) + 1;

			if(cs >= vm) {
				cs %= vm;

				int l = max(lsz-1, 0), r = max(rsz-1, 0);
				if(r < l)
					swap(l, r);

				{
					int subm = 0;
					for(int tpow = 50; tpow >= 0; tpow--) {
						long long cstart = path((1LL<<l)*(subm+tpow));
						if(cstart <= cs)
							subm += tpow;
					}

					if(subm < (1LL<<r) / (1LL<<l))
						result += count(l, cs - path((1LL<<l)*subm));
					if(subm+1 < (1LL<<r) / (1LL<<l))
						result += count(l, cs - path((1LL<<l)*(subm+1)) );
				}
			}
		}

	cout << result << '\n';

	return 0;
}

#include <cstdio>
#include <iterator>

#define MAX_LENGTH 50

long long pc(long long v)
{
  long long sum = 0;
  while(v > 0)
  {
    sum += (v & 1);
    v >>= 1;
  }
  return sum;
}

long long bs(long long lower, long long upper, long long goal)
{
  while(lower < upper)
  {
    long long mid = (lower + upper) / 2;
    long long delta = 2 * mid - pc(mid) - goal;
    if(delta < 0)
    {
      lower = mid + 1;
    }
    else if(delta == 0)
    {
      lower = mid;
      break;
    }
    else
    {
      upper = mid;
    }
  }

  return (lower < upper && 2 * lower - pc(lower) == goal) ? lower : -1;
}

int main(void)
{
  long long s;
  scanf("%lld", &s);

  long long total = 0;
  for(long long i = 0; i <= MAX_LENGTH; i ++)
  {
    for(long long j = 0; j <= MAX_LENGTH; j ++)
    {
      long long n, d, l;

      n = s + 1 - (1LL << j);
      d = (1LL << (i + 1)) + (1LL << (j + 1)) - 3;
      l = n / d;

      if(l <= 0)
      {
        continue;
      }

      puts("====");

      fprintf(stderr, "Suppose the left arm has length %lld and the right arm has length %lld; then the LCA is %lld\n", i, j, l);

      long long ts = s - ((l - 1) * ((1LL << (i + 1)) + (1LL << (j + 1)) - 2) - (l - 1));
      fprintf(stderr, "This is equivalent to seeking a path with sum %lld rooted at 1\n", ts);

      long long lv, rv = -1;

      const long long lfloor = (1LL << i);
      const long long lceil = (1LL << i) + ((i == 0) ? 1 : (1LL << (i - 1)));
      const long long rfloor = (1LL << j) + ((j == 0) ? 0 : (1LL << (j - 1)));
      const long long rceil = (1LL << (j + 1));

      fprintf(stderr, "Seeking a feasible solution; left val ranges over [%lld, %lld), right over [%lld, %lld)\n",
        lfloor, lceil, rfloor, rceil);

      for(lv = lfloor; lv < lceil; lv ++)
      {
        rv = bs(rfloor, rceil, 1 + ts - (2 * lv  - pc(lv)));
        if(rv != -1)
        {
          break;
        }
      }

      if(rv == -1)
      {
        fprintf(stderr, "No feasible solution :(\n");
      }
      else
      {
        fprintf(stderr, "Feasible solution: %lld -> %lld\n", lv, rv);

        long long delta = 1;
        for(long long level = 0; level < std::min(i, j) - 1; level ++)
        {
          if((lv & (1 << level)) != (rv & (1 << level)))
          {
            delta <<= 1;
            fprintf(stderr, "Solution permits inversion at level %lld (total delta %lld)\n", level, delta);
          }
        }

        total += delta;
      }
    }
  }

  printf("%lld\n", total);

  return 0;
}

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define maxn 64
ll n;
ll dp[maxn][2*maxn][2];
int m,p;
ll ans,mi[maxn];
ll calc(ll s,ll q,int a,int b,int t)
{
	memset(dp[p],0,sizeof(dp[p]));
	dp[p][0][0]=1;
	for(int i=2;i<=log2(s)+1;i++)
	{
		int d=(s>>i)&1;
		p^=1;
		memset(dp[p],0,sizeof(dp[p]));
		for(int j=0;j<=2*i-2;j++)
		{
			for(int k=0;k<=1;k++)
			{
				if(dp[p^1][j][k])
				{
					for(int x=0;x<=1;x++)
					{
						if(!x||i<a)
						{
							for(int y=0;y<=1;y++)
							{
								if(!y||i<b)
								{
									if((k+x+y)%2==d)
									{
										dp[p][j+x+y][(k+x+y)/2]+=dp[p^1][j][k];
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return dp[p][t][0];
}
int main()
{
	scanf("%lld",&n);
	mi[0]=1;
	ll x,ret;
	while(mi[m]<=n)
	{
		mi[m+1]=mi[m]<<1;
		m++;
	}
	mi[m+1]=mi[m]<<1;
	for(int i=1;i<=m;i++)
	{
		if((x=n/(mi[i]-1))>0)
		{
			ret=n-x*(mi[i]-1);
			for(int j=i-1;j;j--)
			{
				if(ret>=mi[j]-1)
				{
					ret-=mi[j]-1;
				}
			}
			if(!ret)
			{
				ans++;
			}
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;mi[j]-1<=n;j++)
		{
			if((x=(n-mi[j]+1)/(mi[i+1]+mi[j+1]-3))>0)
			{
				ret=(n-mi[j]+1)-x*(mi[i+1]+mi[j+1]-3);
				if(!ret)
				{
					ans++;
					continue;
				}
				if(i==1&&j==1)
				{
					ans+=(ret==5*x+1);
					continue;
				}
				for(int k=1;k<=i+j;k++)
				{
					if(~(ret+k)&1)
					{
						ans+=calc(ret+k,x,i,j,k);
					}
				}
			}
		}
	}
	printf("%I64d\n",ans);
	return 0;
}

// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;
#define int long long
const int N = (int) 55;
int p[N], dp[2], odp[2];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    p[0] = 1;
    for (int j = 1; j < N; ++j)
        p[j] = p[j - 1] << 1;
    int s, res = 0;
    cin >> s;
    for (int l = 0; l < N; ++l)
        for (int r = 0; r < N; ++r) {
            int mod = 1, mn = (r != 0? p[r - 1]: 0);
            if (l) mod += (p[l] - 1) * 2;
            if (r) mod += (p[r] - 1) * 2;
            if (s - mn < mod) continue;
            int rem = (s - mn + mod) % mod;
            int val = p[r] - 1 + (l >= 2? p[l - 1] - 1: 0);
            memset(dp, 0, sizeof dp);
            dp[0] = 1;
            for (int j = 0; j <= 50; ++j) {
                odp[0] = dp[0];
                odp[1] = dp[1];
                dp[0] = dp[1] = 0;
                for (int a = 0; a <= (j >= l - 1? 0: 1); ++a)
                    for (int b = 0; b <= (j >= r - 1? 0: 1); ++b) {
                        for (int c = 0; c <= 1; ++c) {
                            int nc = (a + b + c) >> 1;
                            int dig = (a + b + c) & 1;
                            if (dig == (rem >> j & 1))
                                dp[nc] += odp[c];
                        }
                    }
            }
            res += dp[0];
        }
    cout << res << endl;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <ctime>
#include <iomanip>
using namespace std;
#define fi firstu77777
#define se second
#define mp make_pair
#define pb push_back
#define FORU(i, a, b) for (int i = a, nn = int(b); i <= nn; ++i)
#define FORD(i, a, b) for (int i = a, nn = int(b); i >= nn; --i)
#define REP(i, b) for (int i = 0, nn = int(b); i < nn; ++i)
#define sz(x) (int)(x).size()
#define mmst(a, x) memset(a, x, sizeof(a))
#define DEBUG(x) cout << #x << " : " << (x) << endl;
#define LOOK(x, a, b) {cout << #x << " : ";FORU(i, a, b) cout << x[i] << ' '; cout << endl; }
#define Tgetw(a, w) ((a << w) & 1)
typedef long long ll;
typedef double ff;
typedef unsigned long long ull;
typedef long double lff;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int N = 150;
ll s, ans;
inline ll dp(int ot, int la, int lb, ll sm) {
    static ll f[N][2], las[N][2];
    REP(a, ot + 1) REP(re, 2) f[a][re] = 0;
    f[0][0] = 1;
    for (int i = 0; (1LL << i) <= sm; ++i) {
        REP(a, ot + 1) REP(re, 2) {
            las[a][re] = f[a][re];
            f[a][re] = 0;
        }
        REP(ca, 2) if (i < la || ca == 0)
            REP(cb, 2) if (i < lb || cb == 0) {
                REP(re, 2) {
                    int dg = ca + cb + re;
                    if ((dg & 1) != Tgetw(sm, i))
                        continue;
                    for (int al = 0; al + ca + cb <= ot; ++al)
                        f[al + ca + cb][dg / 2] += las[al][re];
                }
        }
    }
    return f[ot][0];
}
int main() {
    cin >> s, ans = 0;
    REP(a, 59) REP(b, 59) {
        ll mul = (1LL << a + 1) + (1LL << b + 1) -3;
        ll lca = s / mul ; if (!lca) continue;
        ll res = s - lca * mul - ( (1LL << b) - 1);
        REP(ones, a + b + 1) {
            ll aandb = res + ones;
            if (aandb < 0 || aandb % 2) continue;
            aandb /= 2;
            ans += dp(ones, max(a-1, 0), max(b-1, 0), aandb);
        }
    }
    cout << ans << endl;
    return 0;
}

#include <cstdio>
#include <iterator>

#define MAX_LENGTH 50

long long pc(long long v)
{
  long long sum = 0;
  while(v > 0)
  {
    sum += (v & 1);
    v >>= 1;
  }
  return sum;
}

long long bs(long long lower, long long upper, long long goal)
{
  while(lower < upper)
  {
    long long mid = (lower + upper) / 2;
    long long delta = 2 * mid - pc(mid) - goal;
    if(delta < 0)
    {
      lower = mid + 1;
    }
    else if(delta == 0)
    {
      lower = mid;
      break;
    }
    else
    {
      upper = mid;
    }
  }

  return (lower < upper && 2 * lower - pc(lower) == goal) ? lower : -1;
}

int main(void)
{
  long long s;
  scanf("%lld", &s);

  long long total = 0;
  for(long long i = 0; i <= MAX_LENGTH; i ++)
  {
    for(long long j = 0; j <= MAX_LENGTH; j ++)
    {
      long long n, d, l;

      n = s + 1 - (1LL << j);
      d = (1LL << (i + 1)) + (1LL << (j + 1)) - 3;
      l = n / d;

      if(l <= 0)
      {
        continue;
      }

      fputs("====", stderr);

      fprintf(stderr, "Suppose the left arm has length %lld and the right arm has length %lld; then the LCA is %lld\n", i, j, l);

      long long ts = s - ((l - 1) * ((1LL << (i + 1)) + (1LL << (j + 1)) - 2) - (l - 1));
      fprintf(stderr, "This is equivalent to seeking a path with sum %lld rooted at 1\n", ts);

      long long lv, rv = -1;

      const long long lfloor = (1LL << i);
      const long long lceil = (1LL << i) + ((i == 0) ? 1 : (1LL << (i - 1)));
      const long long rfloor = (1LL << j) + ((j == 0) ? 0 : (1LL << (j - 1)));
      const long long rceil = (1LL << (j + 1));

      fprintf(stderr, "Seeking a feasible solution; left val ranges over [%lld, %lld), right over [%lld, %lld)\n",
        lfloor, lceil, rfloor, rceil);

      for(lv = lfloor; lv < lceil; lv ++)
      {
        rv = bs(rfloor, rceil, 1 + ts - (2 * lv  - pc(lv)));
        if(rv != -1)
        {
          break;
        }
      }

      if(rv == -1)
      {
        fprintf(stderr, "No feasible solution :(\n");
      }
      else
      {
        fprintf(stderr, "Feasible solution: %lld -> %lld\n", lv, rv);

        long long delta = 1;
        for(long long level = 0; level < std::min(i, j) - 1; level ++)
        {
          if((lv & (1 << level)) != (rv & (1 << level)))
          {
            delta <<= 1;
            fprintf(stderr, "Solution permits inversion at level %lld (total delta %lld)\n", level, delta);
          }
        }

        total += delta;
      }
    }
  }

  printf("%lld\n", total);

  return 0;
}

#pragma comment(linker, "/STACK:256000000")

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <memory.h>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <random>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int64, int64> pll;
const int INF = (int)(1e9 + 1337);
const int64 LINF = (int64)(4e18);
const double EPS = 1e-11;
#define sq(x) ((x)*(x))
#define FAIL() ((*(int*)(0))++)
const int HMOD = 1000000009;
const int HBASE = 1003;

const int MAXN = 51;

//inline int add(int a, int b)
//{
//	a += b;
//	if (a >= HMOD)
//	{
//		a -= HMOD;
//	}
//	return a;
//}
//
//inline int sub(int a, int b)
//{
//	a -= b;
//	if (a  < 0)
//	{
//		a += HMOD;
//	}
//	return a;
//}
//
//inline int mul(int a, int b)
//{
//	return int64(a) * b % HMOD;
//}

int64 s;
int add[MAXN];
int64 dp[MAXN][MAXN << 1][2];
int64 ans;

int64 get_min_path(int64 x, int len)
{
    return x * ((1LL << len) - 1);
}

int64 get_max_path(int64 x, int len)
{
    return x * ((1 << len) - 1) + add[len - 1];
}

int64 get_max_lca(int lena, int lenb)
{
    int64 l = 1LL, r = s, lca2 = 0;
    while (l <= r)
    {
        int64 mid = (l + r) >> 1;
        int64 sum = mid;
        if (lena)
        {
            sum += get_min_path(mid << 1, lena);
        }
        if (lenb)
        {
            sum += get_min_path((mid << 1) + 1, lenb);
        }
        //printf("mid %I64d lena %d lenb %d sum %I64d\n", mid, lena, lenb, sum);
        if (sum <= s)
        {
            lca2 = mid;
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }
    return lca2;
}

int64 get_min_lca(int lena, int lenb)
{
    int64 l = 1LL, r = s, lca1 = LINF;
    while (l <= r)
    {
        int64 mid = (l + r) >> 1;
        int64 sum = mid;
        if (lena)
        {
            sum += get_max_path(mid << 1, lena - 1);
        }
        if (lenb)
        {
            sum += get_max_path((mid << 1) + 1, lenb - 1);
        }
        if (sum <= s)
        {
            lca1 = mid;
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }
    return lca1;
}

int64 calc_dp(int lena, int lenb, int pop, int64 som)
{
    memset(dp, 0, sizeof(dp));
    int slen = 1;
    while ((1LL << (slen + 1)) <= som)
    {
        slen++;
    }
    slen++;
#ifdef _MY_DEBUG
    for (int i = 0; i < slen; i++)
    {
        printf("%d", (som & (1LL << i)) ? 1 : 0);
    }
    printf(" --- %d %d %d %I64d\n", lena, lenb, pop, som);
#endif
    dp[0][0][0] = 1;
    for (int l = 1; l <= slen; l++)
    {
        int la = (l == lena + 1 ? 1 : 0);
        int ra = (l == lena || l > lena + 1 ? 0 : 1);
        int lb = ((l == lenb || l == lenb + 1) ? 1 : 0);
        int rb = (l > lenb + 1 ? 0 : 1);
        for (int a = la; a <= ra; a++)
        {
            for (int b = lb; b <= rb; b++)
            {
                for (int m = 0; m <= 1; m++)
                {
                    int cnt = a + b + m;
                    if (((som >> (l - 1)) & 1LL) != int64(cnt & 1))
                    {
                        continue;
                    }
                    for (int p = a + b; p <= min((l << 1), pop); p++)
                    {
                        dp[l][p][(cnt >> 1) & 1] += dp[l - 1][p - a - b][m];
                    }
                }
            }
        }
    }
#ifdef _MY_DEBUG
    for (int l = 1; l <= slen; l++)
    {
        for (int p = 0; p <= pop; p++)
        {
            for (int m = 0; m < 2; m++)
            {
                printf("%d %d %d %I64d\n", l, p, m, dp[l][p][m]);
            }
        }
    }
#endif
    return dp[slen][pop][0];
}

int last(int64 q)
{
    int num = 0;
    while (1LL << (num + 1) <= q)
    {
        num++;
    }
    return num;
}

int64 get_path(int64 q)
{
    int64 sum = 0LL;
    while (q)
    {
        sum += q;
        q >>= 1;
    }
    return sum;
}

int64 trivia(int64 s)
{
    int64 res = 0LL;
    for (int64 a = 1; a <= s; a++)
    {
        int la = last(a);
        for (int64 b = 1; b <= s; b++)
        {
            int lb = last(b);
            int cnt = 0;
            int64 lca = 0LL;
            while (la >= 0 && lb >= 0 && (a & (1LL << la)) == (b & (1LL << lb)))
            {
                cnt++;
                lca <<= 1;
                if ((a & (1LL << la)))
                {
                    lca++;
                }
                la--;
                lb--;
            }
            int64 path = get_path(a) + get_path(b) - 2LL * get_path(lca) + lca;
            if (path == s)
            {
                res++;
            }
        }
    }
    return res;
}

void solve()
{
    scanf("%lld", &s);
    for (int lena = 0; lena <= 50; lena++)
    {
        for (int lenb = 0; lenb <= 50; lenb++)
        {
            //int64 lca1 = get_min_lca(lena, lenb);
            int64 lca2 = get_max_lca(lena, lenb);
            if (lca2 == 0)
            {
                break;
            }
            //assert(lca1 == lca2);
            //printf("%d %d %I64d\n", lena, lenb, lca2);
            int64 sum = s - (lca2 - 1) * ((1 << (lena + 1)) + (1 << (lenb + 1)) - 3);
            //printf("%I64d\n", sum);
            sum++;
            for (int pop = 2; pop <= lena + lenb + 2; pop++)
            {
                int64 som = sum + pop;
                if (som <= 0 || som & 1LL)
                {
                    continue;
                }
                som >>= 1;
                int64 res = calc_dp(lena, lenb, pop, som);
                if (res)
                {
                    ans += res;
                    //printf("lca %I64d %d %d %d %I64d\n", lca2, lena, lenb, pop, res);
                }
            }
        }
    }
    printf("%I64d\n", ans);
    //printf("%I64d\n", trivia(s));
}

void precalc()
{
    for (int i = 1; i < MAXN; i++)
    {
        add[i] = add[i - 1] + ((1 << i) - 1);
    }
}

int main()
{
#ifdef _MY_DEBUG
    freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#else

#endif
    srand(333);

    double st = clock();

    precalc();
    int t = 1; //scanf("%d", &t);
    for (int i = 0; i < t; i++)
    {
        solve();
    }

    //fprintf(stderr, "%.3lf\n", (clock() - st) / CLOCKS_PER_SEC);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
typedef double db;
ll bit[65],f[65][120][2];//��{2,2^2,2^3...2^h1}��{2,2^2,...2^h2}֮��ѡtot���������==s��
inline ll dp(ll s,int tot,int h1,int h2){//Ӧ����{2-1,2^2-1,2^3-1...2^h1-1}��{2-1,2^2-1,...2^h2-1},�����Ѿ��Ѽ�һ�ƹ�ȥs��
	memset(f,0,sizeof f);f[0][0][0]=1;//��{2��2^2...}��ѡ��2^min(h1,h2)��֮ǰ��������ѡ������f[i][j][k]��ʾ������i������֮ǰ������i��ѡ��j����������һλ�Ľ�λΪk
	int ed=log2(s);//��ѡ��������
	rep(i,1,ed){
		ll d=(s>>i)&1;
		int ed=i*2-2;//�� i֮ǰ�����ѡ���ٸ�
		rep(j,1,ed) rep(k,0,1)/*��һλ�Ƿ��λ*/rep(p1,0,1)/*�����Ƿ������߼��Ƿ�ѡһ��2^i*/rep(p2,0,1)/*����ͬ��*/if((i<h1||p1==0)&&(i<h2||p2==0)&& (p1+p2+k)%2==d)/*��Ϊx�����Ҷ��Ӽ�2^h1��2^h2�ǿ϶�Ҫѡ��*/
		f[i][j+p1+p2][(k+p1+p2)/2]+=f[i-1][j][k];
	}
	return f[ed][tot][0];
}
int main(){
	ll x,s,res,ans=0;
	int ed=0;
	scanf("%lld",&s);
	bit[0]=1;while(bit[ed]<=s) bit[++ed]=bit[ed-1]<<1;--ed;//bit[ed]<=s
	rep(i,1,ed){//ͳ��һ���������
		if(bit[i]-1>s) break;
		x=s%(bit[i]-1);
		for(int j=i;j>=1;--j) if(x>=bit[j]-1) x-=bit[j]-1;
		if(!x) ++ans;
	}
	rep(h1,1,ed-1){//ͳ���зֲ�����
		for(int h2=1;bit[h2]-1<=s&&h2<ed;++h2){//ö�����ߵ����� h1  h2
			x=(s-bit[h2]+1)/(bit[h1+1]+bit[h2+1]-3);
			if(x>0){
				res=(s-bit[h2]+1)%(bit[h1+1]+bit[h2+1]-3);
				if(res==0){//����������
					++ans;continue;
				}
				if(h1==1&&h2==1){//xֻѡ�������x*2���Ҷ���x*2+1 ,������x*5+1
					ans+=(s==x*5+1);continue;
				}//������˵����ĳЩ��Ҫ������
				rep(i,1,h1+h2) if((res+i)%2==0) ans+=dp(res+i,i,h1,h2);//�൱�ڰѼ����� i��һŲ����ʽ��һ�߱�ɼ� i��һ
			}
		}
	}
	printf("%lld",ans);
}

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
void dec(ll &x, ll y) {
	if (x >= y)
		x -= y;
}
ll p(int x) {
	return 1ll << x;
}

ll f[51][101][2];
ll calc(ll s, int a, int b, int n) {
	if (n == 0) {
		return s == 0 ? 1 : 0;
	}
	for (int i = max(a, b); i <= 50; ++i)
		if ((s >> i) & 1)
			return 0;
	memset(f, 0, sizeof f);
	for (int i = 0; i < a || i < b; ++i) {
		int d = (s >> i) & 1;
		if (i == 0) {
			if (d == 0) {
				f[0][0][0] = 1;
				f[0][2][1] = 1;
			}
			else {
				f[0][1][0] = 2;
			}
			continue;
		}
		for (int j = 0; j <= 2 * i; ++j) {
			for (int aa = 0; aa <= 1; ++aa) {
				if (aa == 1 && i >= a)
					continue;
				for (int bb = 0; bb <= 1; ++bb) {
					if (bb == 1 && i >= b)
						continue;
					for (int k = 0; k <= 1; ++k) {
						if ((k + aa + bb) % 2 == d)
							f[i][j + aa + bb][(k + aa + bb) / 2] += f[i - 1][j][k];
					}
				}
			}
		}
	}
	return f[max(a, b) - 1][n][0];
}

int main() {
	ll s;
	cin >> s;
	//single
	ll num = 0;
	for (int i = 1; i <= 50; ++i) {
		ll x = s / (p(i) - 1);
		if (x > 0) {
			ll last = s % (p(i) - 1);
			for (int j = i - 1; j >= 1; --j)
				dec(last, p(j) - 1);
			if (last == 0)
				++num;
		}
	}
	//cout << num << endl;
	//double
	for (int h1 = 1; h1 <= 50; ++h1) {
		for (int h2 = 1; p(h2) - 1 <= s; ++h2) {
			ll x = (s - p(h2) + 1) / (p(h1 + 1) + p(h2 + 1) - 3);
			if (x > 0) {
				ll last = (s - p(h2) + 1) % (p(h1 + 1) + p(h2 + 1) - 3);
				if (last == 0)
					++num;
				else {
					for (int n = 0; n <= h1 + h2; ++n) {
						num += calc(last + n, h1, h2, n);
					}
				}
			}
		}
	}

	cout << num << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll S, R;
int len1, len2;

ll cc[52][52][52][2];
ll dp(int bit, int rem1, int rem2, int c) {
    if(bit > 50) return rem1 == 0 && rem2 == 0 && c == 0;
    ll &ret = cc[bit][rem1][rem2][c];
    if(ret != -1) return ret;

    if(bit >= len1 && rem1) return ret = 0;
    if(bit >= len2 && rem2) return ret = 0;

    ret = 0;
    for(int i = 0; i <= (rem1? 1 : 0); i++) {
        for(int j = 0; j <= (rem2? 1 : 0); j++) {
            if((i + j + c) % 2 == ((R & (1LL << bit))? 1 : 0)) {
                ret += dp(bit + 1, rem1 - i, rem2 - j, (i + j + c >= 2));
            }
        }
    }
    return ret;
}

int main() {
    cin >> S;

    ll ans = 0;
    for(int i = 0; i <= 50; i++) {
        for(int j = 0; j <= 50; j++) {
            ll Q;
            if(i == 0 && j == 0) Q = 1;
            else if(i == 0) Q = (1LL << (j + 1)) - 1;
            else if(j == 0) Q = (1LL << (i + 1)) - 1;
            else Q = (1LL << (i + 1)) + (1LL << (j + 1)) - 3;
            if(Q > S) break;
            R = S % Q;
            if(R < (1LL << j) - 1) break;
            R -= (1LL << j) - 1;

            for(int a = 0; a < (i? i : 1); a++) {
                for(int b = 0; b < (j? j : 1); b++) {
                    R += a + b;

                    //cout << a << ' ' << b << ' ' << R << endl;

                    if(R % 2) continue;
                    len1 = i;
                    len2 = j;
                    memset(cc, -1, sizeof(cc));
                    ans += dp(1, a, b, 0);
                }
            }

            //cout << "(i, j) : " << i << ' ' << j << ' ' << ans << endl;
        }
    }
    cout << ans;
}

#include <iostream>
#include <algorithm>
using namespace std;

long long dp[57][57][57][2];
int len;

long long licz3(int la, int pa, int lb, int pb, long long s) {
	len = max(la, lb);
	while((1LL << len) < s) len++;

	for(int a = 0; a <= pa; ++a) for(int b = 0; b <= pb; ++b) dp[0][a][b][0] = dp[0][a][b][1] = 0;
	dp[0][0][0][0] = 1;

	for(int i = 1; i <= len + 1; ++i) {
		bool aok;
		bool bok;
		for(int a = 0; a <= pa; ++a) {
			aok = (i - 1 < la) && a;
			for(int b = 0; b <= pb; ++b) {
				dp[i][a][b][0] = dp[i][a][b][1] = 0;
				bok = (i - 1 < lb) && b;
				if((1LL << (i - 1)) & s) {
					dp[i][a][b][0] = dp[i - 1][a][b][1];
					if(aok) dp[i][a][b][0] += dp[i - 1][a - 1][b][0];
					if(bok) dp[i][a][b][0] += dp[i - 1][a][b - 1][0];

					if(aok && bok) dp[i][a][b][1] = dp[i - 1][a - 1][b - 1][1];
				}
				else {
					dp[i][a][b][0] = dp[i - 1][a][b][0];

					if(aok) dp[i][a][b][1] = dp[i - 1][a - 1][b][1];
					if(bok) dp[i][a][b][1] += dp[i - 1][a][b - 1][1];
					if(aok && bok) dp[i][a][b][1] += dp[i - 1][a - 1][b - 1][0];
				}
			}
		}
	}

	return dp[len + 1][pa][pb][0];
}

long long licz(int la, int lb, long long s) {
	long long res = 0;

	for(int ps = 0; ps <= la + lb; ++ps) {
		if((s + ps) % 2 == 0) {
			if((1LL << la) + (1LL << lb) - 2 >= (s + ps) / 2) {
				licz3(la, min(ps, la), lb, min(ps, lb), (s + ps) / 2);
				for(int pa = 0; pa <= min(la, ps); ++pa) {
					int pb = ps - pa;
					if(pb <= lb) res += dp[len + 1][pa][pb][0];
				}
			}
		}
	}
	return res;
}

int licz2(int la, long long s) {
	int res = 0;
	for(int pop = 0; pop <= la; ++pop) {
		long long a = s + pop;
		if(a % 2 == 0) {
			if(__builtin_popcount(a / 2) == pop) res++;
		}
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);
	long long s;
	cin >> s;
	long long res = 0;

	for(int la = 1; la <= 50; ++la) {
		long long P = (1LL << la) - 1;
		long long sn = s - P;
		if(sn < 0) break;
		res += licz2(la - 1, sn % P);
	}
	for(int la = 2; la <= 50; ++la) {
		for(int lb = 2; lb <= 50; ++lb) {
			long long P = (1LL << la) + (1LL << lb) - 3;
			long long sn = s - P - (1LL << (lb - 1)) + 1;
			if(sn < 0) continue;
			res += licz(la - 2, lb - 2, sn % P);
		}
	}
	cout << res << endl;
	return 0;
}

// #define DEBUG
//#define USEPB_DS
#define USETR1
#define CPPELEVEN
#define GPP

/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
//#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <list>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <tuple>

using namespace std;

#ifndef CPPELEVEN
#ifdef USETR1
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;
#endif
#else
#include <unordered_map>
#include <unordered_set>
#endif

#ifdef USEPB_DS
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// binomial_heap_tag, rc_binomial_heap_tag, thin_heap_tag, binary_heap_tag
typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq_type;
// splay_tree_tag, ov_tree_tag
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> tree_type;
#endif

#define mpr make_pair
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <double, double> pdd;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}

#ifndef CPPELEVEN
template <class T> inline T max1(T a, T b) { return b < a ? a : b; }
template <class T> inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }
template <class T> inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }
template <class T> inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }
template <class T> inline T min1(T a, T b) { return a < b ? a : b; }
template <class T> inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }
template <class T> inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }
template <class T> inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }
#else
template <typename t, typename t1>
t min1(t a, t1 b) { return a < b ? a : b; }
template <typename t, typename... arg>
t min1(t a, arg... arr) { return min1(a, min1(arr...)); }
template <typename t, typename t1>
t max1(t a, t1 b) { return a > b ? a : b; }
template <typename t, typename... arg>
t max1(t a, arg... arr) { return max1(a, max1(arr...)); }
#endif

inline int jud(double a, double b){
	if(abs(a) < eps && abs(b) < eps) return 0;
	else if(abs1(a - b) / max(abs1(a), abs1(b)) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <typename t> inline int jud(t a, t b){
	if(a < b) return -1;
	if(a == b) return 0;
	return 1;
}

// f_lb == 1代表返回相同的一串的左边界，f_small == 1代表返回如果没有寻找的值返回小的数
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1){
	if(na == 0) return 0;
	int be = 0, en = na - 1;
	if(*a <= *(a + na - 1)){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(*(a + be), val) == 1) be--;
		if(!f_small && jud(*(a + be), val) == -1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(*(a + be), val) == -1) be--;
		if(f_small && jud(*(a + be), val) == 1) be++;
	}
	return be;
}

template <class T> inline T lowb(T num) {return num & (-num); }
#ifdef GPP
inline int bitnum(ui nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(ull nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitnum(ll nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitmaxl(ui a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(int a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(ull a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
inline int bitmaxl(ll a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
#else
#endif

long long pow(long long n, long long m, long long mod = 0){
	if(m < 0) return 0;
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

#define  MOD 1000000007
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
	if(mod == -1) mod = MOD;
	a += b;
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
}
template <class t>
void output1(t arr) {
	for(int i = 0; i < (int)arr.size(); i++)
		cerr << arr[i] << ' ';
	cerr << endl;
}
template <class t>
void output2(t arr) {
	for(int i = 0; i < (int)arr.size(); i++)
		output1(arr[i]);
}

//....................密..........封..........线..........下..........禁..........止..........hack...............................................

ll dp[55][55][55];
ll arr[55];

vector <ll> getl(ll l) {
	ll st[55];
	ll sum = 0;
	l--;
	for(int i = 0; i <= 55; i++) {
		st[i] = sum + 1;
		if(l & (1ll << i))
			sum += 1ll << i;
	}
	l++;
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;
	for(ll i = 1; 1ll << i <= l; i++) {
		memset(arr, -1, sizeof(arr));
		arr[i] = (1ll << i) - st[i];
		ll delta = 0;
		for(int j = i; j > 0; j--) {
			if(arr[i] >= 1ll << (j - 1)) {
				int rd = delta;
				int maxv = j - 1;
				for(int k = j; k <= i; k++) if(arr[k] != -1) {
					if(arr[k] >= 1ll << (j - 1)) {
						rd++;
						arr[k] -= 1ll << (j - 1);
					} else {
						maxv = k;
						arr[k] = -1;
					}
				}
				for(int pi = j; pi <= i; pi++) {
					for(int rk = 0; rk <= j; rk++)
						dp[i][pi][rk + rd] += dp[maxv][j - 1][rk];
				}
			} else {
				int maxv = j - 1;
				int rd = delta;
				for(int k = j; k <= i; k++) if(arr[k] != -1) {
					if(arr[j] >= 1ll << (j - 1)) {
						delta++;
						arr[j] = -1;
						maxv = k;
					}
				}
				for(int pi = j; pi <= i; pi++) {
					for(int rk = 0; rk <= j; rk++)
						dp[i][pi][rk + rd] += dp[maxv][j - 1][rk];
				}
			}
			arr[j - 1] = (1ll << (j - 1)) - st[j - 1];
		}
		for(int j = 0; j <= i; j++)
			dp[i][j][delta]++;
	}
	vll ans = vll(55, 0);
	for(int i = 0; 1ll << i <= l; i++) if(l & (1ll << i)){
		for(int j = 0; j < 55; j++)
			ans[j] += dp[i][i][j];
	}
	return ans;
}

ll n;

ll gsum(ll num) {
	ll ans = 0;
	while(num) {
		ans += num / 2;
		num /= 2;
	}
	return ans;
}

ll gsum(ll num1, ll num2) {
	ll ans = 0;
	while(num1 != num2) {
		if(num1 > num2) {
			ans += num1;
			num1 /= 2;
		} else {
			ans += num2;
			num2 /= 2;
		}
	}
	return ans + num1;
}

inline ll minx(ll h, int tuo) {
	assert(tuo >= 0);
	return (h << tuo);
}
inline ll maxx(ll h, int tuo) {
	assert(tuo >= 0);
	return (h << tuo) + (tuo > 0) * ((1 << (tuo - 1)) - 1);
}
inline ll miny(ll h, int tuo) {
	assert(tuo >= 0);
	return (h << tuo) + (tuo > 0) * ((1 << (tuo - 1)));
}
inline ll maxy(ll h, int tuo) {
	assert(tuo >= 0);
	return (h << tuo) + (1 << tuo) - 1;
}

int main() {

//............................不要再忘了检查maxn大小了！！！！BSBandme你个SB！！！！...................................................

	ios_base::sync_with_stdio(0);
	#ifdef DEBUG //......................................................................................................
	freopen("input.txt", "r", stdin);
	int __size__ = 256 << 20; // 256MB
	char *__p__ = (char*)malloc(__size__) + __size__;
	__asm__("movl %0, %%esp\n" :: "r"(__p__));
	#endif //...........................................................................................................

	ll ans = 0;
	cin >> n;
	for(int i = 0; 1ll << i <= n; i++) {
		for(int j = 1; 1ll << j <= n; j++) {
			for(int h = 0; h <= min(i, j); h++) {
				ll be = 1ll << h, en = (1ll << (h + 1)) - 1;
				while(be !=en) {
					ll mid = (be + en) / 2;
					if(gsum(maxx(mid, i - h), maxy(mid, j - h)) >= n) {
						en = mid;
					} else be = mid + 1;
				}
				if(gsum(minx(be, i - h), miny(be, j - h)) > n || gsum(maxx(be, i - h), maxy(be, j - h)) < n)
					continue;

				ll stx, sty;
				if(gsum(minx(be, i - h), maxy(be, j - h)) > n) {
					ll bey = miny(be, j - h), eny = maxy(be, j - h);
					while(bey != eny) {
						ll mid = (bey + eny + 1) / 2;
						if(gsum(minx(be, i - h), mid) <= n) bey = mid;
						else eny = mid - 1;
					}
					stx = minx(be, i - h), sty = bey;
				} else {
					ll bex = minx(be, i - h), enx = maxx(be, i - h);
					while(bex != enx) {
						ll mid = (bex + enx + 1) / 2;
						if(gsum(maxy(be, j - h), mid) <= n) bex = mid;
						else enx = mid - 1;
					}
					stx = bex, sty = maxy(be, j - h);
				}

				ll pstx = stx, psty = sty;
				for(int rd = 0; rd <= 30; rd++) {
					if(stx > maxx(be, i - h)) break;
					ll rk = gsum(stx, sty) - n;
					if(sty == maxy(be, j - h))
						rk = -rk;
					if(rk > 50) break;
					if(rk >= 0) {
						ll rl = maxx(be, i - h) - stx + 1;
						if(stx == minx(be, i - h))
							rl = sty - miny(be, j - h) + 1;
						auto tans = getl(rl);
						ll rl1 = min(maxx(be, i - h) - stx + 1, sty - miny(be, j - h) + 1);
						if(rl > rl1)
							tans[rk] = dp[bitmaxl(rl) - 1][bitmaxl(rl1) - 1][rk];
						ans += tans[rk];
					}
					if(sty == maxy(be, j - h)) stx++;
					else sty++;
				}
				stx = pstx, sty = psty;
				for(int rd = 1; rd <= 30; rd++) {
					if(stx == minx(be, i - h)) sty--;
					else stx--;
					if(sty < miny(be, j - h)) break;
					ll rk = gsum(stx, sty) - n;
					if(sty == maxy(be, j - h))
						rk = -rk;
					if(rk > 50) break;
					if(rk >= 0) {
						ll rl = maxx(be, i - h) - stx + 1;
						if(stx == minx(be, i - h))
							rl = sty - miny(be, j - h) + 1;
						auto tans = getl(rl);
						ll rl1 = min(maxx(be, i - h) - stx + 1, sty - miny(be, j - h) + 1);
						if(rl > rl1)
							tans[rk] = dp[bitmaxl(rl) - 1][bitmaxl(rl1) - 1][rk];
						ans += tans[rk];
					}
				}
 			}
		}
	}
	cout << ans << endl;

    return 0;
}

#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;

int f[55][110][2];

int work(LL s, int l1, int l2, int tot) {
	if (l1 == -1) l1 = 0;
	memset(f, 0, sizeof(f));
	f[0][0][0] = 1;
	rep(i,1,max(l1,l2)) rep(j,0,tot) rep(k,0,1) if (f[i - 1][j][k]) {
		int cnt = (i <= l1) + (i <= l2);
		rep(t,0,2) if (t <= cnt && ((t + k) & 1) == (s >> i & 1)) {
			int w = 1; if (t == 1 && cnt == 2) w = 2;
			f[i][j + t][(k + t) >> 1] += w * f[i - 1][j][k];
		}
	}
	return f[max(l1, l2)][tot][s >> max(l1 + 1, l2 + 1) & 1];
}

int main() {
	freopen("g.in","r",stdin);
	LL s, ans = 0; cin >>s;
	rep(lc,1,50) {
		rep(rc,2,50) {
			LL t = (1LL << lc) + (1LL << rc) - 3;
			LL s0 = s / t; if (!s0) continue;
			rep(tot,0,lc + rc - 2) {
				LL sum = s % t + tot; int k = max(lc - 1, rc - 1);
				if (sum & 1) continue;
				LL s2 = sum - (1LL << (rc - 1));
				if (0 <= s2 && s2 < 1LL << (k + 1)) { if (tot) ans += work(s2, lc - 2, rc - 2, tot - 1); }
				if (lc == 1) {
					LL s1 = sum;
					if (s1 < 0 || s1 > 1LL << (k + 1)) continue;
					ans += work(s1, lc - 2, rc - 2, tot);
				}
			}
		}
	}
	cout <<ans + 1<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int maxL=60;

ll S,pw[maxL],dp[maxL][maxL][2];

int main(){
    pw[0]=1;for (int i=1;i<maxL;i++) pw[i]=pw[i-1]<<1;
    scanf("%lld",&S);int dep=log2(S+1);ll Ans=0;
    for (int i=1;i<=dep;i++){
	ll X=S%(pw[i]-1);
	for (int j=maxL-1;j>=0;j--) if (X>=pw[j]-1) X-=pw[j]-1;
	if (X==0) ++Ans;
    }
    for (int hl=1;hl<=dep;hl++)
	for (int hr=1;hr<=dep;hr++){
	    ll X=(S-pw[hr]+1)/(pw[hl+1]+pw[hr+1]-3);
	    ll R=(S-pw[hr]+1)%(pw[hl+1]+pw[hr+1]-3);
	    if (X==0) continue;
	    if (R==0){
		++Ans;continue;
	    }
	    if (hl==1&&hr==1){
		if (S==X*5+1) ++Ans;
		continue;
	    }

	    for (int c=1;c<=hl+hr;c++){
		ll NUM=R+c;if (NUM&1) continue;memset(dp,0,sizeof(dp));dp[0][0][0]=1;
		for (int i=1;i<=dep;i++)
		    for (int j=0;j<=i+i-2&&j<=c;j++)
			for (int k=0;k<=1;k++)
			    if (dp[i-1][j][k])
				for (int a=0;a<=(i<hl);a++)
				    for (int b=0;b<=(i<hr);b++)
					if (((a+b+k)&1)==((NUM>>i)&1))
					    dp[i][j+a+b][(a+b+k)>>1]+=dp[i-1][j][k];
		Ans+=dp[dep][c][0];
	    }
	}
    printf("%lld\n",Ans);return 0;
}

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<unordered_set>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
typedef unsigned uint;
typedef unsigned long long uLL;
const double pi=acos(-1);
template<class T>
void Read(T &x){
	char c;
	bool f(0);
	while(c=getchar(),c!=EOF){
		if(c=='-')
			f=1;
		else if(c>='0'&&c<='9'){
			x=c-'0';
			while(c=getchar(),c>='0'&&c<='9')
				x=x*10+c-'0';
			ungetc(c,stdin);
			if(f)
				x=-x;
			return;
		}
	}
}
//
LL s,f[2][140][2],ans;
LL dp(int ones,int len1,int len2,LL tot){
	memset(f,0,sizeof f);
	int i,now=0,a,b,d,j;
	f[0][0][0]=1;
	for(i=0;(1ll<<i)<=tot;i++){
		now^=1;
		memset(f[now],0,sizeof f[now]);
		for(a=0;a<2;a++)
			if(!a||i<len1)
				for(b=0;b<2;b++)
					if(!b||i<len2)
						for(d=0;d<2;d++)
							if(((a+b+d)&1)==((tot>>i)&1))
								for(j=0;j+a+b<=ones;j++)
									f[now][j+a+b][(a+b+d)>>1]+=f[now^1][j][d];
	}
	return f[now][ones][0];
}
int main()
{
	Read(s);
	int a,b,i;
	LL lca,cnt,rm,tot;
	for(a=1;a<=58;a++)
		for(b=1;b<=58;b++){
			cnt=(1ll<<(a+1))-1+(1ll<<(b+1))-1-1;
			lca=s/cnt;
			if(!lca)
				continue;
			rm=s%cnt-(1ll<<b)+1;
			for(i=0;i<=a+b;i++){
				tot=rm+i;
				if(tot<0||(tot&1))
					continue;
				ans+=dp(i,a-1,b-1,tot>>1);
			}
		}
	printf("%I64d\n",ans);
}

#include<bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il ll gi(){
    ll x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch))f^=ch=='-',ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f?x:-x;
}
ll sa[233],sb[233],A,B,p2[51];
il int Log2(ll n){
    int ret=0;while(n>1)n>>=1,++ret;
    return ret;
}
std::unordered_map<ll,ll>calced[51][51];
il ll dfs(int a,int b,ll n){
    if(n<0)return 0;
    if(a<b)std::swap(a,b);
    if(a<=0)return!n;
    if(p2[a+1]+p2[b+1]-a-b-4<n)return 0;
    if(calced[a][b].count(n))return calced[a][b][n];
    return calced[a][b][n]=dfs(a-1,b,n)+dfs(a-1,b,n-p2[a]+1);
}
int main(){
    ll n=gi(),ans=0;
    for(ll L=0;L<50;++L)
        for(ll R=0;R<50;++R)
            if(p2[L+1]+3*p2[R]-4<=n){
                ll p=(n-p2[R]+1)/(p2[L+1]+p2[R+1]-3);
                ans+=dfs(L-1,R-1,n-p2[R]+1-p*(p2[L+1]+p2[R+1]-3));
            }
    printf("%lld\n",ans-1);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 400 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;
#define SUM(a, b) (( (a) % MOD + (b) % MOD ) % MOD )
#define MUL(a, b) (((i64)((a) % MOD) * ((b) % MOD)) % MOD)
const double EPS = 1e-7;

int main(){

    /* if(!freopen("data.in", "r", stdin)){
         return 0;
     }*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    i64 s;
    cin >> s;
    i64 ans = 0;
    for(int t1 = 0; t1 <= 60; t1++)
        for(int t2 = 0; t2 <= 60; t2++){
            i64 fac = (1LL << (t1 + 1)) + (1LL << (t2 + 1)) - 3;
            i64 a = s / fac;
            if(a == 0)continue;

            i64 r = s - a * fac;

            if(t1 == 0 && t2 == 0){
                ans += 1;
                continue;
            }
            if(t2 == 0){
                if(r <= ((1LL << (t1 - 1)) - 1))ans += 1;
                continue;
            }

            if(r < ((1LL << (t2 - 1))))continue;

            r -= ((1LL << (t2 - 1)));

            t2--;

            if(t1 == 0){
                if(r <= ((1LL << t2) - 1))ans += 1;
                t2++;
                continue;
            }

            t1--;

            i64 mn = max(0LL, r - ((1LL << t2) - 1));
            i64 mx = min(((1LL << t1) - 1), r);
            //cout << a <<" " << mn << " " << mx << " " << t1 << " " << t2 << endl;
            ans += mx - mn + 1;

            t1++; t2++;
        }
    cout << ans << endl;

}

#include<stdio.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pii;
typedef pair<pii,ll>pi3;
vector<int>vec;
map<pi3,ll>ma;
ll dfs(int pt,int req,ll now)
{
	if(now<0||req<0)return 0;
	if(((now>>pt)<<pt)!=now)return 0;
	if(pt==vec.size())
	{
		if(req==0&&now==0)return 1;
		else return 0;
	}
	pi3 zz=make_pair(make_pair(pt,req),now);
	if(ma.count(zz))return ma[zz];
	ll s=0,t=0;
	for(int i=pt;i<vec.size();i++)s+=(ll)vec[i]*((1LL<<i)-1),t+=vec[i];
	if(s<now||t<req)return ma[zz]=0;
	if(vec[pt]==1)return ma[zz]=dfs(pt+1,req,now-(1LL<<pt)*req)+dfs(pt+1,req-1,now-(1LL<<pt)*(req-1));
	else return ma[zz]=dfs(pt+1,req,now-(1LL<<pt)*req)+dfs(pt+1,req-1,now-(1LL<<pt)*(req-1))*2+dfs(pt+1,req-2,now-(1LL<<pt)*(req-2));
}
int main()
{
	ll num;
	scanf("%lld",&num);
	ll ans=0;
	for(int i=0;i<=45;i++)
	{
		for(int j=0;j<=45;j++)
		{
			ll s=1;
			for(int k=1;k<=i;k++)s+=1LL<<k;
			for(int k=1;k<=j;k++)s+=1LL<<k;
			if(s+(1LL<<j)-1>num)continue;
			vec.clear();
			ma.clear();
			vec.push_back(0);
			for(int k=0;k<=min(i-2,j-2);k++)vec.push_back(2);
			for(int k=max(1,min(i,j))+1;k<=max(i,j);k++)vec.push_back(1);
			ll t=0;
			for(int k=0;k<=i+j;k++)t+=dfs(1,k,num%s-k-((1LL<<j)-1));
			ans+=t;
		}
	}
	printf("%I64d\n",ans);
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
typedef double db;
ll bit[65],f[65][120][2];//��{2,2^2,2^3...2^h1}��{2,2^2,...2^h2}֮��ѡtot���������==s��
inline ll dp(ll s,int tot,int h1,int h2){//Ӧ����{2-1,2^2-1,2^3-1...2^h1-1}��{2-1,2^2-1,...2^h2-1},�����Ѿ��Ѽ�һ�ƹ�ȥs��
	memset(f,0,sizeof f);f[0][0][0]=1;//��{2��2^2...}��ѡ��2^min(h1,h2)��֮ǰ��������ѡ������f[i][j][k]��ʾ������i������֮ǰ������i��ѡ��j����������һλ�Ľ�λΪk
	int ed=log2(s);//��ѡ��������
	rep(i,1,ed){
		ll d=(s>>i)&1;
		int ed=i*2-2;//�� i֮ǰ�����ѡ���ٸ�
		rep(j,1,ed) rep(k,0,1)/*��һλ�Ƿ��λ*/rep(p1,0,1)/*�����Ƿ������߼��Ƿ�ѡһ��2^i*/rep(p2,0,1)/*����ͬ��*/if((i<h1||p1==0)&&(i<h2||p2==0)&& (p1+p2+k)%2==d)/*��Ϊx�����Ҷ��Ӽ�2^h1��2^h2�ǿ϶�Ҫѡ��*/
		f[i][j+p1+p2][(k+p1+p2)/2]+=f[i-1][j][k];
	}
	return f[ed][tot][0];
}
int main(){
	ll x,s,res,ans=0;
	int ed=0;
	scanf("%lld",&s);
	bit[0]=1;while(bit[ed]<=s) bit[++ed]=bit[ed-1]<<1;
	rep(i,1,ed){//ͳ��һ���������
		if(bit[i]-1>s) break;
		x=s%(bit[i]-1);
		for(int j=i;j>=1;--j) if(x>=bit[j]-1) x-=bit[j]-1;
		if(!x) ++ans;
	}
	rep(h1,1,ed-1){//ͳ���зֲ�����
		for(int h2=1;bit[h2]-1<=s&&h2<ed;++h2){//ö�����ߵ����� h1  h2
			x=(s-bit[h2]+1)/(bit[h1+1]+bit[h2+1]-3);
			if(x>0){
				res=(s-bit[h2]+1)%(bit[h1+1]+bit[h2+1]-3);
				if(res==0){//����������
					++ans;continue;
				}
				if(h1==1&&h2==1){//xֻѡ�������x*2���Ҷ���x*2+1 ,������x*5+1
					ans+=(s==x*5+1);continue;
				}//������˵����ĳЩ��Ҫ������
				rep(i,1,h1+h2) if((res+i)%2==0) ans+=dp(res+i,i,h1,h2);//�൱�ڰѼ����� i��һŲ����ʽ��һ�߱�ɼ� i��һ
			}
		}
	}
	printf("%lld",ans);
}

//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    ll dp[60][60][2];
	void main()
	{
        ll S=qread(),ans=0;
        fo(L1,0,50) fo(L2,0,50)
        {
            ll tt=bin(L1+1)+bin(L2+1)-3,ul=ceil(1.0*(S-bin(L1)-bin(L2+1)+L1+L2+3)/tt),ur=(S-bin(L2)+1)/tt;if(!ul) continue;
            fo(LCA,ul,ur) fo(cnt,0,L1+L2)
            {
                ll wt=S-LCA*tt-bin(L2)+1+cnt;if(wt<0 or wt&1) continue;
                memset(dp,0,sizeof dp);dp[1][0][0]=1;int ln=log2(max(1ll,wt));
                fo(i,1,ln) fo(c,0,min(i+i,L1+L2))
                {
                    if(i>=max(L1,L2)) {dp[i+1][c][0]+=dp[i][c][(wt&bin(i))>0];continue;}//0
                    if(wt&bin(i))
                    {
                        dp[i+1][c+1][0]+=dp[i][c][0]*(1+(i<min(L1,L2)));//1
                        dp[i+1][c][0]+=dp[i][c][1],dp[i+1][c+2][1]+=dp[i][c][1]*(i<min(L1,L2));//0/2
                    }
                    else
                    {
                        dp[i+1][c+1][1]+=dp[i][c][1]*(1+(i<min(L1,L2)));//1
                        dp[i+1][c][0]+=dp[i][c][0],dp[i+1][c+2][1]+=dp[i][c][0]*(i<min(L1,L2));//0/2
                    }
                }
                ans+=dp[ln+1][cnt][0];
            }
        }write(ans);
	}
};//(ans+MOD)%MOD
signed main()
{
    // freopen("a.in","r",stdin);
    srand(time(0));
    mine::main();
}

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cassert>

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

const int INF = 2000000000;
const ll LLINF = 9000000000000000000;

#define W(x) cerr << #x << ": " << x << endl;

constexpr ll B = 50;

// carry, bit n., bits
int dp[2][B+1][B+B+1];

ll solve(ll sum, ll bits, ll dmax, ll emax) {
	ll lastbit = 1;
	while ((1LL<<lastbit) <= sum) ++lastbit;

	for (int carry = 0; carry < 2; ++carry)
		for (int b = 0; b <= bits; ++b)
			dp[carry][0][b] = 0;
	dp[0][0][0] = 1;

	for (int b = 1; b < lastbit; ++b) {
		sum >>= 1;
		if (sum&1)
			for (int bt = 0; bt <= bits; ++bt) {
				// turn nothing on
				dp[0][b][bt] = dp[1][b-1][bt];
				// turn d on
				if (bt > 0 && b <= dmax) dp[0][b][bt] += dp[0][b-1][bt-1];
				// turn e on
				if (bt > 0 && b <= emax) dp[0][b][bt] += dp[0][b-1][bt-1];
				// turn d,e on
				if (bt > 1 && b <= dmax && b <= emax)
					dp[1][b][bt] = dp[1][b-1][bt-2];
				else	dp[1][b][bt] = 0;
			}
		else for (int bt = 0; bt <= bits; ++bt) {
				// turn nothing on
				dp[0][b][bt] = dp[0][b-1][bt];
				dp[1][b][bt] = 0; // reset for ease
				// turn d on
				if (bt > 0 && b <= dmax) dp[1][b][bt] += dp[1][b-1][bt-1];
				// turn e on
				if (bt > 0 && b <= emax) dp[1][b][bt] += dp[1][b-1][bt-1];
				// turn d,e on
				if (bt > 1 && b <= dmax && b <= emax)
					dp[1][b][bt] += dp[0][b-1][bt-2];
			}
	}
	ll r = dp[0][lastbit - 1][bits];
	return r;
}

int main() {
	ll s, ans = 0;
	cin >> s;

	for (ll d = 1; d <= B; ++d)
		for (ll e = 1; e <= B; ++e) {
			ll G = ((1LL << d) + (1LL << e) - 3LL);
			ll x = s/G;
			if (x < 1) continue;
			ll r = s - x * G;
			r -= ((1LL << (e - 1)) - 1LL);
			if (r < 0) continue;
			if (r > (1LL << d) + (1LL << e) - d - e - 2LL)
				continue;
//			cerr << "Trying " << d << ' ' << e << ", making " << r << ", starting at " << x << endl;
			for (ll bits = r % 2; bits < max(2LL, d + e - 2LL); bits += 2)
				ans += solve(r+bits, bits, d-2, e-2);
		}

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll S, R;
int len1, len2;

ll cc[52][52][52][2];
ll dp(int bit, int rem1, int rem2, int c) {
    if(bit >= max(len1, len2)) return rem1 == 0 && rem2 == 0 && c == 0;
    ll &ret = cc[bit][rem1][rem2][c];
    if(ret != -1) return ret;

    if(bit >= len1 && rem1) return ret = 0;
    if(bit >= len2 && rem2) return ret = 0;

    ret = 0;
    for(int i = 0; i <= (rem1? 1 : 0); i++) {
        for(int j = 0; j <= (rem2? 1 : 0); j++) {
            if((i + j + c) % 2 == ((R & (1LL << bit))? 1 : 0)) {
                ret += dp(bit + 1, rem1 - i, rem2 - j, (i + j + c >= 2));
            }
        }
    }
    return ret;
}

int main() {
    cin >> S;

    ll ans = 0;
    for(int i = 0; i <= 50; i++) {
        for(int j = 0; j <= 50; j++) {
            ll Q;
            if(i == 0 && j == 0) Q = 1;
            else if(i == 0) Q = (1LL << (j + 1)) - 1;
            else if(j == 0) Q = (1LL << (i + 1)) - 1;
            else Q = (1LL << (i + 1)) + (1LL << (j + 1)) - 3;
            if(Q > S) break;
            R = S % Q;
            if(R < (1LL << j) - 1) break;
            R -= (1LL << j) - 1;

            for(int a = 0; a < (i? i : 1); a++) {
                for(int b = 0; b < (j? j : 1); b++) {
                    R += a + b;

                    //cout << R << endl;

                    if(R % 2) continue;
                    len1 = i;
                    len2 = j;
                    memset(cc, -1, sizeof(cc));
                    ans += dp(1, a, b, 0);
                }
            }

            //cout << i << ' ' << j << ' ' << ans << endl;
        }
    }
    cout << ans;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f[60][120][2];
ll n,L,R;
long long now;
long long dfs(int ws,int res,bool jw){
	if(res<0)return 0;
	if(~f[ws][res][jw])return f[ws][res][jw];
	long long&t=f[ws][res][jw];t=0;
	if((1ll<<ws)>now){
		if(res==0&&jw==0)t=1;
		return t;
	}
	if((1<<ws)&now){
		if(jw){
			t=dfs(ws+1,res,0);
			if(ws<L&&ws<R)t+=dfs(ws+1,res-2,1);
		}else{
			if(ws<L)t+=dfs(ws+1,res-1,0);
			if(ws<R)t+=dfs(ws+1,res-1,0);
		}
	}else{
		if(jw){
			if(ws<L)t+=dfs(ws+1,res-1,1);
			if(ws<R)t+=dfs(ws+1,res-1,1);
		}else{
			t=dfs(ws+1,res,0);
			if(ws<L&&ws<R)t+=dfs(ws+1,res-2,1);
		}
	}
	return t;
}
ll ans;
int main(){
	cin>>n;
	for(ll a=0;(1ll<<a)<=n;a++){
		for(ll b=0;(1ll<<b)<=n;b++){
			ll lca=(n-(1ll<<b)+1)/((1ll<<a+1)+(1ll<<b+1)-3);
			if(lca==0)continue;
			ll nn=n-lca*((1ll<<a+1)+(1ll<<b+1)-3)+1-(1ll<<b);
			for(int i=0;i<=a+b;i++){
				memset(f,-1,sizeof(f));
				L=a-1;R=b-1;
				now=nn+i;
				if(now&1)continue;now/=2;
				ans+=dfs(0,i,0);
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
LL stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    LL top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const LL MAXN=65;
LL n,bin[65];
LL solve1(LL u,LL ls)
{
	LL ret=0;
	for(LL j=0;j<=u;j++)
	{
		LL now=ls+j;
		if(__builtin_popcount(now)==j&&!(now&1)&&now<bin[u])++ret;
	}return ret;
}
LL f[MAXN][2*MAXN][2];
bool check(LL u,LL v){return (u&&v)|(!u&&!v);}
LL solve2(LL u1,LL u2,LL ls)
{
	--u1;--u2;LL ret=0;
	for(LL i=0;i<=u1+u2;i++)
	{
		LL now=ls+i;if(now&1)continue;
		memset(f,0,sizeof(f));f[0][0][0]=1;
		for(LL j=0;j<55;j++)for(LL x=0;x<=i;x++)
			for(LL k=0;k<=1;k++)if(f[j][x][k])
			{
				LL nx1=(k+2)&1,nx2=(k+2)>>1;
				if(check(now&bin[j+1],nx1)&&(j+1<=u1)&&(j+1<=u2))f[j+1][x+2][nx2]+=f[j][x][k];
				nx1=(k+1)&1,nx2=(k+1)>>1;
				if(check(now&bin[j+1],nx1)&&(j+1<=u1))f[j+1][x+1][nx2]+=f[j][x][k];
				if(check(now&bin[j+1],nx1)&&(j+1<=u2))f[j+1][x+1][nx2]+=f[j][x][k];
				nx1=k&1;nx2=k>>1;
				if(check(now&bin[j+1],nx1))f[j+1][x][nx2]+=f[j][x][k];
			}
		ret+=f[55][i][0];
	}return ret;
}
int main()
{
//	freopen("hunter.in","r",stdin);
//	freopen("hunter.out","w",stdout);
	bin[0]=1;for(LL i=1;i<=60;i++)bin[i]=bin[i-1]<<1;
	n=read();
	LL ans=0;
	for(LL i=0,temp=1;temp<=n;i++,temp<<=1)
	{
		LL x=n/(temp*2-1);
		if(x)ans+=solve1(i,n-x*(temp*2-1));
	}
	for(LL i=1,t1=2;t1<=n;i++,t1<<=1)
		for(LL j=1,t2=2;t2<=n;j++,t2<<=1)
		{
			LL x=(n-t2+1)/(t1*2+t2*2-3);
			if(x)ans+=solve2(i,j,n-x*(t1*2+t2*2-3)-t2+1);
		}
	pr2(ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 128;

LL f[2][N][2];
LL cal(int lx , int ly , int one , LL sum) {
  memset(f , 0 , sizeof(f));
  f[0][0][0] = 1;
  int cur = 0 , nxt = 1;
  for (int i = 0 ; (sum >> i) ; ++ i) {
    memset(f[nxt] , 0 , sizeof(f[nxt]));
    for (int dx = 0 ; dx < 2 ; ++ dx) {
      for (int dy = 0 ; dy < 2 ; ++ dy) {
        if (i >= lx && dx) continue;
        if (i >= ly && dy) continue;
        for (int j = 0 ; j < 2 ; ++ j) {
          int num = dx + dy + j;
          if ((sum >> i & 1) != (num & 1)) continue;
          for (int k = 0 ; k + dx + dy <= one ; ++ k) {
            f[nxt][k + dx + dy][num >> 1] += f[cur][k][j];
          }
        }
      }
    }
  }
  return f[cur][one][0];
}

int main() {
  LL s;
  cin >> s;
  LL res = 0;
  for (int a = 0 ; a <= 60 ; ++ a) {
    for (int b = 0 ; b <= 60 ; ++ b) {
      LL coff = (1LL << a + 1) + (1LL << b + 1) - 3;
      LL lca = s / coff , rem = s % coff - (1LL << b) + 1;
      if (lca < 1) continue;
      // 2(x + y) == rem + popcount(x) + popcount(y)
      // x < 2^{a-1} , y < 2^{b-1}
      for (int c = 0 ; c <= 120 ; ++ c) {
        LL sum = rem - c;
        if (sum < 0 || sum % 2 == 1) continue;
        sum >>= 1;
        res += cal(max(0 , a - 1) , max(0 , b - 1) , c , sum);
      }
    }
  }
  cout << res << endl;
}