#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,mod=1e9+7;
map<long long,long long> dp;
long long dfs(long long x)
{
	if (x<2) return x+1;
	if (dp[x]) return dp[x];
	return dp[x]=(dfs(x/2)+dfs((x-1)/2)+dfs((x-2)/2))%mod;
}
int main()
{
	cin>>n;
	cout<<dfs(n);
	return 0;
}