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 <cstdio>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll mod = 1000000007;

ll N;
std::map<P, ll> dp;

ll f( ll S, ll X )
{
  if( dp.count( P( S, X ) ) )
    return dp[P( S, X )];

  ll &ret = dp[P( S, X )];

  // S = 0, X = 0; (1) S = 1, X = 1 (1), S = 2, X = 0 (1)

  if( S == 1 && X == 1 )
    return ret = 2;
  else if( !S || !X )
    return ret = 1;

  return ret = ( ( (S >= 2 && X >= 0 ? f( (S-2)/2, X/2 ) : 0) + (S >= 1 && X >= 1 ? f( (S-1)/2, (X-1)/2 ) : 0) ) % mod + ( S >= 0 && X >= 0 ? f( S/2, X/2 ) : 0 ) ) % mod;
}

int main()
{
  scanf( "%lld", &N );

  printf( "%lld\n", f( N, N ) );
  
  return 0;
}