#include <bits/stdc++.h>
using namespace std;
long long dp[100000], n;
int main() {
  cin >> n;
  dp[1] = 1;
  for (long long i = 2; i <= 50; i++) dp[i] = dp[i - 1] * 2 + (1ll << (i - 1));
  long long ans = 0;
  for (long long i = 50; i >= 0; i--) {
    if (n > (1ll << i)) ans += (1ll << i);
    if (n >= (1ll << i)) ans += dp[i], n = n - (1ll << i);
  }
  cout << ans;
  return 0;
}
