#include <bits/stdc++.h>
using namespace std;
long long n, a[100], len, dp[100][100][2];
const long long ha = 1e9 + 7;
long long dfs(long long pos, long long j, long long mn) {
  if (pos == 0) return 1;
  if (dp[pos][j][mn] != -1) return dp[pos][j][mn];
  long long &now = dp[pos][j][mn], lim = mn ? a[pos] : 1;
  now = 0;
  if (!mn) {
    now = (now + dfs(pos - 1, j + 1, 0)) % ha;
    now = (now + dfs(pos - 1, j, 0) * (1 << j)) % ha;
  } else {
    now = (now +
           dfs(pos - 1, j, mn && 0 == lim) * (j == 0 ? 1 : (1 << (j - 1)))) %
          ha;
    if (a[pos] == 1)
      now = (now + dfs(pos - 1, j + 1, mn && lim == 1)) % ha,
      now = (now +
             dfs(pos - 1, j, mn && 1 == lim) * (j == 0 ? 0 : (1 << (j - 1)))) %
            ha;
  }
  return now;
}
signed main() {
  scanf("%lld", &n);
  memset(dp, -1, sizeof dp);
  while (n) a[++len] = n & 1, n >>= 1;
  printf("%lld", dfs(len, 0, 1));
  return 0;
}
