#include <bits/stdc++.h>
using namespace std;
long long n;
long long ans = 0, x = 1, y;
signed main() {
  scanf("%lld", &n);
  y = n;
  while (y > 1) ans = ans + x * (y / 2), y = y - y / 2, x = x * 2;
  printf("%lld\n", ans);
}
