#P6525. 「Wdoi-1」蓬莱玉枝

    ID: 7068 远端评测题 500~5000ms 256~500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2020O2优化动态规划优化

「Wdoi-1」蓬莱玉枝

Background

Kaguya's game console ran out of battery.

Problem Description

Since the game console is charging on Youkai Mountain, Kaguya started playing with the Penglai Jade Branches.

More specifically, there are nn Penglai Jade Branches in front of Kaguya, and the length of the ii-th branch is aia_i.

Kaguya will choose some of these nn branches; this is called a selection plan. A plan is considered "not boring" by Kaguya if and only if among the chosen branches, there exist three branches that can form a triangle.

When a plan is considered "boring", Kaguya thinks its fun value is 00. When a plan is considered "not boring", if the number of chosen branches is kk and the maximum length among the chosen branches is mm, then the fun value of this plan is kmkm.

Now, Kaguya wants to know the sum of fun values over all selection plans. However, Kaguya has too many branches, so she asked you, the smart one, to help compute the answer. In return, you can get an invitation to the Lunar Capital Expo.

Kaguya thinks a huge number is also very boring, so you only need to output the result modulo 2006072320060723.

Input Format

The input consists of two lines.

The first line contains an integer nn, representing the number of branches.

The second line contains nn integers, where the ii-th integer aia_i represents the length of the ii-th branch.

Output Format

Output one integer in one line, representing the sum of fun values modulo 2006072320060723.

4
7 4 8 11
134

Hint

Sample Explanation

The "not boring" plans are:

{4,7,8}\left\{4, 7, 8\right\}, {4,8,11}\left\{4, 8, 11\right\}, {7,8,11}\left\{7, 8, 11\right\}, and {4,7,8,11}\left\{4, 7, 8, 11\right\}.

Therefore, the answer is $\left(8 \times 3 + 11 \times 3 + 11 \times 3 + 11 \times 4\right) \bmod 20060723 = 134$.

Constraints and Notes

This problem uses bundled testdata: a subtask is passed if and only if all test points in that subtask are passed.

Subtask ID nn Time Limit Memory Limit Score
11 2020 1s1\operatorname s 500MB500\operatorname{MB} 1515
22 100100 2020
33 200200 0.5s0.5\operatorname s 1010
44 10001000 1s1\operatorname s 1515
55 15001500
66 20002000 5s5\operatorname s 256MB256\operatorname{MB} 1010
77 50005000 2s2\operatorname s 500MB500\operatorname{MB} 1515

For 100%100\% of the data, 0<n50000 < n \le 5000, and 0<ai1090 < a_i \le 10^9.

Translated by ChatGPT 5