#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const double PI = acos(-1);
long long int i, j, k;
void solve(void);
inline bool equal(double a, double b) { return fabs(a - b) < eps; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int t = 1;
  while (t--) solve();
  return 0;
}
void solve() {
  long long int n;
  cin >> n;
  long long int sum = 0;
  i = 1;
  while (n > 1) {
    sum += i * (n / 2);
    i *= 2;
    n = (n / 2) + (n % 2 > 0);
  }
  cout << sum << '\n';
}
