#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
vector<int> g;
int n, f[30][30][2];
int dfs(int x, int p, bool ismx) {
  if (x == -1) return 1;
  int& ret = f[x][p][ismx];
  if (ret) return ret;
  if (!ismx || g[x]) ret = dfs(x - 1, p + 1, ismx);
  for (int i = 0; i <= (p && (ismx ? g[x] : 1)); ++i)
    ret = (ret + (long long)dfs(x - 1, p, ismx && i == g[x]) *
                     max((1 << p >> 1), 1)) %
          M;
  return ret;
}
int main() {
  scanf("%d", &n);
  while (n) {
    g.push_back(n & 1);
    n >>= 1;
  }
  cout << dfs(g.size() - 1, 0, 1);
}
