// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

ll read() {
	ll X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int mod=1e9+7;

map<ll,int> f;

int calc(ll n) {
	if (f.count(n)) return f[n];
	return f[n]=((calc(n/2)+calc((n-1)/2))%mod+calc((n-2)/2))%mod;
}

int main() {
	f[0]=1,f[1]=2;
	printf("%d\n",calc(read()));
	return 0;
}