#include <cstdio>
#include <map>
const long long MOD = 1e9 + 7;
std::map<long long, long long> dp;
long long f(long long x) {
    if (dp[x]) return dp[x] % MOD;
    return dp[x] = (f((x - 1) / 2) + f(x / 2) + f((x - 2) / 2)) % MOD;
}
int main() {
    long long n;
    scanf("%lld", &n);
    dp[0] = 1;
    dp[1] = 2;
    printf("%lld\n", f(n) % MOD);
}