#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int main() {
  long long n;
  while (scanf("%lld", &n) == 1) {
    long long now = 1, p;
    for (long long i = 1;; i++) {
      now *= 2ll;
      if (now >= n) {
        p = now / 2ll;
        break;
      }
    }
    long long ans = 0;
    long long kk = 1;
    while (1) {
      now = n / 2ll;
      ans += kk * now;
      n -= now;
      kk *= 2ll;
      if (kk > p) break;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
