// see https://github.com/LumaKernel/vimfiles/tree/master/snippets/cp-cpp/temp.snip
/// --- .lumrc Template {{{ ///
// #define DEBUG
// #define assert(...)
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = tuple<ll, ll>;
using P3 = tuple<ll, ll, ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;

#define omajinai ios::sync_with_stdio(false),cin.tie(0)

#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define FORI(i,a,b) for(int i=int(a);i<=int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPI(i,n) FORI(i,0,n)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define RFORI(i,a,b) for(int i=int(b);i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPI(i,n) RFORI(i,0,n)

#define ALL(a) begin(a),end(a)
#define UNIQUE(a) (a).erase(unique(ALL(a)),(a).end())
#define PB push_back
#define EACH(i,c) REP(i,(c).size())
#define REACH(i,c) RREP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

#define BR cout<<"\n";

#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
#else
#define dump(...)
#endif

#define YES(x) cout<<((x)?"YES":"NO")<<"\n";
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n";
#define yes(x) cout<<((x)?"yes":"no")<<"\n";

int __int_temp; ll __ll_temp; string __string_temp;
#define oini (omajinai, cin>>__int_temp, __int_temp)
#define oinl (omajinai, cin>>__ll_temp, __ll_temp)
#define oins (omajinai, cin>>__string_temp, __string_temp)
#define ini (cin>>__int_temp, __int_temp)
#define inl (cin>>__ll_temp, __ll_temp)
#define ins (cin>>__string_temp, __string_temp)

#define isInside(y,x) (0<=(y)&&(y)<h&&0<=(x)&&(x)<w)

#define fi(x) (get<0>(x))
#define se(x) (get<1>(x))
#define th(x) (get<2>(x))
#define fo(x) (get<3>(x))
#define fif(x) (get<4>(x))

template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; EACH(i, v) o << v[i] << (i != (int)v.size()-1 ? ", " : ""); o << "}";  return o; }

template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }

template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; }

template<typename T> inline int intlog2(T x);
template<> inline int intlog2(int x) { return x == 0 ? 0 : 32 - __builtin_clz(x); }
template<> inline int intlog2(ll x) { return x == 0 ? 0 : 64 - __builtin_clzll(x); }

constexpr double PI = acos(-1);

/// }}}--- ///

constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr int MOD = 1e9+7;

/// --- MOD Library {{{ ///

int modadd(int a, int b) { return (((a + b) % MOD ) + MOD ) % MOD; }
void sadd(int &a, int b) { a = modadd(a, b); }
int modmul(int a, int b) { return (ll) a * b % MOD; }
void smul(int &a, int b) { a = modmul(a, b); }
int modpow(int a, ll b) {
  int res = 1;
  while(b){
    if(b & 1) smul(res, a);
    smul(a, a);
    b>>=1;
  }
  return res;
}
int inv(int a) {
  return modpow(a, MOD - 2);
}

/// }}}--- ///

int solve2(ll n) {
  map<P, int> dp2;
  dp2[P(0, 0)] = 1;
  // when
  // a + b <= s
  // a ^ b <= t
  //
  // a_i >= b_i
  function<ll(ll, ll, ll, ll)> f = [&](ll s, ll t, ll x, ll y) -> ll {
    if(x<0 || y<0) return 0;
    if(dp2.count(P(s, t))) return dp2[P(s, t)];
    return
      dp2[P(s, t)] =
      ((ll)
       f(s >> 1, t >> 1, 0, 0) +
       f((s-1) >> 1, (t-1) >> 1, s-1, t-1) +
       f((s-2) >> 1, t >> 1, s-2, 0)) % MOD;
  };
  return f(n, n, 0, 0);
}

int dp[66][3];

int main() {
  ll n=inl;
  int h=intlog2(n);
  dp[h][0] = dp[h][1] = 1;

  RFORI(i, 2, h) {
    if(n & (1LL << (i - 2))) {
      sadd(dp[i-1][0], dp[i][0]);
      sadd(dp[i-1][1], dp[i][0]);
      sadd(dp[i-1][1], dp[i][1]);
      sadd(dp[i-1][2], dp[i][1]);
      sadd(dp[i-1][2], dp[i][1]);
      sadd(dp[i-1][2], dp[i][2]);
      sadd(dp[i-1][2], dp[i][2]);
      sadd(dp[i-1][2], dp[i][2]);
    } else { 
      sadd(dp[i-1][0], dp[i][0]);
      sadd(dp[i-1][0], dp[i][1]);
      sadd(dp[i-1][1], dp[i][1]);
      sadd(dp[i-1][2], dp[i][1]);
      sadd(dp[i-1][2], dp[i][2]);
      sadd(dp[i-1][2], dp[i][2]);
      sadd(dp[i-1][2], dp[i][2]);
    }
  }
  int ans = 0;
  REP(j, 3) sadd(ans, dp[1][j]);
  dump(ans , solve2(n));
  assert(ans == solve2(n));
  cout << ans << endl;
}


Measured memory_bytes: 256