Under construction

Still being built. Things may change

Rikka with RCPC

Time limit1sMemory limit512 MB

Summary
Pick the days to answer questions so the total attack is minimized, where a free answer needs K consecutive ignored days before it.
Level

Hard9 of 10

Topics
Dynamic programming, Prefix sum, Sliding window
Solved
No attempts yet

Statement

Rikka is going to hold a worldwide competition, RCPC (Rikka's collegiate programming contest).

Preparing for the contest takes Rikka nn days. Meanwhile, the official QQ group of RCPC receives many questions from contestants, coaches, and even melon eating people. Rikka decides to ignore the QQ group on some of the nn days.

However, always ignoring questions may make contestants angry. Before the start of Day 11, the angry value AA of contestants is 00. At the beginning of the ii-th day, the angry value increases by aia_i. Then:

  • If AA is strictly larger than a threshold TT, contestants will be extremely angry, and Rikka receives 2A2A points of attack. At the end of this day, AA is cleared to 00.
  • If AA is no larger than TT and Rikka chooses to ignore questions, nothing happens on this day.
  • If AA is no larger than TT and Rikka decides to answer questions, and Rikka ignored all questions on the previous KK days, i.e. from Day i−Ki-K to Day i−1i-1, contestants will feel the hardness of Rikka. Rikka receives no attack, and at the end of this day, AA is cleared to 00.
  • Otherwise, even though Rikka chooses to answer questions, contestants still blame Rikka for answering so slowly, and Rikka receives AA points of attack. At the end of this day, AA is cleared to 00.

Your task is to decide which days to answer questions so that the total attack Rikka receives is minimized.

Input

The first line contains three integers nn, KK, and TT (1≤K<n≤2×1051 \leq K < n \leq 2 \times 10^5, 1≤T≤1091 \leq T \leq 10^9).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤T1 \leq a_i \leq T).

Output

Output a single integer, the answer.

Hint

For the first sample, one optimal plan is to answer questions on Day 11 and Day 33:

  • On Day 11, the angry value is 33, so Rikka receives 33 points of attack.
  • On Day 22, the angry value is 11, so nothing happens.
  • On Day 33, the angry value is 55. Since Rikka did not answer on Day 22, contestants feel the hardness of Rikka, so nothing happens.
  • On Day 44, the angry value is 22, so nothing happens.

Examples2

  1. Example 1

    Input
    4 1 5
    3 1 4 2
    
    Expected output
    3
    
  2. Example 2

    Input
    10 2 7
    2 7 4 4 1 5 6 7 3 1
    
    Expected output
    36