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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

const ll mod = 1e9 + 7;

map<pair<ll,ll>,ll> dp;

ll f(ll x, ll y) {
  if (x<0 || y<0) return 0;
  if (dp.count({x,y})) return dp[{x,y}];
  if (x==0 && y==0) return 1;

  ll res = 0;
  if (x>=2 && y>=2) res += f((x-2)/2, (y-2)/2);
  if (x>=1 && y>=1) res += f((x-1)/2, (y-1)/2);
  res += f(x/2, y/2);
  res %= mod;
  res += mod;
  res %= mod;

  return dp[{x,y}] = res;
}

ll n;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n;
  ll res = f(n,n);
  res %= mod;
  res += mod;
  res %= mod;
  cout<<res<<endl;
  

  return 0;
}
// don't forget to read in the input :^)
