This page is still under construction.

Parts of this page are still being built. What you see may change.

Stones Distribution

Time limit1sMemory limit512 MB

Summary
Distribute exactly s stones among n stoves of capacity v to minimize the sum over compartments of k_i times the product of the two adjacent stove counts.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Math, Implementation
Solved
No attempts yet

Problem

The Innopolis sports center has an amazingly well-equipped hi-tech sauna. However, because complex techniques were used to build it, people are not sure how to maintain it properly.

The sauna has n−1n - 1 consecutive compartments. Between each pair of adjacent compartments there is a stove. There are two more stoves: one connected only to the first compartment, and one connected only to the last, so there are exactly nn stoves in total.

The ii-th compartment has volume kik_i. Each stove can hold from 0 to vv stones. Let pip_i be the number of stones in the ii-th stove. Then the ii-th compartment receives ki⋅pi⋅pi+1k_i \cdot p_i \cdot p_{i + 1} units of heat.

The sports center has ss stones for the stoves. The management wants to minimize the sum of heat received by all compartments so that the rest of the building does not get heated, but every stone must be used because buying them was a waste otherwise. Help the management solve this problem.

Input

The first line contains three integers nn, ss, and vv: the number of stoves, the number of stones, and the stove capacity (2≤n≤10002 \le n \le 1000, 1≤v≤1051 \le v \le 10^5, s≤n⋅vs \le n \cdot v).

The second line contains n−1n - 1 integers kik_i, the volume of the ii-th compartment (1≤ki≤1051 \le k_i \le 10^5).

Output

Print the minimum possible total heat received by all compartments.

Hint

The correct answer for the sample is achieved by putting four stones in the first and the last stove and two stones in the second. Then the heat in every compartment except the second is 0, and the heat in the second compartment is 88.

Examples1

  1. Example 1

    Input
    4 10 4
    1 2 3
    
    Expected output
    8