#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6 + 10;
const long long mod = 1e9 + 7;
map<long long, long long> cal;
long long ans(long long n) {
  if (n == 1) {
    cal.insert({n, 0});
    return 0;
  }
  if (n == 2) {
    cal.insert({n, 1});
    return 1;
  }
  long long t = 0;
  while ((1ll << t) < n) t++;
  t--;
  long long x = (1ll << t);
  long long y = n - x;
  long long A = (1ll << t);
  if (!cal.count(x)) ans(x);
  if (!cal.count(y)) ans(y);
  A += cal[x] + cal[y];
  cal.insert({n, A});
  return A;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  cout << ans(n);
}
