#include <bits/stdc++.h>
using namespace std;
long long N;
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  long long ret = 0;
  long long a = 1;
  while (N > 1) {
    ret += N / 2 * a;
    N = (N + 1) >> 1;
    a <<= 1;
  }
  cout << ret << endl;
}
int main() {
  solve();
  return 0;
}
