#include <bits/stdc++.h>
using namespace std;
long long solve(long long n) {
  if (n == 1) return 0;
  return (n / 2) + 2 * solve((n + 1) / 2);
}
int main() {
  long long n;
  cin >> n;
  cout << solve(n) << endl;
  return 0;
}
