#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

n = input()
n = bin(n)[2:]

def func(dig, val1, val2):
    for i in range(dig):
        v1 = val1 * 2 + val2
        v2 = val2 * 2 + val1
        val1, val2 = v1, v2
    return val2

ans = 0
val1 = 0
val2 = 1
for i in range(len(n)):
    if n[i] == '1':
        ans += func(len(n) - i - 1, val1, val1 + val2)
        val1 = val1 + val2
    else:
        val2 = val1 + val2
print (ans + val2) % (10 ** 9 + 7)