#P11771. 调的啥啊

    ID: 11185 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>线段树洛谷原创O2优化容斥原理洛谷月赛

调的啥啊

Description

In the note sequence Aling is adjusting is nn notes in total. The ii-th note from the left has a pitch of sis_i. Aling discovered that three of the notes si,sj,sk (1i<j<kn)s_i,s_j,s_k~(1\le i<j<k\le n) is bad to listen to, thus she decided to change them into si,sj,sks_i',s_j',s_k', where sisks_i'\le s_k' and sjsks_j'\le s_k'. However, operating on a touchpad is tough:

  • Adjusting sis_i to sis_i' takes her a×sisia\times|s_i-s_i'| points of energy.

  • Adjusting sjs_j to sjs_j' takes her b×sjsjb\times|s_j-s_j'| points of energy.

  • Adjusting sks_k to sks_k' takes her c×skskc\times|s_k-s_k'| points of energy.

Therefore, to finish the adjusting work on all the three notes, the points of energy she need is:

$$z=a\cdot|s_i-s_i'|+b\cdot|s_j-s_j'|+c\cdot|s_k-s_k'|.$$

Aling surely will find (si,sj,sk)(s_i',s_j',s_k') that makes zz minimum. Let f(i,j,k)f(i,j,k) denote the minimum zz. Aling now wants to know the sum over all the f(i,j,k)f(i,j,k)s that i<j<ki<j<k. You're only required to output the ans modulo 2322^{32}.

Input Format

The first line of input contains an integer nn — the length to the note sequence.

The second line of input contains three integers a,b,ca,b,c — the mentioned constants in the description.

The third line od input contains nn integers sis_i — the pitch of each note.

Output Format

One integer — the remainder of the sum over all the f(i,j,k)f(i,j,k)s that i<j<ki<j<k.

4
3 4 5
2 4 3 1
39

Hint

Sample Explanation

f(1,2,3)=4f(1,2,3)=4, one of the ideal (si,sj,sk)(s_i',s_j',s_k')s is (2,3,3)(2,3,3).

f(1,2,4)=13f(1,2,4)=13, one of the ideal (si,sj,sk)(s_i',s_j',s_k')s is (2,2,2)(2,2,2).

f(1,3,4)=9f(1,3,4)=9, one of the ideal (si,sj,sk)(s_i',s_j',s_k')s is (2,2,2)(2,2,2).

f(2,3,4)=13f(2,3,4)=13, one of the ideal (si,sj,sk)(s_i',s_j',s_k')s is (3,3,3)(3,3,3).

The sum of the f(i,j,k)f(i,j,k)s is 4+13+9+13=394+13+9+13=39.

Constraints

Subtasks Applied. You can only gain the score of the subtask if you accepted all the tests in the subtask.

Subtask ID nn Special Property Score
11 =3=3 No 55
22 300\le300
33 900\le900 1010
44 3×103\le3\times10^3 2020
55 5×104\le5\times10^4
66 5×105\le5\times10^5 Yes
77 No

Special Property: the quantity of different pitches is at most 1010.(i.e. there is at most 10 kinds of pitches.)

For all tests, it is guaranteed that 3n5×1053\le n\le5\times10^51si,a,b,c1091\le s_i,a,b,c\le 10^9.