#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  n -= 1;
  long long ans = 0;
  for (int i = 0; i < 64 && (1ll << i) <= n; i++)
    ans += (n / (1ll << (i + 1)) +
            (n / (1ll << (i + 1)) * (1ll << (i + 1)) + (1ll << i) <= n)) *
           (1ll << i);
  cout << ans << endl;
  return 0;
}
