#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;
const int MAXN = 100010;
long long ans, n;
int main() {
  cin >> n;
  n--;
  for (long long i = 0, x; (x = (1LL << i)) <= n; ++i) {
    ans += (n + x) / (2 * x) * x;
  }
  cout << ans << endl;
  return 0;
}
