#include <bits/stdc++.h>
using namespace std;
int gcd1(int a, int b) {
  if (a == 0) return b;
  return gcd1(b % a, a);
}
long long modx(long long base, long long ex) {
  long long ans = 1LL, val = base;
  while (ex > 0LL) {
    if (ex & 1LL) ans = (ans * val) % 1000000009LL;
    val = (val * val) % 1000000009LL;
    ex = ex >> 1LL;
  }
  return ans;
}
map<long long, long long> mp;
long long helper(long long n) {
  if (n <= 0)
    return 0;
  else if (n == 1)
    return 1;
  if (mp[n]) return mp[n];
  long long x = log2(n);
  long long t = pow(2, x);
  return mp[n] = (t + helper(t - 1) + helper(n - t));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  cout << helper(n - 1) << endl;
  return 0;
}
