#include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int P = 1000000007; int main() { ll n; cin >> n; n++; ll r = 0, c = 0, a = 0; for (int k = 60; k >= 0; k--) { ll m = 1LL << k; if (n & m) { ll t = m / 2; ll s = (m + P - 1) % P; r += (t % P + t / 2 % P * (k - 1) % P) % P * s % P; r += a * (m % P) % P * c % P; r += a * (t % P) % P * k % P; r += c * s % P * (t % P) % P; c++; a += m; a %= P; r %= P; } } cout << r << endl; return 0; }