You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.

Constraints

* 1≦N≦10^{18}

Input

The input is given from Standard Input in the following format:


N


Output

Print the number of the possible pairs of integers u and v, modulo 10^9+7.

Examples

Input

3


Output

5


Input

1422


Output

52277


Input

1000000000000000000


Output

787014179
#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;
}
