// includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // macros #define ll long long int #define pb emplace_back #define mk make_pair #define pq priority_queue #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using namespace std; // types typedef pair P; typedef pair Pl; typedef pair Pll; typedef pair Pd; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1e9 + 7; // solve template bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;} template bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;} ll dp[61][61][2], num[61][61][2]; int main(int argc, char const* argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); ll n, N; cin >> n; N = n; vector vec, sum; while(n){ vec.pb(n % 2); n /= 2; } reverse(all(vec)); for(int i = 0; i < sz(vec); i++){ //cout << vec[i] << "\n "[i + 1 != sz(vec)]; sum.pb((i > 0 ? sum[i-1]: 0) + vec[i]); } //cout << N << endl; dp[0][1][1] = 1, num[0][1][1] = 1; dp[0][0][0] = 0, num[0][0][0] = 1; for(int i = 1; i < sz(vec); i++){ dp[i][0][0] = 0; num[i][0][0] = 1; //cout << i << " " << 0 << " " << dp[i][0][1] << endl; for(int j = 1; j <= i + 1; j++){ dp[i][j][0] = (2 * dp[i-1][j-1][0] % mod + 2 * dp[i-1][j][0] % mod + num[i-1][j-1][0]) % mod; num[i][j][0] = (num[i-1][j-1][0] + num[i-1][j][0]) % mod; if(vec[i] == 1){ dp[i][j][0] = (dp[i][j][0] + 2 * dp[i-1][j][1] % mod) % mod; num[i][j][0] = (num[i][j][0] + num[i-1][j][1]) % mod; } if(sum[i] == j){ dp[i][j][1] = (N >> (sz(vec) - i - 1)) % mod; num[i][j][1] = 1; }else{ dp[i][j][1] = 0; num[i][j][1] = 0; } //cout << i << " " << j << " " << dp[i][j][1] << endl; } } ll res = 0; for(int i = 1; i <= sz(vec); i++){ res = (res + (ll)i * dp[sz(vec)-1][i][0] % mod) % mod; res = (res + (ll)i * dp[sz(vec)-1][i][1] % mod) % mod; } //res = (res + __builtin_popcount(N) * (N % mod) % mod) % mod; cout << res << endl; return 0; }