import sys
from collections import Counter
readline = sys.stdin.readline
MOD = 10**9+7
N = int(readline())

CC = Counter()
CC[0] = 1
CC[1] = 2
def calc(x):
    res = 0
    if CC[x]:
        res = CC[x]
    elif x == 1:
        res = 2
    elif x%2 == 0:
        res = 2*calc(x//2-1) + calc(x//2)
    else:
        res = 2*calc(x//2) + calc(x//2-1)
    CC[x] = res%MOD
    return res%MOD
print(calc(N))