from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) N = int(input()) L = N.bit_length() d2 = [pow(2,i,mod) for i in range(300)] ans = 0 for i in range(L): n = N//d2[i+1] a = (d2[i]+d2[i+1]-1)*d2[i]//2 d = d2[2*i+1] tmp1 = n*(2*a+(n-1)*d)//2 MIN = d2[i+1]*(n+1)-d2[i] MAX = min(N,MIN+d2[i]) tmp2 = (MIN+MAX)*(MAX-MIN+1)//2 ans += tmp1+tmp2 ans %= mod print(ans%mod)