#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long sum = 0;
  long long x = 1;
  while (n != 1) {
    sum += (n / 2ll) * x;
    n = (n + 1) / 2ll;
    x *= 2ll;
  }
  cout << sum << endl;
  return 0;
}
