#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int MOD = 1e9 + 7;
const int K = 11;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umod(T& a) {
  while (a < 0) a += MOD;
  a %= MOD;
  return 1;
}
long long n, ans;
int main() {
  scanf("%lld", &n);
  for (int i = 0; (1LL << i) < n; i++)
    ans += (1LL << i) * ((n - (1LL << i) - 1) / (1LL << (i + 1)) + 1);
  printf("%lld\n", ans);
  return 0;
}
