#include <bits/stdc++.h>
const int MOD = 1E9 + 7;
const int N = 1000000 + 5;
const int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};
using namespace std;
long long a[20] = {1,  2,  4,  5,  8,  10, 13, 14, 18, 21,
                   26, 28, 33, 36, 40, 41, 46, 50, 57, 60};
map<long long, long long> mp;
long long cal(long long x) {
  if (x <= 20) return a[x];
  if (mp[x]) return mp[x];
  if (x % 2)
    return mp[x] = (2 * cal(x / 2) % MOD + cal(x / 2 - 1) % MOD) % MOD;
  else
    return mp[x] = (2 * cal(x / 2 - 1) % MOD + cal(x / 2) % MOD) % MOD;
}
int main() {
  long long n;
  scanf("%lld", &n);
  printf("%lld\n", cal(n));
  return 0;
}
