#include <bits/stdc++.h>

using namespace std ;

#define ll long long
const int mod = 1e9 + 7 ;

ll n ;
map< ll , ll > f ;

ll dp( ll x ) {
	if( f[ x ] ) return f[ x ] ;
	return f[ x ] = ( dp ( x >> 1 ) + dp( ( x - 1 ) >> 1 ) + dp( ( x - 2 ) >> 1 ) ) % mod; 
}

int main() {
	scanf( "%lld" , &n ) ;
	f[ 0 ] = 1 ; f[ 1 ] = 2 ;
	printf( "%lld\n" , dp( n ) ) ;
} 