n=gets.to_i;s=0;62.times{|j|s+=((3*(i=2**j)*i-i)/2+i*i*~-c=-~n/2/i)*c+[(4*i*c+i*2+~-m=-~n%(2*i)-i)*m/2,0].max};p s.%10**9+7