#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000007;
const int MB = 40;
long long dp[MB][MB][2];
long long c[MB][MB];
long long k;
int main() {
  for (int i = 0; i < MB; i++) {
    c[i][0] = c[i][i] = 1ll;
    for (int j = 1; j < i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
      if (c[i][j] >= Mod) c[i][j] -= Mod;
    }
  }
  cin >> k;
  dp[MB - 1][0][1] = 1;
  for (int i = MB - 2; i >= 0; i--) {
    for (int pb = 0; pb < MB - 1 - i; pb++) {
      if (k & (1ll << i)) {
        (dp[i][pb + 1][0] += dp[i + 1][pb][0]) %= Mod;
        (dp[i][pb][0] += dp[i + 1][pb][0] + dp[i + 1][pb][1]) %= Mod;
        (dp[i][pb][0] += dp[i + 1][pb][0] * ((1ll << pb) - 1)) %= Mod;
        (dp[i][pb + 1][1] += dp[i + 1][pb][1]) %= Mod;
        long long sodd = 0, seven;
        for (int odd = 1; odd <= pb; odd += 2) (sodd += c[pb][odd]) %= Mod;
        (((seven = (1ll << pb) - sodd) %= Mod) += Mod) %= Mod;
        (dp[i][pb][0] += dp[i + 1][pb][1] * (seven - 1)) %= Mod;
        (dp[i][pb][1] += dp[i + 1][pb][1] * sodd) %= Mod;
      } else {
        (dp[i][pb + 1][0] += dp[i + 1][pb][0]) %= Mod;
        (dp[i][pb][0] += dp[i + 1][pb][0] * ((1ll << pb) - 1)) %= Mod;
        (dp[i][pb][0] += dp[i + 1][pb][0]) %= Mod;
        dp[i][pb + 1][1] += 0;
        (dp[i][pb][1] += dp[i + 1][pb][1]) %= Mod;
        long long sodd = 0, seven;
        for (int odd = 1; odd <= pb; odd += 2) (sodd += c[pb][odd]) %= Mod;
        (((seven = (1ll << pb) - sodd) %= Mod) += Mod) %= Mod;
        (dp[i][pb][1] += dp[i + 1][pb][1] * (seven - 1)) %= Mod;
      }
    }
  }
  long long ans = 0ll;
  for (int i = 0; i < MB; i++) (ans += dp[0][i][0] + dp[0][i][1]) %= Mod;
  cout << ans << endl;
}
