#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long dp[40][40][2];
int x, a[40], n, i, j;
int main() {
  scanf("%d", &x);
  for (n = 0; x; x /= 2) a[++n] = x % 2;
  dp[n][1][1] = 1;
  for (i = n - 1; i >= 1; i--) {
    for (j = 1; j <= n; j++) {
      dp[i][j][0] = (dp[i][j][0] + dp[i + 1][j][0] * (1 << (j - 1))) % MOD;
      if (a[i])
        dp[i][j][0] = (dp[i][j][0] + dp[i + 1][j][1] * (1 << (j - 1))) % MOD;
      dp[i][j][0] = (dp[i][j][0] + dp[i + 1][j][0] * (1 << (j - 1))) % MOD;
      dp[i][j][1] = (dp[i][j][1] + dp[i + 1][j][1] * (1 << (j - 1))) % MOD;
      dp[i][j + 1][0] = (dp[i][j + 1][0] + dp[i + 1][j][0]) % MOD;
      if (a[i]) dp[i][j + 1][1] = (dp[i][j + 1][1] + dp[i + 1][j][1]) % MOD;
    }
    dp[i][1][0] = (dp[i][1][0] + 1) % MOD;
  }
  long long ans = 1;
  for (i = 1; i <= n; i++) ans = (ans + dp[1][i][0] + dp[1][i][1]) % MOD;
  printf("%lld", ans);
}
