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>
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 :^)
