#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

const ll p=1e9+7;
const int MAX_N=100000;

map<ll,map<ll,ll>> memo;
ll f(ll S, ll X) {
  if(memo[S].find(X)!=memo[S].end()) {
    return memo[S][X];
  }
  ll ret=0;
  if(S-2>=0)
    ret+=f((S-2)/2,X/2);
  if(S-1>=0&&X-1>=0)
    ret+=f((S-1)/2,(X-1)/2);
  ret+=f(S/2,X/2);
  return memo[S][X]=ret%p;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll n;
  cin>>n;
  memo[0][0]=1;
  memo[1][0]=1;
  memo[0][1]=1;
  memo[1][1]=2;
  cout << f(n,n)<<endl;
  return 0;
}
