#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int maxn = 100050;
long long f(long long n) {
  if (n == 1) return 1;
  return (n + 1) / 2 + 2 * f(n / 2);
}
int main(int argc, char const *argv[]) {
  long long n;
  cin >> n;
  cout << f(n - 1) << endl;
  return 0;
}
