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