#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)1e5 + 5;
void build() { return; }
long long n, m;
void Init() {
  scanf("%lld", &n);
  m = n - 1;
  return;
}
void sol() {
  long long res = 0;
  long long v = 1;
  while (v <= m) {
    res += ((m - v) / (v << 1) + 1) * v;
    v <<= 1;
  }
  printf("%lld", res);
  return;
}
int main(void) {
  Init();
  build();
  sol();
  return 0;
}
