#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long int linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;
long long int dp[100][3];
int main(int argc, char const* argv[]) {
  long long int n;
  cin >> n;
  long long int tmp = n;
  vector<int> vec;
  while (tmp) {
    vec.push_back(int(tmp % 2));
    tmp /= 2;
  }
  reverse(vec.begin(), vec.end());
  dp[0][0] = 1;
  for (int i = (1); i < (vec.size() + 1); ++i) {
    dp[i][0] = dp[i - 1][0];
    if (vec[i - 1] == 0) dp[i][0] = (dp[i][0] + dp[i - 1][1]) % mod;
    if (vec[i - 1] == 0) {
      dp[i][1] = dp[i - 1][1];
    } else {
      dp[i][1] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
    }
    dp[i][2] = dp[i - 1][2] * 3 % mod;
    if (vec[i - 1] == 0) {
      dp[i][2] = (dp[i][2] + dp[i - 1][1]) % mod;
    } else {
      dp[i][2] = (dp[i][2] + dp[i - 1][1] * 2) % mod;
    }
  }
  cout << dp[vec.size()][0] + dp[vec.size()][1] + dp[vec.size()][2] << endl;
  return 0;
}
