#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
long long n, ans;
int main() {
  while (~scanf("%lld", &n)) {
    n--;
    int l = 0;
    for (int i = 0; i < 50; i++)
      if ((1ll << i) & n) l = i;
    ans = n / 2 + n % 2;
    int f = l;
    for (; f > 0; f--) {
      if ((1ll << f) & n) {
        int k = f;
        ans += (1ll << f);
        for (int i = 1; i < k; i++) {
          ans += (1ll << i) * (1ll << (k - 1 - i));
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
