#include using namespace std; constexpr long long mod = 1e9+7; constexpr long long inv2 = 5e8+4; int main(){ long long N; cin >> N; long long ans = 0; long long b = 1LL; while (N >= b){ long long bm = b % mod; long long q = (N + 1LL) / b; long long r = (N + 1LL) % b; long long p = q / 2; long long pm = p % mod; long long qm = q % mod; long long rm = r % mod; long long bp = bm * pm % mod; long long inc = bp * bp % mod; ans = (ans + inc) % mod; inc = (bm + mod - 1LL) % mod; inc = inc * bm % mod; inc = inc * inv2 % mod; inc = inc * pm % mod; ans = (ans + inc) % mod; if (q % 2LL == 1LL){ inc = (bm * qm) % mod; inc = (inc * rm) % mod; ans = (ans + inc) % mod; inc = ((rm * (rm + mod - 1LL)) % mod * inv2) % mod; ans = (ans + inc) % mod; } b *= 2LL; } cout << ans << endl; return 0; }