N = int(input())

ans = 0
for i in range(N):
    tmp = 1
    b = 1
    while b <= i:
        if i & b > 0:
            tmp <<= 1
        b <<= 1
    tmp >>= 1
    ans = (ans + tmp) % 10000000007

print(ans)
