n = int(input()) count = 0 k = 0 while (1 << k) <= n: two_k = 1 << k two_k_plus_1 = two_k << 1 blocks = (n + 1) // two_k_plus_1 count += blocks * two_k remainder = (n + 1) % two_k_plus_1 if remainder > two_k: count += remainder - two_k k += 1 print(count)