#include <cstdio>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll mod = 1000000007;

ll N;
std::map<P, ll> dp;

ll f( ll S, ll X )
{
  if( dp.count( P( S, X ) ) )
    return dp[P( S, X )];

  ll &ret = dp[P( S, X )];

  // S = 0, X = 0; (1) S = 1, X = 1 (1), S = 2, X = 0 (1)

  if( S == 1 && X == 1 )
    return ret = 2;
  else if( !S || !X )
    return ret = 1;

  return ret = ( ( (S >= 2 && X >= 0 ? f( (S-2)/2, X/2 ) : 0) + (S >= 1 && X >= 1 ? f( (S-1)/2, (X-1)/2 ) : 0) ) % mod + ( S >= 0 && X >= 0 ? f( S/2, X/2 ) : 0 ) ) % mod;
}

int main()
{
  scanf( "%lld", &N );

  printf( "%lld\n", f( N, N ) );
  
  return 0;
}