#include <bits/stdc++.h>
using namespace std;
vector<int> va;
long long int dp[100][2][2][2];
long long int f(long long int x, long long int c, long long int t1,
                long long int t2) {
  if (x < 0) {
    return c == 0;
  }
  if (dp[x][c][t1][t2] != -1) return dp[x][c][t1][t2];
  long long int m1 = 1, m2 = 1;
  if (t1) m1 = va[x];
  if (t2) m2 = va[x];
  long long int p = 0;
  for (int u = 0; u <= m1; ++u) {
    for (int v = 0; v <= m2; ++v) {
      int flg = 0;
      for (int a = 0; a <= 1; ++a) {
        if (flg) continue;
        for (int b = 0; b <= 1; ++b) {
          if (a ^ b != u || flg) continue;
          if ((a + b) % 2 == v && (a + b) / 2 == c) {
            flg = 1;
            long long int n1 = t1, n2 = t2;
            if (u != va[x]) n1 = 0;
            if (v != va[x]) n2 = 0;
            p = p + f(x - 1, 0, n1, n2);
            if (p > 1000000007) p -= 1000000007;
          }
          if ((a + b + 1) % 2 == v && (a + b + 1) / 2 == c) {
            flg = 1;
            long long int n1 = t1, n2 = t2;
            if (u != va[x]) n1 = 0;
            if (v != va[x]) n2 = 0;
            p = p + f(x - 1, 1, n1, n2);
            if (p > 1000000007) p -= 1000000007;
          }
        }
      }
    }
  }
  dp[x][c][t1][t2] = p;
  return p;
}
int solve() {
  long long int n, i, j, k, m;
  cin >> n;
  while (n) {
    va.push_back(n % 2);
    n /= 2;
  }
  memset(dp, -1, sizeof(dp));
  long long int p = f(va.size() - 1, 0, 1, 1);
  cerr << p << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, i, j;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
  ;
}
