#include #define int long long using namespace std; int mod = 1000000007; int inv2 = 500000004; int g[60]; //popcount(0)~popcount(2^n - 1)の和 int f[60]; //V(0)~V(2^n - 1)の和。ただしV(i) = i * popcount(i) //l + … + r - 1 int wa(int l, int r) { int n = r - l; n %= mod; l %= mod; return (n * (n - 1) % mod * inv2 + l * n % mod) % mod; } signed main() { int i; g[0] = 0; for (i = 1; i < 60; i++) { g[i] = 2 * g[i - 1] + (1LL << (i - 1)) % mod; g[i] %= mod; } f[0] = 0; for (i = 1; i < 60; i++) { f[i] = 2 * f[i - 1] + (1LL << (i - 1)) % mod * g[i - 1] + wa(1LL << (i - 1), 1LL << i); f[i] %= mod; } int n; cin >> n; n++; int l = 0, cnt = 0; int ans = 0; for (i = 59; i >= 0; i--) { if ((n >> i) & 1) { ans += f[i] + l % mod * g[i] + cnt * wa(l, l + (1LL << i)); ans %= mod; cnt++; l += (1LL << i); } } cout << ans << endl; return 0; }