#include <stdio.h>
long long n,res,a=1;
int main()
{
for (scanf(“%I64d”,&n);a<n;res+=(n-1)/a*(a-(a>>1)),a<<=1ll);
printf(“%I64d\n”,res);
return 0;
}