#include using namespace std; long long N, dp[66][2][2][2][2], mod = 1000000007; long long solve(long long dig, long long t1, long long t2, long long a, long long b) { if (dig == -1) { if (a == 1 && b == 1) return 1; return 0; } if (dp[dig][t1][t2][a][b] >= 1) return dp[dig][t1][t2][a][b] - 1; long long B1 = 1, B2 = 1; if (t1 == 0 && (N / (1LL << dig)) % 2 == 0) B1 = 0; if (t2 == 0 && (N / (1LL << dig)) % 2 == 0) B2 = 0; long long sum = 0; for (int i = 0; i <= B1; i++) { for (int j = 0; j <= B2; j++) { int n1 = t1, n2 = t2; if (i != B1) n1 = 1; if (j != B2) n2 = 1; int c1 = a, c2 = b; if ((i&j) < (i^j)) c1 = 1; if ((i^j) < (i | j)) c2 = 1; if (c1 == 0 && (i&j) > (i^j)) continue; if (c2 == 0 && (i^j) > (i | j)) continue; sum += solve(dig - 1, n1, n2, c1, c2); sum %= mod; } } dp[dig][t1][t2][a][b] = sum + 1; return sum; } int main() { cin >> N; cout << solve(60, 0, 0, 0, 0) / 2 << endl; return 0; }