#include using namespace std; using ll = long long; template struct mod_int { static const int Mod = MOD; unsigned x; mod_int() : x(0) { } mod_int(int sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; } mod_int(long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; } int get() const { return (int)x; } mod_int &operator+=(mod_int that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } mod_int &operator-=(mod_int that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % MOD; return *this; } mod_int &operator/=(mod_int that) { return *this *= that.inverse(); } mod_int operator+(mod_int that) const { return mod_int(*this) += that; } mod_int operator-(mod_int that) const { return mod_int(*this) -= that; } mod_int operator*(mod_int that) const { return mod_int(*this) *= that; } mod_int operator/(mod_int that) const { return mod_int(*this) /= that; } mod_int inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return mod_int(u); } }; template istream& operator >> (istream& is, mod_int& val) { long long x; is >> x; val = x; return is; } template ostream& operator << (ostream& os, const mod_int& val) { os << val.get(); return os; } using mint = mod_int<1000000007>; mint digit_dp(ll n) { vector s; if (n == 0) s.push_back(0); while (n) s.push_back(n % 2), n /= 2; reverse(s.begin(), s.end()); n = s.size(); vector>> cnt(n + 1, vector>(2, vector(61))); vector>> dp(n + 1, vector>(2, vector(61))); cnt[0][0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { int lim = j ? 1 : s[i]; for (int d = 0; d <= lim; d++) { for (int k = 0; k <= 60; k++) { if (k + d <= 60) { cnt[i + 1][j || d < lim][k + d] += cnt[i][j][k]; dp[i + 1][j || d < lim][k + d] += dp[i][j][k] + cnt[i][j][k] * ((ll)d << (ll)(n - 1 - i)); } } } } } mint res = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j <= 60; j++) { res += dp[n][i][j] * j; } } return res; } int main() { ll N; cin >> N; cout << digit_dp(N) << endl; return 0; }