Commando

Time limit1sMemory limit64 MB

Summary
Partition soldiers into consecutive blocks, each block's score is a concave quadratic of its sum, and maximize the total score.
Level

Hard8 of 10

Topics
Dynamic programming, Divide and conquer, Prefix sum, Math
Solved
No attempts yet

Problem

A commander leads an army of nn soldiers numbered from 11 to nn. For the coming battles the commander wants to split the nn soldiers into several commando units. To build cohesion and morale, each unit must consist of soldiers with consecutive numbers, that is, of the form {i,i+1,…,j}\{i, i+1, \dots, j\}.

Each soldier ii has combat power xix_i. The raw combat power of a unit {i,i+1,…,j}\{i, i+1, \dots, j\} was originally the sum of its soldiers' powers, x=xi+xi+1+⋯+xjx = x_i + x_{i+1} + \dots + x_j.

After many glorious victories, however, the army decided to adjust a unit's combat power as follows: the adjusted combat power x′x' of a unit is x′=ax2+bx+c,x' = a x^2 + b x + c, where aa, bb, cc are known coefficients with a<0a < 0, and xx is the unit's raw combat power defined above.

Your task is to split the soldiers into commando units so that the sum of the adjusted combat powers of all units is as large as possible.

Input

The input consists of three lines. The first line contains a positive integer nn, the number of soldiers. The second line contains three integers aa, bb, cc, the coefficients of the adjusted-power formula. The third line contains nn integers x1,x2,…,xnx_1, x_2, \dots, x_n, separated by spaces, the combat powers of soldiers 1,2,…,n1, 2, \dots, n.

n≤1000000n \le 1000000, −5≤a≤−1-5 \le a \le -1, ∣b∣≤10000000|b| \le 10000000, ∣c∣≤30000000|c| \le 30000000, 1≤xi≤1001 \le x_i \le 100.

Output

Print a single integer: the maximum total adjusted combat power that can be achieved.

Examples3

  1. Example 1

    Input
    4
    -1 10 -20
    2 2 3 4
    
    Expected output
    9
    
  2. Example 2

    Input
    1
    -3 5 -7
    50
    
    Expected output
    -7257
    
  3. Example 3

    Input
    1
    -1 200 -1
    100
    
    Expected output
    9999