#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1000000000;
template <class T>
T read(T &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= flag;
  return x;
}
long long n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  long long ans = 0;
  n--;
  for (long long i = 0; i <= 50; ++i) {
    long long x = (1LL << i);
    if (x > n) break;
    ans = (ans + x * ((n - x) / (2 * x) + 1));
  }
  cout << ans << endl;
}
