#include <bits/stdc++.h>
using namespace std;
template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  while (cin >> n) {
    const int N = 70;
    const int M = 20;
    const long long int mod = 1e9 + 7;
    long long int dp[N][M];
    fill(&dp[0][0], &dp[N - 1][M - 1] + 1, 0);
    dp[0][0] = 1;
    cout << ">>>> " << n << endl;
    vector<int> v;
    for (long long int i = 1; i <= n; i *= 2LL) {
      v.push_back((bool)(n & i));
    }
    reverse(v.begin(), v.end());
    for (int nth = 0; nth < v.size(); ++nth) {
      for (int i = 0; i < 3; ++i) {
        {
          int a = 0, b = 0;
          const int j = i * 2 + v[nth] - a - b;
          if (0 <= j) {
            (dp[nth + 1][min(j, 2)] += dp[nth][i]) %= mod;
          }
        }
        {
          int a = 1, b = 1;
          const int j = i * 2 + v[nth] - a - b;
          if (0 <= j) {
            (dp[nth + 1][min(j, 2)] += dp[nth][i]) %= mod;
          }
        }
        {
          int a = 0, b = 1;
          const int j = i * 2 + v[nth] - a - b;
          if (0 <= j) {
            (dp[nth + 1][min(j, 2)] += dp[nth][i]) %= mod;
          }
        }
      }
    }
    long long int sum = dp[v.size()][0] + dp[v.size()][1] + dp[v.size()][2];
    sum %= mod;
    cout << sum << endl;
  }
  return 0;
}
