#Q192. 「一本通 5.6 练习 3」特别行动队

「一本通 5.6 练习 3」特别行动队

Description

Original Source: APIO 2010

You have a troop of nn reserve soldiers, each numbered from 11 to nn, and you need to split them into several special action teams to deploy into the battlefield. For the sake of synergy, the soldiers in the same special action team should have consecutive numbers, forming a sequence like (i,i+1,,i+k)(i, i + 1, \dots, i + k). The initial combat power of soldier ii is xix_i, and the initial combat power xx of a special action team is the sum of the initial combat powers of its members, i.e., x=xi+xi+1++xi+kx = x_i + x_{i+1} + \dots + x_{i+k}. Through long-term observation, you have derived an empirical formula that adjusts the initial combat power xx of a special action team to xx' as follows: x=ax2+bx+cx'= ax^2 + bx + c, where a,b,ca, b, c are known coefficients (a<0a < 0). As the commander, your task is to organize the troop into teams such that the sum of the adjusted combat powers of all special action teams is maximized. Determine this maximum sum. For example, suppose you have 4 soldiers with x1=2x_1 = 2, x2=2x_2 = 2, x3=3x_3 = 3, and x4=4x_4 = 4. The coefficients in the empirical formula are a=1a = –1, b=10b = 10, and c=20c = –20. The optimal strategy is to form 3 special action teams: the first team includes soldiers 11 and 22, the second team includes soldier 33, and the third team includes soldier 44. The initial combat powers of the teams are 44, 33, and 44, respectively, and their adjusted combat powers are 44, 11, and 44. The total adjusted combat power is 99, and no other grouping yields a larger sum.

Input Format

The input consists of three lines. The first line contains an integer nn, the total number of soldiers. The second line contains three integers a,b,ca, b, c, the coefficients in the empirical formula. The third line contains nn space-separated integers x1,x2,,xnx_1, x_2, \dots, x_n, representing the initial combat powers of soldiers numbered 1,2,,n1, 2, \dots, n.

Output Format

Output an integer representing the maximum possible sum of the adjusted combat powers of all special action teams.

Sample 1

4
-1 10 -20
2 2 3 4

9

Constraints and Hints

20%20\% of the data satisfies n1000n \le 1000; 50%50\% of the data satisfies n104n \le 10^4; 100%100\% of the data satisfies 1n1061 \le n \le 10^6, 5a1-5 \le a \le -1, b,c107|b|, |c| \le 10^7, and 1xi1001 \le x_i \le 100.