#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MOD = 1000000007; int main() { long long n; cin >> n; ++ n; vector dp(1<<4, 0); dp[0] = 1; for(int i=63; i>=0; --i){ int z = (n >> i) & 1; vector nextDp(1<<4, 0); for(int a=0; a<(1<<4); ++a){ for(int x=0; x<2; ++x){ for(int y=0; y<2; ++y){ bitset<4> bs(a); if(!bs[0] && x > y) continue; else if(x < y) bs[0] = true; if(!bs[1] && y > z) continue; else if(y < z) bs[1] = true; if(!bs[2] && (x & y) > (x ^ y)) continue; else if((x & y) < (x ^ y)) bs[2] = true; if(!bs[3] && (x ^ y) > (x | y)) continue; else if((x ^ y) < (x | y)) bs[3] = true; nextDp[bs.to_ulong()] += dp[a]; nextDp[bs.to_ulong()] %= MOD; } } } dp = move(nextDp); } cout << dp.back() << endl; return 0; }