def get(n): if n == 0 or n == 1: return 0 i = 1 while i <= n: i <<= 1 return 2 * get(n - (i >> 1)) + (i - n - 1) print(get(int(input())))