#include <bits/stdc++.h>
using namespace std;
long dp[66][3], m = 1e9 + 7, n;
int b;
int main() {
  cin >> n;
  dp[60][0] = 1;
  for (int i = 59; i >= 0; i--) {
    b = (n >> i) & 1;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j * 2 + b >= k) {
          (dp[i][min(j * 2 + b - k, 2)] += dp[i + 1][j]) %= m;
        }
      }
    }
  }
  cout << dp[0][0] + dp[0][1] + dp[0][2] << endl;
}
