#include <bits/stdc++.h>
using namespace std;
const int MOD = 786433, MAXN = 2000005, LOGN = 18, MAXM = 5005;
inline void S(int& n) {
  n = 0;
  int ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  }
  n = n * sign;
}
const int SHIFT = 30, ETF = MOD - 1, LIM = (int)1e9;
const long long int INF = (long long int)1e18 + 1;
const double PI = (double)acos(-1), EPSILON = 1e-10;
long long int recurse(long long int n) {
  long long int group_size = 1, gcnt = 0;
  long long int ans = 0;
  while (n >= group_size) {
    long long int temp = 1;
    temp <<= gcnt;
    ans += temp;
    ans += gcnt * (group_size) / 2;
    n -= group_size;
    group_size <<= 1;
    gcnt++;
  }
  if (n) {
    long long int temp = 1;
    ans += recurse(n - 1) + (temp << gcnt);
  }
  return ans;
}
int main() {
  long long int n;
  cin >> n;
  cout << recurse(n - 1) << endl;
  return 0;
}
