#include #include #include #include using namespace std; using i64 = int64_t; constexpr int mod = static_cast(powl(10, 9)) + 7; vector p2; string to_bin(const i64 a) { if(a == 0) { return "0"; } string s = bitset<64>(a).to_string(); int p = static_cast(s.find('1')); return s.substr(p); } i64 f(i64 x) { string s = to_bin(x); int n = static_cast(s.size()); vector> dp(3, vector(n+1, 0)); vector> dq(3, vector(n+1, 0)); dp[1][0] = 1; for(int i=n-1; i>=0; --i) { vector> ndp(3, vector(n+1, 0)); vector> ndq(3, vector(n+1, 0)); for(int flag=0; flag<3; ++flag) { for(int cnt1=0; cnt1 s[i] - '0') { dflag = 2; } int nflag = flag * dflag; if(nflag >= 2) { nflag = 2; } if(flag == 0 && dflag == 2) { nflag = 2; } int ncnt1 = cnt1 + (d == 1); ndp[nflag][ncnt1] += dp[flag][cnt1]; ndp[nflag][ncnt1] %= mod; ndq[nflag][ncnt1] += dq[flag][cnt1] + dp[flag][cnt1] * d * p2[n-1-i]; ndq[nflag][ncnt1] %= mod; } } } dp = ndp; dq = ndq; } i64 res = 0; for(int flag=0; flag<2; ++flag) { for(int cnt1=1; cnt1<=n; ++cnt1) { res += dq[flag][cnt1] * cnt1; res %= mod; } } return res; } int main(void) { p2.resize(110); p2[0] = 1; for(int i=0; i<105; ++i) { p2[i+1] = p2[i] * 2 % mod; } i64 n; scanf("%ld", &n); i64 res = f(n); printf("%ld\n", res); return 0; }