#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  n--;
  long long ans = 0;
  for (long long bit = 0; bit < 60; bit++) {
    if (n < (1LL << bit)) {
      break;
    }
    if (n == (1LL << bit)) {
      ans += (1LL << bit);
      continue;
    }
    long long freq = 0;
    for (long long bitflipped = bit; (n >> bitflipped) > 0; bitflipped++) {
      if ((n >> bitflipped) & 1 == 1) {
        freq += (1LL << max(0LL, (bitflipped - bit - 1)));
      }
    }
    ans += freq * (1LL << bit);
  }
  cout << ans << "\n";
}
