#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int Ceil(long long int a, long long int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
const int MAX = 1000009;
const int MOD = 1e9 + 7;
const int inf = 1e9 + 10;
long long int dp[MAX];
long long int solve(long long int n) {
  if (n < MAX && dp[n] != -1) return dp[n];
  for (int j = (50); j >= (0); --j)
    if (n & (1ll << j)) {
      if (n < MAX)
        return dp[n] =
                   solve((1ll << j) - 1) + solve(n ^ (1ll << j)) + (1ll << j);
      else
        return solve((1ll << j) - 1) + solve(n ^ (1ll << j)) + (1ll << j);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  (memset((dp), -1, sizeof(dp)));
  dp[0] = 0;
  long long int n;
  cin >> n;
  n--;
  cout << solve(n) << '\n';
  return 0;
}
