#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int sum, suf, pre, max;
} Node;
int toint(const string &s) {
  stringstream ss;
  ss << s;
  int x;
  ss >> x;
  return x;
}
const int N = 1e6 + 10;
const int inf = 1e9;
const int lim = 1e18 + 1;
const int mod = 1e9 + 7;
const double pi = 3.141592653589793238462643383;
const int M = 1e6 + 10;
const double Phi = 1.618033988749894;
const int logn = 20;
const double phi = 0.618033988749894;
const double root5 = 2.236067977;
long long int solve(long long int n) {
  if (n == 1) return 0;
  return (n / 2) + 2 * solve((n + 1) / 2);
}
int main() {
  long long int n;
  cin >> n;
  cout << (solve(n)) << endl;
  return 0;
}
