#include using namespace std; using int64 = long long; const int mod = 1e9 + 7; const int inv2 = 5e8 + 4; int64 sum(int64 a, int64 d, int64 n) { a %= mod; d %= mod; n %= mod; return n * (2 * a % mod + (n + mod - 1) % mod * d % mod) % mod * inv2 % mod; } int main() { int64 N; cin >> N; int64 ret = 0; for(int64 k = 1; k <= N; k <<= 1) { int64 sum1 = sum(k, 1, k); int64 length = (N + 1) / (2 * k); ret += sum(sum1, k % mod * (2 * k % mod) % mod, length); ret %= mod; int64 out = (N + 1) % (2 * k) - k; if(out > 0) { int64 pos = (N + 1) / (2 * k) * (2 * k) + k; ret += sum(pos, 1, out); ret %= mod; } } cout << ret << endl; }