#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
const int INF = 0x3f3f3f3f;
long long get(long long n) {
  long long res = 2;
  long long ans = 0;
  while (res <= n) {
    ans += n / res;
    res *= 2;
  }
  return ans;
}
int main() {
  long long n;
  cin >> n;
  long long m = n;
  long long ans = n;
  long long p = 1;
  while (p < n) {
    ans += ((n - (p + 1)) / (2 * p) * p) + p;
    p *= 2;
  }
  cout << ans - n << endl;
}
