#include <bits/stdc++.h>
using namespace std;
long long addmod(long long x, long long y) {
  if (x + y >= 1000000007)
    return x + y - 1000000007;
  else
    return x + y;
}
long long productmod(long long x, long long y) {
  if (x * y >= 1000000007)
    return (x * y) % 1000000007;
  else
    return x * y;
}
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] = addmod(dp[i + 1][0], dp[i + 1][1]);
      dp[i][2] =
          addmod(productmod(dp[i + 1][1], 2), productmod(dp[i + 1][2], 3));
    } else {
      dp[i][0] = addmod(dp[i + 1][0], dp[i + 1][1]);
      dp[i][1] = dp[i + 1][1] % 1000000007;
      dp[i][2] = addmod(dp[i + 1][1], productmod(dp[i + 1][2], 3));
    }
  }
  long long ans = 0;
  for (int i = 0; i < 3; i++) {
    ans = addmod(ans, dp[0][i]);
  }
  cout << ans << endl;
}
