#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int main(void) {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long at = 1, res = 0;
  while (n > 1LL) {
    res += (n >> 1) * at;
    n = (n + 1LL) >> 1;
    at <<= 1;
  }
  cout << res << endl;
  return 0;
}
