#include #include typedef long long ll; ll MOD = 1000000007; int main(){ ll N; scanf("%lld",&N); int keta = 1; ll pow2 = 2; while(pow2 < N){ keta++; pow2 *= 2; } ll ans = 0; for(int n = 1; n <= keta; n++){ ll k = 1; for(int j = 1; j < n; j++) k *= 2LL; ll origK = k; ll x = N/(2LL*origK); k %= MOD; ll k2 = k*k; k2 %= MOD; ll tmp = ((3*k2-k)/2+k2*(x-1)); tmp %= MOD; ans += x* tmp; ans %= MOD; if(N >= 2*origK*x+origK){ ll tmp1 = ((2*k*x+k)+(N)); if(tmp1 % 2 == 0) tmp1 /= 2; tmp1 %= MOD; ll tmp2 = (N-(2*k*x+k)+1); if(tmp2 % 2 == 0) tmp2 /= 2; tmp2 %= MOD; ans += tmp1*tmp2; } ans %= MOD; //printf("k = %lld, x = %lld, ans = %lld\n",k,x,ans); } printf("%lld\n",ans); }