#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=~(1<<31),MAXN=1e6+10;
const int MOD=1e9+7;

map<ll,ll> mp;

ll dfs(ll now)
{
    ll ans=0;
    if(mp[now])return mp[now];
    if(now==1)return 2;
    if(now==0)return 1;
    if(now&1)
    {
        ans+=2*dfs(now/2);
        ans+=dfs(now/2-1);
    }
    else
    {
        ans+=dfs(now/2);
        ans+=2*dfs(now/2-1);
    }
    mp[now]=ans%MOD;
    return ans%MOD;
}

int main()
{
    ll n;
    scanf("%lld",&n);
    cout<<dfs(n);
	return 0;
}
