//================================= // Created on: 2018/09/28 22:51:11 //================================= #include using ll = long long; constexpr ll MOD = 1000000007LL; constexpr ll HALF = (MOD + 1) / 2; int main() { ll N; std::cin >> N; ll d = 1; ll ans = 0; for (; d <= N; d *= 2) { const ll step = d * 2; const ll num = (N + 1) / step; ll sum = 0; if (num >= 1) { const ll STEP = (d % MOD) * (step % MOD) % MOD; const ll S = (((3 * d - 1) % MOD) * (d % MOD) % MOD) * HALF % MOD; const ll T = (S + (num - 1) * STEP % MOD) % MOD; sum = ((S + T) * num % MOD) * HALF % MOD; const ll A = step * num + d; if (A <= N) { (sum += (((A + N) % MOD) * ((N - A + 1) % MOD) % MOD) * HALF % MOD) %= MOD; } } else { sum = (((N + d) % MOD) * ((N - d + 1) % MOD) % MOD) * HALF % MOD; } (ans += sum) %= MOD; } std::cout << ans << std::endl; return 0; }