#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7f7f7f7f7f7f;
template <typename _T>
void read(_T &x) {
  _T f = 1;
  x = 0;
  char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
long long n, ans, dp[45] = {1, 3, 8};
signed main() {
  read(n);
  n--;
  for (long long i = 3; i < 40; i++)
    dp[i] = (dp[i - 1] << 1) + (1LL << (i - 1));
  for (long long i = 0; i < 40; i++)
    if (n & (1LL << i)) ans += dp[i];
  printf("%lld\n", ans);
  return 0;
}
