#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  n--;
  long long ans = 0;
  for (long long i = 1; i <= n; i <<= 1) {
    ans += (((n - i) / (2 * i)) + 1) * i;
  }
  cout << ans << "\n";
  return 0;
}
