#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7ll;
long long a[100] = {1,   2,   4,   5,   8,   10,  13,  14,  18,  21,  26,  28,
                    33,  36,  40,  41,  46,  50,  57,  60,  68,  73,  80,  82,
                    89,  94,  102, 105, 112, 116, 121, 122, 128, 133, 142, 146,
                    157, 164, 174, 177, 188, 196, 209, 214, 226, 233, 242, 244,
                    253, 260, 272, 277, 290, 298, 309, 312, 322, 329, 340};
long long f(long long k) {
  if (k == 0) {
    return 1ll;
  }
  if (k < 0) {
    return 0ll;
  }
  if (k <= 50) {
    return a[k];
  }
  if (k & 1) {
    return (2ll * f(k / 2ll) % mod + f(k / 2ll - 1ll) % mod) % mod;
  } else {
    return (2ll * f(k / 2ll - 1ll) % mod + f(k / 2ll) % mod) % mod;
  }
}
int main() {
  long long n;
  cin >> n;
  cout << f(n) << endl;
  return 0;
}
inline void getInt(int* p) {
  char ch;
  do {
    ch = getchar();
  } while (ch == ' ' || ch == '\n');
  if (ch == '-') {
    *p = -(getchar() - '0');
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 - ch + '0';
    }
  } else {
    *p = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 + ch - '0';
    }
  }
}
