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