#include<iostream>
#include<cstdio>
#include<cmath>

const int p=10e9+7;

using namespace std;
int S(int n)
{
	if(n==0)return 1;
	if(n==1)return 2;
	else return (S(n/2)+S((n-1)/2)+S((n-2)/2))%p;	
}

int main()
{
	int n;
	scanf("%d",&n);
	printf("%d",S(n));
	return 0;
	
} 