#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long ans = 0;
  long long now = 1;
  while (n > 1) {
    ans = ans + now * (n / 2);
    n = n / 2 + n % 2;
    now = now * 2;
  }
  printf("%lld\n", ans);
}
