#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long arr[45];
  arr[0] = 0;
  for (long long i = 1; i < 45; i++) arr[i] = 2 * arr[i - 1] + (1LL << (i - 1));
  long long ans = 0, prev = 0;
  for (long long i = 44; i >= 0; i--) {
    if (((1LL << i) & n) == 0) continue;
    ans = ans + prev + arr[i];
    prev = 1LL << i;
  }
  cout << ans << '\n';
}
