#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, ans = 0, z = 1;
  cin >> n;
  while (n != 0) {
    ans += n / 2 * z;
    if (n % 2 == 1 && n != 1) {
      n++;
    }
    n = n / 2;
    z = 2 * z;
  }
  cout << ans;
}
