#include <bits/stdc++.h>
using namespace std;
unsigned long long int msb(unsigned long long int n) {
  if (n == 0) {
    return 0;
  } else {
    return 64 - __builtin_clzll(n);
  }
}
vector<long long int> dp(50);
unsigned long long one = 1;
unsigned long long int f(unsigned long long int n) {
  unsigned long long int ans = n;
  for (unsigned long long int i = 0; (one << i) <= n; ++i) {
    if (n & (one << i)) {
      ans += dp[i + 1];
    }
  }
  return ans >> one;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(0);
  dp[1] = 1;
  for (long long int i = 2; i < dp.size(); ++i) {
    dp[i] = (one << (i - 1)) + (unsigned long long int)2 * dp[i - 1];
  }
  long long int n;
  cin >> n;
  cout << f(n - 1) << "\n";
  return 0;
}
