You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.

Constraints

* 1≦N≦10^{18}

Input

The input is given from Standard Input in the following format:


N


Output

Print the number of the possible pairs of integers u and v, modulo 10^9+7.

Examples

Input

3


Output

5


Input

1422


Output

52277


Input

1000000000000000000


Output

787014179
tg = 0
ls = 1
md = 2
MOD = 10**9+7
n = int(input())
l = n.bit_length()
# ^tight/loose, +tight/loose/middle, bitnum
dp = [[[0] * l for _ in range(3)] for i in range(2)]
for i in range(l):
    if i == 0:
        # 10
        dp[tg][tg][0] = 1
        # 00
        dp[ls][md][0] = 1
        continue
    # i-th bit is 1
    if n & (1 << l - i - 1):
        # 10
        dp[tg][tg][i] += dp[tg][tg][i-1]
        dp[ls][ls][i] += dp[ls][md][i-1]
        dp[ls][tg][i] += dp[ls][tg][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
        # 00
        dp[ls][md][i] += dp[tg][tg][i-1]
        dp[ls][ls][i] += dp[ls][md][i-1]
        dp[ls][md][i] += dp[ls][tg][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
        # 11 
        dp[ls][md][i] += dp[ls][md][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
    # i-th bit is 0
    else:
        # 10
        dp[ls][ls][i] += dp[ls][ls][i-1]
        dp[ls][md][i] += dp[ls][md][i-1]
        # 00
        dp[tg][tg][i] += dp[tg][tg][i-1]
        dp[ls][ls][i] += dp[ls][md][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
        dp[ls][tg][i] += dp[ls][tg][i-1]
        # 11 
        dp[ls][tg][i] += dp[ls][md][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
    for xp in dp:
        for pp in xp:
            pp[i] %= MOD

ans = 0
for xp in dp:
    for pp in xp:
        ans += pp[-1]
        ans %= MOD
print(ans)