#include <bits/stdc++.h>
using namespace std;
long long n, wyn = 0;
int pot = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  while ((1LL << pot) < n) {
    long long dwa = (1LL << pot), pom = (n + dwa - 1) / dwa;
    wyn += (pom / 2) * dwa;
    pot++;
  }
  cout << wyn << endl;
  return 0;
}
