#include <bits/stdc++.h>
long long int N;
int dp[70][3], bit, ans;
int main() {
  scanf("%lld", &N);
  dp[0][0] = 1;
  for (long long int i = N; i > 0; i /= 2) {
    ++bit;
  }
  for (int i = 0; i <= bit; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (N >> (bit - i) & 1) {
        dp[i + 1][std::min(j * 2 + 1, 2)] += dp[i][j];
        dp[i + 1][std::min(j * 2, 2)] += dp[i][j];
        dp[i + 1][std::min(j * 2 + 1, 2)] %= 1000000007;
        dp[i + 1][std::min(j * 2, 2)] %= 1000000007;
        if ((j * 2 - 1) >= 0) {
          dp[i + 1][std::min(j * 2 - 1, 2)] += dp[i][j];
          dp[i + 1][std::min(j * 2 - 1, 2)] %= 1000000007;
        }
      } else {
        dp[i + 1][std::min(j * 2, 2)] += dp[i][j];
        dp[i + 1][std::min(j * 2, 2)] %= 1000000007;
        if ((j * 2 - 1) >= 0) {
          dp[i + 1][std::min(j * 2 - 1, 2)] += dp[i][j];
          dp[i + 1][std::min(j * 2 - 1, 2)] %= 1000000007;
        }
        if ((j * 2 - 2) >= 0) {
          dp[i + 1][std::min(j * 2 - 2, 2)] += dp[i][j];
          dp[i + 1][std::min(j * 2 - 2, 2)] %= 1000000007;
        }
      }
    }
  }
  ans = dp[bit + 1][0] + dp[bit + 1][1] + dp[bit + 1][2];
  ans %= 1000000007;
  printf("%d\n", ans);
  return 0;
}
