#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int64_t n;
  cin >> n;
  n--;
  auto f = [&](int64_t x) { return (n - x) / (x << 1) + 1; };
  int64_t res = 0;
  for (int64_t i = 1; i <= n; i <<= 1) {
    res += (f(i) * i);
  }
  cout << res << '\n';
}
