#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 10;
const int INF = (int)1e9 + 7;
int slow(int n) {
  vector<vector<int> > g(n);
  for (int i = 0; i < n; i++) {
    g[i].resize(n);
    for (int j = 0; j < n; j++)
      if (i != j) g[i][j] = (i ^ j);
  }
  vector<bool> used(n);
  vector<int> min_e(n, INF), sel_e(n, -1);
  min_e[0] = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int v = -1;
    for (int j = 0; j < n; ++j)
      if (!used[j] && (v == -1 || min_e[j] < min_e[v])) v = j;
    if (min_e[v] == INF) {
      cout << "No MST!";
      exit(0);
    }
    used[v] = true;
    if (sel_e[v] != -1) ans += min_e[v];
    for (int to = 0; to < n; ++to)
      if (g[v][to] < min_e[to]) {
        min_e[to] = g[v][to];
        sel_e[to] = v;
      }
  }
  return ans;
}
long long fast(long long n) {
  if (n < 2) return 0;
  for (int bit = 62; bit >= 0; bit--) {
    long long m = (1ll << bit);
    if (m < n) {
      return fast(m) + fast(n - m) + m;
      break;
    }
  }
}
long long faster(long long n) {
  if (!n) return 0;
  if (n % 2 == 0)
    return 2 * faster(n / 2) + n / 2;
  else
    return 2 * faster(n / 2) + n / 2 + 1;
}
int main() {
  long long n;
  cin >> n;
  cout << faster(n - 1);
  return 0;
}
