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