#include <bits/stdc++.h>
using namespace std;
const int N = 61, Mod = 1000000007;
long long f[N][N], g[N][N];
int main() {
  int i, j, t;
  long long n, ans;
  t = 1;
  while (t--) {
    ans = 1;
    scanf("%lld", &n);
    for (i = N - 2; i >= 0; n &= ((long long)1 << i) - 1, i--) {
      if (g[i + 1][1] || n >> i)
        g[i][1] = 1;
      else
        g[i][1] = 0;
      f[i][1] = f[i + 1][1] * 2;
      if (g[i + 1][1]) f[i][1]++;
      if (n >> i) f[i][1] += g[i + 1][1];
      f[i][1] %= Mod;
      for (j = 2; j < N; j++) {
        g[i][j] = (g[i + 1][j] * ((long long)1 << j - 1)) % Mod;
        if (n >> i) g[i][j] = (g[i][j] + g[i + 1][j - 1]) % Mod;
        f[i][j] = (f[i + 1][j - 1] + f[i + 1][j] * ((long long)1 << j)) % Mod;
        if (n >> i)
          f[i][j] = (f[i][j] + g[i + 1][j] * ((long long)1 << j - 1)) % Mod;
      }
    }
    for (j = 1; j < N; j++) ans = (ans + f[0][j] + g[0][j]) % Mod;
    cout << ans << endl;
  }
  return 0;
}
