import os, sys; sys.setrecursionlimit(10**7) readline = sys.stdin.readline # from collections import defaultdict, deque, Counter # from heapq import heapify, heappush, heappop # from itertools import accumulate, chain # from operator import add # from bisect import bisect_left, bisect_right, insort # import math # from decimal import Decimal # from random import randrange # from typing import * # import time mod = 10 ** 9 + 7 def popcount63(x): x = (x & 0x5555555555555555) + ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = x + (x >> 4) & 0xF0F0F0F0F0F0F0F x = x + (x >> 32) & 0xFFFFFFFF return ((x * 0x1010101) & 0xFFFFFFFF) >> 24 def main(): N = list(map(int, bin(int(readline()))[2:])) k = len(N) dp = [[0] * 60 for _ in range(k)] tmpn = 0 for i in range(k): tmpn <<= 1 tmpn += N[i] dp[i][popcount63(tmpn)] = tmpn n = tmpn dp2 = [[(0, 0)] * 60 for _ in range(k)] for i in range(k): dp2[i][0] = (1, 0) for i in range(1, k): for j in range(1, 60): p = dp2[i - 1][j - 1][0] + dp2[i - 1][j][0] q = 2 * dp2[i - 1][j - 1][1] + dp2[i - 1][j - 1][0] + 2 * dp2[i - 1][j][1] if N[i] and dp[i - 1][j]: p += 1 q += 2 * dp[i - 1][j] dp2[i][j] = (p % mod, q % mod) ans = popcount63(n) * n for d in range(60): ans += dp2[-1][d][1] * d ans %= mod print(ans) if __name__ == '__main__': main()