// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}


typedef int Num;
const Num mod = 1000000007;

//{{{ operation
inline Num prod(const Num &a, const Num &b, const Num m = mod){
	Num c = (a*(long long)b)%m;
//	assert(0<=c and c<m);
	return c;
}
inline void mult(Num &a, const Num &b, const Num m = mod){
	a = prod(a,b,m);
}
inline Num sum(const Num &a, const Num &b, const Num m = mod){
	Num c=a+b;
	if(c>=m)c-=m;
//	assert(0<=c and c<m);
	return c;
}
inline Num add(Num &a, const Num &b, const Num m = mod){
	a = sum(a,b,m);
}
inline Num neg(const Num &a, const Num m = mod){
	if(a==0)return 0;
	else return m-a;
}
inline Num vbit(const Num &a, const Num &b, const Num m = mod){
	Num c=a-b;
	if(c<0)c+=m;
	return c;
}
inline Num subt(Num &a, const Num &b, const Num m = mod){
	a -= b;
	if(a<0)a+=m;
}
/*
inline Num inv(const Num &a, const Num m = mod){
	return invMod(a,m);
}
inline Num quot(const Num &a, const Num &b, const Num m = mod){
	return prod(a,inv(b,m),m);
}
inline void divide(Num &a, const Num &b, const Num m = mod){
	a = prod(a,inv(b,m),m);
}
*/
//}}}

uInt N;

int dp[2][2][2][100];//

int calc(int bound,int carry_to, int carry_from ,int t){
	int &r = dp[bound][carry_to][carry_from][t];
	if(r>=0)return r;
	uInt N2;
	if(bound) N2 = (N&((1ull<<t)-1));
	else N2 = (1ull<<t)-1;
	if(t==0){
		if(carry_from or carry_to)return r=0;
		else return r=1;
	}
	int ans=0;
	int head_bit = (N2&(1ull<<(t-1)))?1:0;
	for(int d=0;d<=2;d++){
		int e = d;
		if(carry_from)e++;
		if(carry_to)e-=2;
		if(e<0 or 2<e)continue;
		if(e==head_bit){
			add(ans,calc(bound,carry_from,0,t-1));
			add(ans,calc(bound,carry_from,1,t-1));
		}
		if(e<head_bit){
			add(ans,calc(0,carry_from,0,t-1));
			add(ans,calc(0,carry_from,1,t-1));
		}
	}
	return r = ans;
}

int main(){
	cin>>N;
	memset(dp,-1,sizeof(dp));
	int ans = 0;
	add(ans,calc(1,0,0,60));
	add(ans,calc(1,0,1,60));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256