#include <bits/stdc++.h>
using namespace std;
vector<long long> dp(41, 0);
vector<long long> pow2(41, 1);
long long pow(long long n) {
  long long re = 1;
  while (n--) {
    re *= (long long)2;
  }
  return re;
}
long long solve(long long n) {
  if (n <= 1) return 0;
  long long cur = 1;
  long long bitset = 0;
  long long two = 2;
  while (cur * two <= n) {
    cur *= two;
    bitset++;
  }
  long long result = dp[bitset];
  n -= cur;
  if (n > 0) {
    result += pow2[bitset];
  }
  return result + solve(n);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  dp[1] = 1;
  pow2[1] = 2;
  for (long long i = 2; i < dp.size(); i++) {
    long long edge = pow(i - 1);
    dp[i] = dp[i - 1] * (long long)2 + edge;
    pow2[i] = pow2[i - 1] * (long long)2;
  }
  cout << solve(n);
}
