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>

typedef long long i64;

const int N = 100 + 10, MOD = 1000000007;

i64 n;
int f[N][2][2][2];

int main() {
  scanf("%lld", &n);
  f[0][0][0][0] = 1;
  for (int i = 0; i < 64; ++i) {
    for (int x = 0; x < 2; ++x) { // <= or >
      for (int y = 0; y < 2; ++y) { // last a & b
        for (int z = 0; z < 2; ++z) { // +z
          int cur = f[i][x][y][z];
          if (!cur) continue;
          for (int a = 0; a < 2; ++a) { // current a ^ b
            for (int b = 0; b < 2; ++b) { // current a & b
              if (a && b) continue;
              int t = a + y + z;
              int p = t & 1, q = n >> i & 1, u;
              if (p == q) u = x; else u = (p < q ? 0 : 1);
              bool w = t >> 1;
              (f[i + 1][u][b][w] += cur) %= MOD;
            }
          }
        }
      }
    }
  }
  printf("%d\n", f[64][0][0][0]);
  return 0;
}
