#include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; template struct modint{ ll val; modint(): val(0){} template explicit modint(T t){val = t%M; if(val < 0) val += M;} modint pow(ll k){ modint res(1), x(val); while(k){ if(k&1) res *= x; x *= x; k >>= 1; } return res; } template modint& operator=(T a){ val = a%M; if(val < 0) val += M; return *this; } modint inv() {return pow(M-2);} modint& operator+=(modint a){ val += a.val; if(val >= M) val -= M; return *this;} modint& operator-=(modint a){ val += M-a.val; if(val >= M) val -= M; return *this;} modint& operator*=(modint a){ val = 1LL*val*a.val%M; return *this;} modint& operator/=(modint a){ return (*this) *= a.inv();} modint operator+(modint a) const {return modint(val) +=a;} modint operator-(modint a) const {return modint(val) -=a;} modint operator*(modint a) const {return modint(val) *=a;} modint operator/(modint a) const {return modint(val) /=a;} modint operator-(){ return modint(-val);} bool operator==(const modint a) const {return val == a.val;} bool operator!=(const modint a) const {return val != a.val;} bool operator<(const modint a) const {return val < a.val;} }; using mint = modint; template vector make_v(U size, const T& init){ return vector(static_cast(size), init); } template auto make_v(U size, Ts... rest) { return vector(static_cast(size), make_v(rest...)); } template void chmin(T &a, const T &b){ a = (a < b ? a : b); } template void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { ll n; cin >> n; string s; while(n){ s += char('0' + (n&1)); n /= 2; } reverse(s.begin(),s.end()); n = s.size(); auto dp = make_v(n+1, n+1, 2, make_pair(mint(0), mint(0))); dp[0][0][0] = make_pair(mint(0), mint(1)); for (int i = 0; i < n; ++i) { for (int j = 0; j <= i; ++j) { for (int k = 0; k < 2; ++k) { int d = k ? 1 : s[i]-'0'; auto from = dp[i][j][k]; for (int l = 0; l <= d; ++l) { auto to = dp[i+1][j+l][k | (l < d)]; dp[i+1][j+l][k | (l < d)] = {to.first + from.first*mint(2)+from.second*mint(l), to.second + from.second}; } } } } mint ans; for (int i = 1; i <= n; ++i) { for (int j = 0; j < 2; ++j) { ans += dp.back()[i][j].first*mint(i); } } cout << ans.val << "\n"; return 0; }