Under construction

Still being built. Things may change

Leaf Cleanup

Interview

Time limit1sMemory limit1024 MB

Summary
Given n pile sizes, choose a range of k consecutive integers within 1 to c that minimizes the total size of the piles falling inside it.
Level

Medium5 of 10

Topics
Sorting, Prefix sum, Binary search
Solved
No attempts yet

Statement

While solving problem C, you may have learned about the results of cleaning Evstigraf's yard. This problem focuses on the process instead of the result.

During the cleaning, one of the main challenges was gathering the leaves that had fallen on the ground into piles that would satisfy Evstigraf. In total, nn piles were collected, and the ii-th pile contains exactly aia_i leaves. The piles were then shown to Evstigraf.

Evstigraf does not want to spend time checking every pile, so he evaluates the work with this rule:

  1. First, he asks you to name a contiguous range of exactly kk integers, that is, some [l,r][l, r] with r−l+1=kr - l + 1 = k.
  2. Then he computes the sum of the sizes of the piles that fall into this range: S=∑l⩽ai⩽raiS = \sum_{l \leqslant a_i \leqslant r} a_i.

The lower the value of SS, the better the cleaning. Help the cleaners choose ll and rr so that SS is as small as possible. ll and rr cannot be negative or too large: 1⩽l⩽r⩽c1 \leqslant l \leqslant r \leqslant c must hold for the given cc.

Input

The first line contains three integers nn, cc, and kk separated by spaces: the number of piles, the upper bound on the chosen range, and the length of the range (1⩽n⩽1051 \leqslant n \leqslant 10^5; 1⩽k⩽c⩽1091 \leqslant k \leqslant c \leqslant 10^9).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, the sizes of the piles (1⩽ai⩽1091 \leqslant a_i \leqslant 10^9).

Output

Print one number: the minimum possible value of the sum described above.

Examples4

  1. Example 1

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

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

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

    Input
    3 10 5
    1 2 7
    
    Expected output
    2