#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
inline string IntToString(long long a) {
  char x[100];
  sprintf(x, "%lld", a);
  string s = x;
  return s;
}
inline long long StringToInt(string a) {
  char x[100];
  long long res;
  strcpy(x, a.c_str());
  sscanf(x, "%lld", &res);
  return res;
}
inline string GetString(void) {
  char x[1000005];
  scanf("%s", x);
  string s = x;
  return s;
}
inline string uppercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}
inline string lowercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}
inline void OPEN(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
int f(int n) {
  int risan = 0;
  for (int(u) = (0); (u) <= (n); ++(u))
    for (int(v) = (0); (v) <= (n); ++(v)) {
      for (int(a) = (0); (a) <= (v); ++(a)) {
        int b = v - a;
        if ((a ^ b) == u) {
          ++risan;
          goto ok;
        }
      }
    ok:;
    }
  return risan;
}
int g(int n) {
  int risan = 0;
  for (int(a) = (0); (a) <= (n); ++(a))
    for (int(b) = (a); (b) <= (n); ++(b)) {
      if (a + b <= n)
        ;
      if (a + b <= n) ++risan;
    }
  return risan;
}
map<pair<long long, long long>, long long> dp;
unordered_map<long long, long long> dpa;
long long MOD = 1e9 + 7;
long long n;
long long a(long long n) {
  if (dpa.count(n)) return dpa[n];
  if (n == 0) return 0;
  if (n == 1) return 1;
  if (n % 2 == 0) return dpa[n] = a(n / 2);
  return dpa[n] = (a(n / 2) + a(n / 2 + 1)) % MOD;
}
inline long long sum(long long l, long long r) {
  if (l > r) return 0;
  if (dp.count(make_pair(l, r))) return dp[make_pair(l, r)];
  if (l > 1) {
    return dp[make_pair(l, r)] = (sum(1, r) - sum(1, l - 1) + MOD) % MOD;
  }
  if (r - l <= 2) {
    long long res = 0;
    for (long long i = l; i <= r; ++i) res += a(i);
    return dp[make_pair(l, r)] = res % MOD;
  }
  long long &res = dp[make_pair(l, r)];
  long long ret = 0;
  if (r % 2 == 1) {
    ret = a(r);
    --r;
  }
  long long m = (l + r) >> 1;
  if (m % 2 == 1) ++m;
  ret += (sum(m / 2, r / 2) * 3 - a(m / 2) - a(r / 2));
  ret += sum(l, m - 1);
  return res = ret % MOD;
}
int main() {
  scanf("%lld", &n);
  printf("%lld\n", sum(1, n + 1));
  return 0;
  for (int(i) = (1); (i) <= (30); ++(i)) {
    ;
    assert(sum(1, i + 1) == f(i));
  };
  ;
  return 0;
}
