#include <bits/stdc++.h>
using namespace std;
signed main() {
  unsigned long long n;
  cin >> n;
  int digit = ceil(log2((double)n));
  bitset<64> nbs(n);
  long long dp[digit][3];
  fill(dp[0], dp[digit], 0);
  dp[digit - 1][0] = 1;
  dp[digit - 1][1] = 1;
  dp[digit - 1][2] = 0;
  for (int i = digit - 2; i >= 0; i--) {
    if (nbs.test(i)) {
      dp[i][0] = dp[i + 1][0];
      dp[i][1] = (dp[i + 1][0] + dp[i + 1][1]) % 1000000007;
      dp[i][2] = (dp[i + 1][1] * 2 + dp[i + 1][2] * 3) % 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] = (dp[i + 1][1] + dp[i + 1][2] * 3) % 1000000007;
    }
  }
  cout << (accumulate(dp[0], dp[0] + 3, 0LL) % 1000000007) << endl;
}
