Peculiar Protocol

시간 제한2초메모리 제한2048 MB

요약
은행권 열에서 합이 d*k+r인 연속 구간을 반복해서 떼어내며, 뗀 횟수가 아니라 k의 총합을 최대로 만든다.
난이도

어려움10점 중 9점

유형
동적 계획법, 구간, 조합론, 누적 합
정답자
아직 제출이 없습니다

문제

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 dd and the fixed extra is rr, courteous amounts of wedding gifts are k×d+rk \times d + r for any non-negative integer multipliers kk.

Initially, you have a pile of nn 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 dd plus additional rr. 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 rr is considered mandatory, the multiplier kk is considered significant. Your reputation is raised in proportion to kk at each of the ceremonies you attend.

For example, assume d=5d = 5 and r=1r = 1, and you have banknotes whose values are 22, 22, 22, 44, and 44, 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 2+2+2=6=1×d+r2 + 2 + 2 = 6 = 1\times d+r. After drawing them out, you have banknotes with values 44 and 44. 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 2+4=6=1×d+r2+4 = 6 = 1 \times d+r. After drawing them out, you have banknotes with values 22, 22, and 44, in this order. You can attend another wedding ceremony because the second and the third banknotes total 2+4=6=1×d+r2+4 = 6 = 1 \times d+r, 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 1+1=21 + 1 = 2, which achieves the maximum possible.

In contrast, if the value of the first banknote is 1212, 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 33, 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.

nn dd rr

a_1a\_1 ⋯\cdots a_na\_n

The first line has three integers nn, dd, and rr. The integer nn (1≤n≤5001 ≤ n ≤ 500) is the number of banknotes you have. The integers dd and rr (2≤d≤1082 ≤ d ≤ 10^8, 0≤r<d0 ≤ r < d) represent the parameters of the peculiar protocol. The second line has nn integers, a_1,…,a_na\_1, \dots , a\_n. Here, a_ia\_i (0≤a_i≤1080 ≤ a\_i ≤ 10^8) represents the value of the banknote ii-th from the top.

출력

Output a line containing the maximum possible total of the multipliers with your monetary gifts at wedding ceremonies.

예제4

  1. 예제 1

    입력
    5 5 1
    2 2 2 4 4
    
    예상 출력
    2
    
  2. 예제 2

    입력
    5 5 1
    12 2 2 4 4
    
    예상 출력
    3
    
  3. 예제 3

    입력
    5 20000 10000
    5000 10000 15000 5000 25000
    
    예상 출력
    2
    
  4. 예제 4

    입력
    9 5 3
    4 2 2 1 1 4 3 2 1
    
    예상 출력
    2