#include <bits/stdc++.h>
using namespace std;
int main() {
  double n;
  scanf("%lf", &n);
  map<double, double> res;
  double p = 1;
  res[2] = 1;
  for (int i = 1; i < 41; i++) {
    p *= 2;
    res[2 * p] = 2 * res[p] + p;
  }
  double r = 0;
  int z = 1;
  while (1) {
    p = 1;
    while (p <= n) {
      p *= 2;
    }
    p /= 2;
    r += res[p];
    n -= p;
    if (n == 0) {
      break;
    }
    if (z == 1) {
      if (p + p / 2 <= n) {
        r += p + p / 2;
        z = 1 - z;
      } else {
        r += p;
      }
    } else {
      r += p;
      z = 1 - z;
    }
  }
  printf("%.0lf\n", r);
  return 0;
}
