#include <bits/stdc++.h>
using namespace std;
long long n;
const long long mod = 1000000007LL;
long long dp[35][35][2];
void init() {
  int tmp;
  scanf("%d", &tmp);
  n = tmp;
}
void process() {
  dp[32][0][0] = 1;
  for (int i = 32; i > 0; i--) {
    for (int j = 0; j <= 32 - i; j++) {
      long long t1, t2;
      if (j == 0)
        t1 = 1, t2 = 0;
      else
        t1 = t2 = 1 << (j - 1);
      if (n & (1 << (i - 1))) {
        dp[i - 1][j][0] = (dp[i - 1][j][0] + dp[i][j][0] * t2) % mod;
        dp[i - 1][j + 1][0] = (dp[i - 1][j + 1][0] + dp[i][j][0]) % mod;
        dp[i - 1][j][1] = (dp[i - 1][j][1] + dp[i][j][0] * t1) % mod;
        dp[i - 1][j + 1][1] = (dp[i - 1][j + 1][1] + dp[i][j][1]) % mod;
        dp[i - 1][j][1] = (dp[i - 1][j][1] + dp[i][j][1] * (t1 + t2)) % mod;
      } else {
        dp[i - 1][j][0] = (dp[i - 1][j][0] + dp[i][j][0] * t1) % mod;
        dp[i - 1][j + 1][1] = (dp[i - 1][j + 1][1] + dp[i][j][1]) % mod;
        dp[i - 1][j][1] = (dp[i - 1][j][1] + dp[i][j][1] * (t1 + t2)) % mod;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= 32; i++) ans = (ans + dp[0][i][0] + dp[0][i][1]) % mod;
  cout << ans << endl;
}
int main() {
  init();
  process();
  return 0;
}
