#include <iostream>
#include <cstring>

using namespace std;

const int MOD = 1000000007;

long long N;
long long dp[61][3];

long long search(int digit = 60, int prevDif = 0){
	if(prevDif < 0) return 0;
	if(digit < 0) return 1;
	if(dp[digit][prevDif] >= 0) return dp[digit][prevDif];
	long long res = 0;
	for(int add=0;add<=2;add++){
		int newDif = min<int>(2, 2 * prevDif + (N>>digit)%2 - add);
		res = (res + search(digit-1, newDif)) % MOD;
	}
	return dp[digit][prevDif] = res;
}

int main(){
	while(cin >> N){
		memset(dp, -1, sizeof(dp));
		cout << search() << endl;
	}
}
