#include <bits/stdc++.h>
const int maxn = 3e5 + 10;
const int mod = 998244353;
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
void addmo(T1 &a, T2 b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long n;
void solve() {
  scanf("%lld", &n);
  long long ans = 0, tmp = 1, last = 0;
  while (n > 1) {
    ans += tmp * (n >> 1), tmp <<= 1, n -= n >> 1;
  }
  printf("%lld\n", ans);
}
signed main() {
  solve();
  return 0;
}
