import sys readline=sys.stdin.readline def Pop_Count(N): r=(N&0x5555555555555555)+((N>>1)&0x5555555555555555) r=(r&0x3333333333333333)+((r>>2)&0x3333333333333333) r=(r&0x0f0f0f0f0f0f0f0f)+((r>>4)&0x0f0f0f0f0f0f0f0f) r=(r&0x00ff00ff00ff00ff)+((r>>8)&0x00ff00ff00ff00ff) r=(r&0x0000ffff0000ffff)+((r>>16)&0x0000ffff0000ffff) r=(r&0x00000000ffffffff)+((r>>32)&0x00000000ffffffff) return r mod=10**9+7 def solve(N): if N==0: return 0,0 if N%2: a,b=solve(N-1) p=Pop_Count(N-1) a+=(N-1)*p b+=p return a%mod,b%mod a,b=solve(N//2) return (a*2+a*2+b+(N//2)**2)%mod,(b*2+N//2)%mod N=int(readline())+1 ans=solve(N)[0] print(ans)