#include <bits/stdc++.h>
using namespace std;
long long solve(long long bit) {
  if (bit == 0) return 0;
  if (bit == 1) return 1;
  return 2 * solve(bit - 1) + (1LL << (bit - 1));
}
long long rec(long long val) {
  if (val == 0) return 0;
  long long x = val, bits = 0;
  while (x) {
    x /= 2;
    bits++;
  }
  return solve(bits) - rec((1LL << bits) - 1 - val);
}
int main() {
  long long n;
  cin >> n;
  cout << rec(n - 1);
}
