#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;

LL a[21]= {1, 2, 4, 5, 8, 10, 13, 14, 18, 21, 26, 28, 33, 36, 40,
            41, 46, 50, 57, 60, 68, 73, 80, 82, 89, 94, 102, 105, 112, 116, 121,
            122, 128, 133, 142};
map<LL,LL> mp;
LL cal(LL x) {
    if(x<=20)
        return a[x];
    if(mp[x])
        return mp[x];
    if(x%2)
        return mp[x]=(2*cal(x/2)%MOD+cal(x/2-1)%MOD)%MOD;
    else
        return mp[x]=(2*cal(x/2-1)%MOD+cal(x/2)%MOD)%MOD;
}
int main() {
    LL n;
    scanf("%lld",&n);
    printf("%lld\n",cal(n));
    return 0;
}