#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define ll long long

using namespace std;
map<ll,ll>dp;
const ll mod=1e9+7;
ll solve(ll n)
{
  if(dp[n])
    return dp[n];
  else
    return dp[n]=(solve(n/2)%mod+solve((n-1)/2)%mod+solve((n-2)/2)%mod)%mod;
}
int main()
{
   ll n;
   while(~scanf("%lld",&n))
         {
            dp[0]=1;
            dp[1]=2;
             printf("%lld\n",solve(n));
         }
         return 0;
}
