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