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