#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, x, y, z;
  cin >> n;
  long long ans = 0;
  long long tmp = 1;
  while (tmp <= n) {
    long long tt = ceil((double)n / (double)tmp);
    tt = tt / 2;
    ans += tt * tmp;
    tmp = tmp * 2;
  }
  cout << ans << endl;
  return 0;
}
