#include <bits/stdc++.h>
using namespace std;
void tc() {
  long long n, ans = 0;
  cin >> n;
  for (long long i = 1; i <= n; i *= 2) {
    ans += (n + i - 1) / (i * 2) * i;
  }
  cout << ans << '\n';
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;
  while (t--) tc();
  return 0;
}
