#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% from functools import lru_cache # %% N = int(read()) MOD = 10**9 + 7 # %% @lru_cache(None) def f(N): """return (sum of x*popcount(x), sum of x, sum of popcount(x), sum of 1) for 0 <= x <= N""" if N <= 1: return N, N, N, N + 1 Sxp = 0 Sx = 0 Sp = 0 S1 = 0 # 2x a, b, c, d = f(N // 2) Sxp += 2 * a Sx += 2 * b Sp += c S1 += d # 2x+1 a, b, c, d = f((N - 1) // 2) Sxp += 2 * a + 2 * b + c + d Sx += 2 * b + d Sp += c + d S1 += d return Sxp, Sx, Sp, S1 # %% print(f(N)[0] % MOD)