#include <bits/stdc++.h>
using namespace std;
const long long MOD = long long(1e9 + 7);
long long dp[70][2][2];
int a[70];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  for (int i = 0; i < 64; i++) {
    a[i] = N >> i & 1;
  }
  dp[0][0][0] = 1;
  for (int i = 0; i < 64; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        if (dp[i][j][k] == 0) continue;
        int u[4] = {0, 1, 0}, v[4] = {0, 0, 1};
        for (int l = 0; l < 3; l++) {
          int sum = j + u[l] + v[l];
          int nj = sum / 2;
          int nk = (sum % 2) > a[i] || k && (sum % 2) >= a[i];
          dp[i + 1][nj][nk] += dp[i][j][k];
          dp[i + 1][nj][nk] %= MOD;
        }
      }
    }
  }
  cout << dp[64][0][0] << endl;
}
