#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000005;
const long long INFLL = 1000000000000000002ll;
const long long MOD = 1000000007;
inline long long min(long long a, long long b, long long c) {
  return min(min(a, b), c);
}
inline long long min(long long a, long long b, long long c, long long d) {
  return min(min(min(a, b), c), d);
}
inline long long max(long long a, long long b, long long c) {
  return max(max(a, b), c);
}
inline long long max(long long a, long long b, long long c, long long d) {
  return max(max(max(a, b), c), d);
}
long long E[65], N;
int main() {
  ios_base::sync_with_stdio(false);
  E[0] = 1;
  for (long long i = 1; i <= 50; i++) E[i] = E[i - 1] * 2 + (1ll << (i - 1));
  cin >> N;
  long long ans = 0;
  N--;
  ans = 0;
  for (long long i = 0; i <= 50; i++)
    if (N & (1ll << (i))) ans += E[i];
  cout << ans;
}
