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)