#include <bits/stdc++.h>
using namespace std;
long long dp[200][200][2];
long long er[200], ei = 0;
int k;
long long c[200][200], t1[1000], t2[1000];
long long prim = 1000000007;
void initiall() {
  int i, j;
  for (i = 0; i <= 100; i++) c[i][0] = 1;
  for (i = 1; i <= 100; i++)
    for (j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % prim;
  for (i = 1; i <= 100; i++) {
    t1[i] = 0;
    t2[i] = 0;
    for (j = 0; j <= i; j++) {
      if (j % 2)
        t1[i] = (t1[i] + c[i][j]) % prim;
      else
        t2[i] = (t2[i] + c[i][j]) % prim;
    }
  }
}
int main() {
  initiall();
  int i, j, can;
  scanf("%d", &k);
  while (k > 0) {
    er[++ei] = k % 2;
    k /= 2;
  }
  for (i = 1; i <= ei / 2; i++) swap(er[i], er[ei - i + 1]);
  dp[0][0][1] = 1;
  for (i = 1; i <= ei; i++) {
    dp[i][0][0] = 1;
    for (j = 1; j <= i; j++)
      for (can = 0; can <= 1; can++) {
        if (can == 1) {
          if (er[i])
            dp[i][j][can] =
                (dp[i - 1][j - 1][1] + dp[i - 1][j][1] * t1[j]) % prim;
          else
            dp[i][j][can] = (dp[i - 1][j][1] * t2[j]) % prim;
        } else {
          dp[i][j][can] =
              (dp[i - 1][j][0] * (t1[j] + t2[j]) + dp[i - 1][j - 1][0]) % prim;
          if (er[i]) dp[i][j][can] += dp[i - 1][j][1] * t2[j];
        }
        dp[i][j][can] %= prim;
      }
  }
  long long ans = 1;
  for (i = 1; i <= ei; i++) ans += dp[ei][i][1] + dp[ei][i][0], ans %= prim;
  cout << ans << endl;
}
