#include<cstdio>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
#define int long long 
const int mod=1e9+7;
map<int,int>d;
inline int read() 
{
    char ch=getchar();
    int x=0,q=1;
    while(ch>'9' || ch<'0')q=ch==45?-1:q,ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
    return x*q;
}
inline int solve(int x)
{
	if(d[x])
		return d[x];
	else
	return d[x]=((solve(x/2)+solve((x-1)/2)+solve((x-2)/2)))%mod;
}
signed main()
{
	//初始条件
	d[0]=1;//a=b=0一组 
	d[1]=2; //a=b=0一组 ，a=b=1第二组； 
	int n;
	n=read(); 
	int ans=solve(n);
	printf("%lld\n",ans);
	return 0;
}
