#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll N, f[64][3];
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> N;
  f[60][0] = 1;
  for (int i = 59; i >= 0; --i) {
    f[i][2] = (f[i + 1][2] * 3 + f[i + 1][1]) % MOD;
    f[i][0] = f[i + 1][0];
    f[i][1] = f[i + 1][1];
    if ((N >> i) & 1) {
      (f[i][2] += f[i + 1][1]) %= MOD;
      (f[i][1] += f[i + 1][0]) %= MOD;
    } else {
      (f[i][0] += f[i + 1][1]) %= MOD;
    }
  }
  cout << (f[0][0] + f[0][1] + f[0][2]) % MOD;
  return 0;
}