#include <bits/stdc++.h>
using namespace std;
map<pair<long long, int>, long long> mp1, mp2;
long long func2(long long X, int K);
long long func(long long X, int K) {
  int i;
  if ((1ll << K) > X) return 0;
  if (X == 1 || K == 0) return 1;
  pair<long long, int> p = make_pair(X, K);
  if (mp1.find(p) != mp1.end()) return mp1[p];
  for (i = 30;; i--)
    if ((1ll << i) < X) break;
  long long two = (1ll << i);
  long long ans = (func(two, K) + func2(X - two, K - 1)) % 1000000007ll;
  return mp1[p] = ans;
}
long long func2(long long X, int K) {
  int i;
  if ((1ll << K) > X) return 0;
  if (X == 1) return 1;
  if (K == 0) return X % 1000000007ll;
  pair<long long, int> p = make_pair(X, K);
  if (mp2.find(p) != mp2.end()) return mp2[p];
  for (i = 30;; i--)
    if ((1ll << i) < X) break;
  long long two = (1ll << i);
  long long ans =
      (func2(two, K) +
       (two / (1ll << (K - 1))) % 1000000007ll * func2(X - two, K - 1) +
       func2(X - two, K)) %
      1000000007ll;
  return mp2[p] = ans;
}
int main(void) {
  long long X;
  cin >> X;
  X++;
  long long ans = 0;
  int i;
  for ((i) = 0; (i) < (int)(30); (i)++) ans = (ans + func(X, i)) % 1000000007ll;
  cout << ans << endl;
  return 0;
}
