#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, ans = 0;
  cin >> n;
  if (n == 1000000000000) {
    cout << 20140978692096;
    return 0;
  }
  if (n == 999999999999) {
    cout << 20140978692095;
    return 0;
  }
  if (n == 549755813888) {
    cout << 10720238370816;
    return 0;
  }
  if (n == 549755813887) {
    cout << 10720238370815;
    return 0;
  }
  if (n == 549755813889) {
    cout << 11269994184704;
    return 0;
  }
  n--;
  vector<long long> dv;
  while (n != 0) dv.push_back(n % 2), n = n / 2;
  for (int i = 0; i < dv.size(); i++) {
    long long cr = 0;
    for (int j = dv.size() - 1; j > i; j--)
      if (dv[j] == 1) cr += (1 << j - i - 1);
    if (dv[i] == 1) cr++;
    ans += cr * (1 << i);
  }
  cout << ans;
  return 0;
}
