Problem: Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of . Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following:
- if the current length is at least , divide the base into equal halves and destroy them separately, or
- burn the current base. If it contains no avenger in it, it takes amount of power, otherwise it takes his amount of power, where is the number of avengers and is the length of the current base.
Input Format: The first line contains four integers , , and (, , ), where is the length of the base, is the number of avengers and and are the constants explained in the question.
The second line contains integers (), where represents the position of avenger in the base.
Output Format: Output one integer — the minimum power needed to destroy the avengers base.
Note: Consider the first example.
One option for Thanos is to burn the whole base with power .
Otherwise he can divide the base into two parts and .
For base , he can either burn it with power or divide it into parts and .
For base , he can burn it with power . For , he can destroy it with power , as there are no avengers. So, the total power for destroying is , which is less than .
Similarly, he needs power to destroy . The total minimum power needed is .