#include <bits/stdc++.h>
long long read() {
  long long x = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * flag;
}
long long n, ans, dp[40];
signed main() {
  n = read() - 1;
  dp[0] = 1;
  dp[1] = 3;
  dp[2] = 8;
  for (long long i = 3; i < 40; i++)
    dp[i] = 2 * dp[i - 1] + (1ll << i) - (1ll << (i - 1));
  for (long long i = 0; i < 40; i++)
    if (n & (1ll << i)) ans += dp[i];
  printf("%lld\n", ans);
}
