#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dp[65][2][2][2] = {0};
int main() {
  long long n;
  cin >> n;
  long long n2 = n, keta = 1;
  while (n2 > 1) {
    n2 /= 2;
    keta++;
  }
  dp[0][0][0][0] = 1;
  dp[0][1][0][1] = 1;
  long long o1 = 0, o2 = 0;
  for (int i = 0; i < keta - 1; i++) {
    int nk = keta - i - 2;
    long long no1 = 0, no2 = 0;
    dp[i + 1][0][0][0] += dp[i][0][0][0] + dp[i][0][1][0];
    dp[i + 1][0][1][0] += dp[i][1][0][0] + dp[i][1][1][0] + o1;
    dp[i + 1][1][0][0] += dp[i][0][0][0] + dp[i][0][1][0];
    dp[i + 1][1][1][0] += dp[i][1][0][0] + dp[i][1][1][0] + o1;
    no1 += dp[i][1][0][0] + dp[i][1][1][0] + o1;
    if (((n >> nk) & 1) == 0) {
      dp[i + 1][0][0][1] += dp[i][0][0][1] + dp[i][0][1][1];
      dp[i + 1][0][1][1] += dp[i][1][0][1] + dp[i][1][1][1] + o2;
      no2 += dp[i][1][0][1] + dp[i][1][1][1] + o2;
    } else {
      dp[i + 1][0][0][0] += dp[i][0][0][1] + dp[i][0][1][1];
      dp[i + 1][0][1][0] += dp[i][1][0][1] + dp[i][1][1][1] + o2;
      dp[i + 1][1][0][1] += dp[i][0][0][1] + dp[i][0][1][1];
      dp[i + 1][1][1][1] += dp[i][1][0][1] + dp[i][1][1][1] + o2;
      no1 += dp[i][1][0][1] + dp[i][1][1][1] + o2;
    }
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        for (int l = 0; l < 2; l++) dp[i + 1][j][k][l] %= mod;
      }
    }
    o1 = no1;
    o2 = no2;
    o1 %= mod;
    o2 %= mod;
  }
  long long ans = 0;
  for (int j = 0; j < 2; j++) {
    for (int k = 0; k < 2; k++) {
      for (int l = 0; l < 2; l++) {
        ans += dp[keta - 1][j][k][l];
      }
    }
  }
  cout << (ans + o1 + o2) % mod << endl;
}
