// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
LL n , C[ 100 ][ 100 ];
void init(){
  n = getint();
  for( int i = 0 ; i < 100 ; i ++ )
    C[ i ][ 0 ] = C[ i ][ i ] = 1;
  for( int i = 2 ; i < 100 ; i ++ )
    for( int j = 1 ; j < i ; j ++ )
      C[ i ][ j ] = add( C[ i - 1 ][ j ] , C[ i - 1 ][ j - 1 ] );
}
LL bt[ 62 ] , ans , two[ 62 ] , st[ 62 ];
unordered_map< LL , LL > sv[ 62 ][ 2 ];
inline LL go( int now , LL sum , int bound ){
  if( sum > n ) return 0;
  if( now < 0 ){
    //ans = add( ans , 1 );
    return 1;
  }
  auto it = sv[ now ][ bound ].find( sum );
  if( it != sv[ now ][ bound ].end() )
    return it -> second;
  if( bt[ now ] || !bound ){
    LL ret = 0;
    LL wst = 0;
    if( now ) wst = st[ now - 1 ];
    if( sum + wst <= n ){
      //for( int j = 0 ; j <= now ; j ++ )
        //ans = add( ans , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
      for( int j = 0 ; j <= now ; j ++ )
        ret = add( ret , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
    }else
      ret = add( ret , go( now - 1 , sum , 0 ) );
    wst += two[ now + 1 ];
    if( sum + wst <= n ){
      //for( int j = 0 ; j <= now ; j ++ )
        //ans = add( ans , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
      for( int j = 0 ; j <= now ; j ++ )
        ret = add( ret , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
    }else
      ret = add( ret , go( now - 1 , sum + two[ now + 1 ] , 0 ) );
    if( bound ) ret = add( ret , go( now - 1 , sum + two[ now ] , 1 ) );
    else{
      wst = 0;
      if( now ) wst = st[ now - 1 ];
      wst += two[ now ];
      if( sum + wst <= n ){
        //for( int j = 0 ; j <= now ; j ++ )
          //ans = add( ans , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
        for( int j = 0 ; j <= now ; j ++ )
          ret = add( ret , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
      }else
        ret = add( ret , go( now - 1 , sum + two[ now ] , 0 ) );
    }
    return sv[ now ][ bound ][ sum ] = ret;
  }else{
    LL ret = 0;
    if( bound ){
      ret = add( ret , go( now - 1 , sum + two[ now + 1 ] , 1 ) );
      ret = add( ret , go( now - 1 , sum , 1 ) );
    }else{
      LL wst = 0;
      if( now ) wst = st[ now - 1 ];
      if( sum + wst <= n ){
        //for( int j = 0 ; j <= now ; j ++ )
          //ans = add( ans , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
        for( int j = 0 ; j <= now ; j ++ )
          ret = add( ret , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
      }else
        ret = add( ret , go( now - 1 , sum , 0 ) );
      wst += two[ now + 1 ];
      if( sum + wst <= n ){
        //for( int j = 0 ; j <= now ; j ++ )
          //ans = add( ans , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
        for( int j = 0 ; j <= now ; j ++ )
          ret = add( ret , mul( C[ now ][ j ] , two[ j ] % mod7 ) );
      }else
        ret = add( ret , go( now - 1 , sum + two[ now + 1 ] , 0 ) );
    }
    return sv[ now ][ bound ][ sum ] = ret;
  }
}
void solve(){
  LL xn = n , pt = 0;
  while( xn ){
    bt[ pt ++ ] = xn % 2;
    xn >>= 1;
  }
  two[ 0 ] = 1;
  for( int i = 1 ; i < 62 ; i ++ )
    two[ i ] = two[ i - 1 ] * 2ll;
  st[ 0 ] = two[ 1 ];
  for( int i = 1 ; i + 1 < 62 ; i ++ )
    st[ i ] = st[ i - 1 ] + two[ i + 1 ];
  ans = go( 60 , 0 , 1 );
  printf( "%lld\n" , ans );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 384