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