#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int pw[35];
int ans;
int lim;
long long n;
void pre() {
  pw[0] = 1;
  for (int i = 1; i < 30; ++i) {
    pw[i] = pw[i - 1] << 1;
  }
}
int calc(int m, int x) {
  int ans = 0;
  while (x > 0) {
    int k = 1;
    while ((k << 1) <= x) {
      k <<= 1;
    }
    int p = m & (k - 1);
    ans += pw[__builtin_popcount(p)];
    ans %= mod;
    if (m & k) {
      x -= k;
    } else {
      break;
    }
  }
  if (x == 0) {
    ++ans;
  }
  return ans;
}
void solve() {
  scanf("%lld", &n);
  assert(n <= 10000000);
  for (int x = 0; x <= n; ++x) {
    ans += calc(~x, (n - x) / 2);
    ans %= mod;
  }
  printf("%d", ans);
}
int main() {
  int tt = 1;
  pre();
  while (tt--) {
    solve();
  }
  return 0;
}
