#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<ll,ll> mp;
ll f(ll n) {
  if (n==0) return 0;
  if (n==1) return 1;
  if (mp.count(n)) return mp[n];
  if (n%2) {
    return mp[n] = (2LL*f(n/2)%mod + f(n/2+1)%mod);
  } else {
    return mp[n] = (2LL*f(n/2)%mod + f(n/2-1)%mod);
  }
}

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

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