#include<vector>
#include<iostream>
#define ll long long
using namespace std;
ll getnextBit(ll n){
ll m = 0;
while (n > 1) {
n = n >> 1;
m+=1;
}
return m;
}
ll getmostBit(ll n, ll m){
ll tmp = 1 << m;
while (n < tmp) {
tmp = tmp >> 1;
--m;
}
return m;
}
ll func(ll n){
if (n == 0)
return 0;
ll m = getnextBit(n);
ll m = getmostBit(n, m);
if (n == (1LL << (m + 1)) - 1)
return (m + 1) * (1 << m);
n = n - (1LL << m);
return (n + 1) + func(n) + m * (1LL << (m - 1));
}
int main(){
int n;
cin >> n;
cout<<func(n)<<endl;
}