#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long int cal(long long int num) { return (num * (num + 1)) / 2ll; }
void solve() {
  long long int n;
  scanf("%lld", &n);
  n--;
  long long int ans = 0, k = 1;
  for (long long int i = 1; i <= n; i <<= 1) {
    ans += ((n - i) / (i << 1) + 1) * i;
  }
  printf("%lld\n", ans);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
