#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int main() {
  long long dp[100][3] = {};
  long long N;
  cin >> N;
  dp[99][0] = 1;
  for (int i = 98; i >= 0; i--) {
    if ((N >> i) & 1) {
      dp[i][0] = (dp[i + 1][0]) % 1000000007;
      dp[i][1] = (dp[i + 1][0] + dp[i + 1][1]) % 1000000007;
      dp[i][2] = (3 * dp[i + 1][2] + 2 * dp[i + 1][1]) % 1000000007;
    } else {
      dp[i][0] = (dp[i + 1][0] + dp[i + 1][1]) % 1000000007;
      dp[i][1] = (dp[i + 1][1]) % 1000000007;
      dp[i][2] = (3 * dp[i + 1][2] + dp[i + 1][1]) % 1000000007;
    }
  }
  cout << (dp[0][0] + dp[0][1] + dp[0][2]) % 1000000007 << endl;
  return 0;
}
