#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  long long x = 1;
  cin >> N;
  long long ans = 0;
  while (N > 1) {
    ans += (N / 2) * x;
    N -= N / 2;
    x *= 2;
  }
  cout << ans << endl;
}
