#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, ans = 0, p = (long long int)1;
  cin >> n;
  for (int i = 0; i < 41; i++) {
    ans += (n / 2) * p;
    n = (n + 1) / 2;
    p *= (long long int)2;
  }
  cout << ans;
}
