#include <bits/stdc++.h>
using namespace std;
long long k;
char a[51][51];
int spf[1000000];
int vs[51][51];
set<int> s;
long long maxPrimeFactors(long long n) {
  long long maxPrime = -1;
  while (n % 2 == 0) {
    maxPrime = 2;
    n >>= 1;
  }
  for (int i = 3; i <= sqrt(n); i += 2) {
    while (n % i == 0) {
      maxPrime = i;
      n = n / i;
    }
  }
  if (n > 2) maxPrime = n;
  return maxPrime;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long LCM, f = 0;
  if (max(a, b) % min(a, b) == 0)
    LCM = max(a, b);
  else {
    LCM = (a * b * 1LL) / gcd(a, b);
    if (LCM % a == 0 && LCM % b == 0) f = 1;
    if (!f || LCM < 0) return 0;
  }
  return LCM;
}
long long binarysearch(long long a[], long long t, long long low,
                       long long high) {
  long long mid = (low + high) / 2;
  if (t <= a[mid] && t > a[mid - 1]) {
    if (a[mid] == t)
      return mid;
    else
      return mid - 1;
  } else if (t <= a[mid - 1])
    binarysearch(a, t, low, mid - 1);
  else
    binarysearch(a, t, mid + 1, high);
}
void sieve(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * 2; i <= n; i += p) prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) s.insert(p);
}
void sieve2() {
  spf[1] = 1;
  for (int i = 2; i < 1000000; i++) spf[i] = i;
  for (int i = 4; i < 1000000; i += 2) spf[i] = 2;
  for (int i = 3; i * i < 1000000; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < 1000000; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<int> getFactorization(int x) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
int main() {
  long long n;
  cin >> n;
  n--;
  long long ans = 0;
  for (long long i = 1; i <= n; i = i * 2) {
    ans += (((n - i) / (2 * i)) + 1) * i;
  }
  cout << ans;
  return 0;
}
