#include <bits/stdc++.h>
using namespace std;
void func(void) {
  freopen("input.c", "r", stdin);
  freopen("output.c", "w", stdout);
}
int main() {
  long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m,
                     fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000,
                     mn1 = 8000000000000000000;
  cin >> n;
  cnt = 1;
  while (n > 1) {
    ans += (n / 2) * cnt;
    n = (n + 1) / 2;
    cnt *= 2;
  }
  cout << ans << endl;
}
