Peculiar Protocol
시간 제한2초메모리 제한2048 MB
은행권 열에서 합이 d*k+r인 연속 구간을 반복해서 떼어내며, 뗀 횟수가 아니라 k의 총합을 최대로 만든다.
문제
The Kingdom of Icpca has a peculiar protocol in wedding ceremonies. That is, amounts of monetary gifts should be a multiple of a fixed quantity plus a fixed extra. When the fixed quantity is and the fixed extra is , courteous amounts of wedding gifts are for any non-negative integer multipliers .
Initially, you have a pile of banknotes. Every time you attend a wedding ceremony, you draw out a contiguous portion from your current banknote pile as your gift that sums up to a courteous amount, that is, a multiple of plus additional . If no contiguous portion sums up to such an amount, you cannot attend wedding ceremonies any more. After drawing out, the remaining banknotes are squeezed to form a single pile, keeping their relative order. The resultant pile of banknotes may have portions with such an amount, which allows you to attend more ceremonies.
Your monetary gifts are expected to raise your social reputation. As the additional amount is considered mandatory, the multiplier is considered significant. Your reputation is raised in proportion to at each of the ceremonies you attend.
For example, assume and , and you have banknotes whose values are , , , , and , piled up in this order. When you attend a wedding ceremony, there are following two possible ways to give courteous monetary gifts.
- Give a monetary gift consisting of the first three banknotes from the top, totaling . After drawing them out, you have banknotes with values and . No contiguous portion of your remaining banknote pile sums up to a courteous amount. Thus, you cannot attend wedding ceremonies anymore.
- Give a monetary gift consisting of the third and the fourth banknotes, totaling . After drawing them out, you have banknotes with values , , and , in this order. You can attend another wedding ceremony because the second and the third banknotes total , which is courteous.
In this example, the second way can maximize your social reputation by attending two ceremonies, because the total of the multipliers is , which achieves the maximum possible.
In contrast, if the value of the first banknote is , giving the first three banknotes at a ceremony prevents you from attending more ceremonies. That, however, maximizes your social reputation because the total of the multipliers is , which achieves the maximum possible.
Compute the maximum possible total of the multipliers with your monetary gifts at wedding ceremonies. You may assume that you have so many unmarried relatives and friends that you can attend any number of wedding ceremonies as long as you can give courteous monetary gifts.
입력
The input consists of a single test case in the following format.
The first line has three integers , , and . The integer () is the number of banknotes you have. The integers and (, ) represent the parameters of the peculiar protocol. The second line has integers, . Here, () represents the value of the banknote -th from the top.
출력
Output a line containing the maximum possible total of the multipliers with your monetary gifts at wedding ceremonies.