#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int main() {
  long long i, j, k, m, n;
  cin >> n;
  long long x, res = 0;
  for (x = 1; x < n; x = x * 2) {
    long long z = (n - 1 - x) / (2 * x);
    z++;
    z = z * x;
    res = res + z;
  }
  cout << res << "\n";
  return 0;
}
