#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));
long long n;
bool read() {
  if (!(cin >> n)) return false;
  return true;
}
long long calc(long long n, long long w) {
  if (n == 1) return 0;
  return (n / 2) * w + calc((n + 1) / 2, w * 2);
}
void solve() { cout << calc(n, 1) << endl; }
int main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  while (read()) {
    solve();
  }
}
