/*************************************************************************
	> File Name: m.cpp
	> Author: LiuGeXian
	> Mail: 1019630230@qq.com 
	> Created Time: 2020/5/11 7:08:09
 ************************************************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll n;
map<ll, ll> m;
ll Solve(ll x){
	if (m[x]) return m[x] % MOD;
	return m[x] = (Solve((x-1)/2) + Solve(x / 2) + Solve((x-2)/2)) % MOD;
}
int main(){
	scanf("%lld", &n);
	m[0] = 1;
	m[1] = 2;
	cout << Solve(n) << endl;
	return 0;
}
