#include using namespace std; #include using mint = atcoder::modint1000000007; int main(){ int64_t N; cin >> N; array,2>,63>,63> dp; //popcountの値ごとのN以下の非負整数の{総和,個数} for(auto &a : dp) for(auto &b : a) for(auto &c : b) c = {0, 0}; dp[61][0][1] = {0, 1}; for(int64_t b = 60; b >= 0; b--){ for(int64_t pop_prev = 0; pop_prev <= 60; pop_prev++){ for(int64_t str_prev = 0; str_prev <= 1; str_prev++){ for(int64_t pop = 0; pop <= 1; pop++){ if(pop == 0){ dp[b][pop_prev][str_prev and (N&1LL< 0].first += dp[b+1][pop_prev][str_prev].first * 2 + dp[b+1][pop_prev][str_prev].second; dp[b][pop_prev+1][str_prev and (N&1LL< 0].second += dp[b+1][pop_prev][str_prev].second; } } } } } mint res = 0; for(int64_t p = 0; p <= 60; p++){ res += (dp[0][p][0].first + dp[0][p][1].first) * p; } cout << res.val() << '\n'; }