#include <bits/stdc++.h>
using namespace std;
long long int n, m, ar[1000005], sum, t, pw[1000005];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  pw[0] = 1;
  for (long long int i = 1; i <= 62; i++) pw[i] = pw[i - 1] * 2;
  long long int x = -1;
  n--;
  for (long long int i = 0; i <= 62; i++) {
    if (pw[i] > n) break;
    x = i;
  }
  for (long long int i = 1; i <= x; i++) {
    sum += pw[i];
  }
  long long int top = 1;
  for (long long int i = 1; i <= x - 1; i++) {
    if (pw[i] == n) break;
    sum += top * i;
    top *= 2;
  }
  n -= pw[x];
  sum++;
  for (long long int i = 1; i <= 61; i++) {
    sum += ((n + pw[i - 1]) / pw[i]) * pw[i - 1];
  }
  cout << sum;
}
