n=gets.to_i;s=0;62.times{|j|s+=((3*(i=2**j)*i-i)/2+i*i*~-c=-~n/2/i)*c+(i<-~n%(2*i)?(m=-~n%(2*i)-i)*~-m/2+m*(2*i*c+i):0)};p s.%10**9+7