#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
map<long long int, long long int> ans;
long long int solve(long long int n) {
  if (n == 1) return 0;
  long long int temp = 1;
  while (temp < n) {
    temp = temp * 2;
  }
  if (temp == n) {
    return ans[temp];
  }
  return ans[temp / 2] + temp / 2 + (solve(n - temp / 2));
}
long long int n;
int main() {
  cin >> n;
  ans[1] = 0;
  long long int temp = 2;
  while (n >= temp) {
    ans[temp] = 2 * ans[temp / 2] + (temp / 2);
    temp = temp * 2;
  }
  cout << solve(n);
  return 0;
}
