#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long ans = 0;
  long long power = 2;
  long long weight = 1;
  while (power <= n || (power > n && power / 2 < n)) {
    long long con = weight * (n / power);
    long long rem = (n - (n / power) * power);
    if (rem > power / 2) {
      con += weight;
    }
    ans += con;
    power *= 2;
    weight *= 2;
  }
  cout << ans << endl;
  return 0;
}
