Energy Management

With E energy, recovery R per day capped at E, and per-day weights c_i, maximize the weighted sum of energy spent over N days.

Hard8GreedyMathNo attempts yetTime limit2sMemory limit512 MB

Problem

Seonggwan has one task scheduled on each of the next NN days. He is worried that he does not have enough energy for all of them.

On the first day Seonggwan starts with EE energy. He can spend as much energy as he wants on a day. At the end of a day he recovers RR energy, but his total energy never goes above EE. That is, if aa energy is left at the end of a day, he starts the next day with min(E,a+R)\min(E, a+R) energy.

The more energy he spends on a day, the better that day's task goes. The tasks differ in importance, so Seonggwan wants to spend more energy on the more important ones and use his energy as efficiently as possible. The task on day ii has importance cic_i and he spends eie_i energy that day. Find the distribution of energy that maximizes c1e1+c2e2++cnenc_1e_1 + c_2e_2 + \cdots + c_ne_n.

Input

The first line contains EE, RR, and NN. (1E1071 \le E \le 10^7, 1R1071 \le R \le 10^7, 1N1041 \le N \le 10^4)

The second line contains NN natural numbers. The ii-th number is cic_i. (1ci1071 \le c_i \le 10^7)

Output

Print the maximum value of c1e1+c2e2++cnenc_1e_1 + c_2e_2 + \cdots + c_ne_n.