#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, coe = 1, res = 0;
  cin >> n;
  --n;
  do {
    res += (n + 1) / 2 * coe;
    n >>= 1;
    coe <<= 1;
  } while (n);
  return cout << res, 0;
}
