あ#include <iostream>
using namespace std;

typedef long long ll;

ll mod=1e9+7;

ll f(ll n){
  if(n==0) return 1;
  else if(n%2==0) return f(n/2)+f(n/2-1);
  else return f(n/2);
}

ll sum(ll n){
  if(n==0) return 1;
  else if(n%2==0) return (3*sum(n/2-1)+f(n/2))%mod;
  else return (3*sum(n/2)-f(n/2))%mod;
}

int main(){
  ll n;
  cin >> n;
  cout << sum(n) << endl;
}

