#include <bits/stdc++.h>
using namespace std;
long long N, ans;
int main() {
  cin >> N;
  for (int i = 0; i < 40; i++) {
    long long cur = (1LL << i);
    ans += (((N - 1 + cur) / (2 * cur)) * (cur));
  }
  cout << ans << endl;
}
