#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
bool can[100005];
int ans;
int lim;
long long n;
void solve() {
  scanf("%lld", &n);
  assert(n <= 100000);
  lim = 1;
  while (lim <= n) {
    lim <<= 1;
  }
  for (int x = 0; x <= n; ++x) {
    int m = (lim - 1) ^ x;
    for (int s = m;; s = (s - 1) & m) {
      if (s * 2 + x <= n) {
        ++ans;
        ans %= mod;
      }
      if (s == 0) {
        break;
      }
    }
  }
  printf("%d", ans);
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
