#include<bits/stdc++.h>
using namespace std; 
const int MOD = 1e9 + 7;
typedef long long ll; 
map<ll, ll> m; 
ll f(ll n) 
{
  return m[n] > 0 ? m[n]: (m[n] = (f(n / 2) + f((n - 1) / 2) % MOD + f((n - 2) / 2)) %MOD);
} 
int main() 
{
  ll n;
  cin>>n;
  m[0] = 1;
  m[1] = 2;
  cout<<f(n);
  return 0;
}