N = int(eval(input()))

dp = [[0] * 3 for i in range(100)]



MOD = int(1e9+7)

maxBit = 70

while not (N >> maxBit):

    maxBit -= 1



dp[maxBit][0] = 1

dp[maxBit][1] = 1

for i in range(maxBit-1, -1, -1):

    for j in range(3):

        bit = (N >> i) & 1

        for k in range(3):

            nj = 2 * j + bit - k

            if nj < 0:

                continue

            nj = min((nj, 2))

            dp[i][nj] += dp[i+1][j]

            dp[i][nj] %= MOD



print((sum(dp[0]) % MOD))

N = int(eval(input()))

s = bin(N)[2:]

n = len(s)

dp = [[0] * 4 for i in range(len(s)+1)]

dp[0][0] = 1

MOD = int(1e9) + 7

for i in range(n):

    b = 1 if s[i] == '1' else 0

    for j in range(4):

        for k in range(3):

            nj = min(((j << 1) + b - k, 3))

            if 0 <= nj:

                dp[i+1][nj] += dp[i][j]

                dp[i+1][nj] %= MOD

print((sum(dp[n]) % MOD))

N = int(eval(input()))
dp = [[0] * 3 for i in range(100)]
MOD = int(1e9 + 7)
maxBit = 70
while not (N >> maxBit):
    maxBit -= 1
dp[maxBit][0] = 1
dp[maxBit][1] = 1
for i in range(maxBit - 1, -1, -1):
    for j in range(3):
        bit = (N >> i) & 1
        for k in range(3):
            nj = 2 * j + bit - k
            if nj < 0:
                continue
            nj = min((nj, 2))
            dp[i][nj] += dp[i + 1][j]
            dp[i][nj] %= MOD
print((sum(dp[0]) % MOD))

N = int(eval(input()))
s = bin(N)[2:]
n = len(s)
dp = [[0] * 4 for i in range(len(s) + 1)]
dp[0][0] = 1
MOD = int(1e9) + 7
for i in range(n):
    b = 1 if s[i] == "1" else 0
    for j in range(4):
        for k in range(3):
            nj = min(((j << 1) + b - k, 3))
            if 0 <= nj:
                dp[i + 1][nj] += dp[i][j]
                dp[i + 1][nj] %= MOD
print((sum(dp[n]) % MOD))

-dp = [[0] * 3 for i in range(100)] -MOD = int(1e9 + 7) -maxBit = 70 -while not (N >> maxBit): -    maxBit -= 1 -dp[maxBit][0] = 1 -dp[maxBit][1] = 1 -for i in range(maxBit - 1, -1, -1): -    for j in range(3): -        bit = (N >> i) & 1 +s = bin(N)[2:] +n = len(s) +dp = [[0] * 4 for i in range(len(s) + 1)] +dp[0][0] = 1 +MOD = int(1e9) + 7 +for i in range(n): +    b = 1 if s[i] == "1" else 0 +    for j in range(4): -            nj = 2 * j + bit - k -            if nj < 0: -                continue -            nj = min((nj, 2)) -            dp[i][nj] += dp[i + 1][j] -            dp[i][nj] %= MOD -print((sum(dp[0]) % MOD)) +            nj = min(((j << 1) + b - k, 3)) +            if 0 <= nj: +                dp[i + 1][nj] += dp[i][j] +                dp[i + 1][nj] %= MOD +print((sum(dp[n]) % MOD))