#include <bits/stdc++.h>
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
void mkuni(vector<T> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class T>
void print(T x, int suc = 1) {
  cout << x;
  if (suc == 1)
    cout << '\n';
  else
    cout << ' ';
}
template <class T>
void print(const vector<T> &v, int suc = 1) {
  for (int i = 0; i < v.size(); i++)
    print(v[i], i == (int)(v.size()) - 1 ? suc : 2);
}
const int mod = 1e9 + 7;
int a[70];
long long dp[70][2][2];
long long dfs(int pos, bool limit = 1, bool add = 0) {
  if (pos == -1) return add == 0;
  long long &ret = dp[pos][limit][add];
  if (ret != -1) return ret;
  ret = 0;
  int up = limit ? a[pos] : 1;
  if (up == 1) {
    if (add)
      ret = (ret + dfs(pos - 1, limit, 1)) % mod;
    else {
      ret = (ret + dfs(pos - 1, limit, 0)) % mod;
      ret = (ret + dfs(pos - 1, limit, 1));
    }
    return ret;
  }
  if (add) {
    ret = (ret + dfs(pos - 1, limit && up == 0, 0)) % mod;
    ret = (ret + dfs(pos - 1, limit && up == 0, 1)) % mod;
  } else {
    ret = (ret + dfs(pos - 1, limit && up == 0, 0)) % mod;
  }
  return ret;
}
int solve(long long x) {
  memset(dp, -1, sizeof(dp));
  int pos = 0;
  while (x) {
    a[pos++] = x % 2;
    x /= 2;
  }
  return dfs(pos - 1);
}
int main() {
  long long n;
  cin >> n;
  cout << solve(n) << endl;
}
