#include<bits/stdc++.h>
#define N 1000005
typedef long long LL;
const int mod=998244353;
using namespace std;
LL n;
LL ans=1;
int main(){
ios::sync_with_stdio(0);
cin.tie();cout.tie();
cin>>n;
if(n==1) cout<<ans<<endl;
for(int i=1;i<=64;i++){
if(n>(1LL<<i)){
ans+=(1LL<<(i-1)%mod)*(i+1)%mod;
ans%=mod;
}else{
ans+=(n-(1LL<<(i-1)))%mod*(i+1)%mod;
ans%=mod;
break;
}
}
cout<<ans<<endl;
return 0;
}