#include #include typedef long long int int64; #define POS(i,j) ((i)*f+(j)) void run(void){ int64 n; scanf("%lld",&n); const int mod=1000000007; const int f=61; int64 *dp=(int64 *)calloc(2*f,sizeof(int64)); int64 *cnt=(int64 *)calloc(2*f,sizeof(int64)); int64 sup=0; int now=0; int i; for(i=f-2;i>=0;i--){ int next=now^1; for(int j=f-1;j>0;j--){ dp[POS(next,j)]=(2*dp[POS(now,j)]+2*dp[POS(now,j-1)]+cnt[POS(now,j-1)])%mod; cnt[POS(next,j)]=(cnt[POS(now,j)]+cnt[POS(now,j-1)])%mod; } cnt[POS(next,0)]=cnt[POS(now,0)]; if((n>>i)&1){ dp[POS(next,sup)]=(dp[POS(next,sup)]+((n-(1LL<>i))%mod; cnt[POS(next,sup)]=(cnt[POS(next,sup)]+1)%mod; sup++; } now=next; } int64 ans=0; for(i=1;i