CF1805F1.Survival of the Weakest (easy version)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of the problem. It differs from the hard one only in constraints on nn . You can make hacks only if you lock both versions.

Let a1,a2,,ana_1, a_2, \ldots, a_n be an array of non-negative integers. Let F(a1,a2,,an)F(a_1, a_2, \ldots, a_n) be the sorted in the non-decreasing order array of n1n - 1 smallest numbers of the form ai+aja_i + a_j , where 1i<jn1 \le i < j \le n . In other words, F(a1,a2,,an)F(a_1, a_2, \ldots, a_n) is the sorted in the non-decreasing order array of n1n - 1 smallest sums of all possible pairs of elements of the array a1,a2,,ana_1, a_2, \ldots, a_n . For example, F(1,2,5,7)=[1+2,1+5,2+5]=[3,6,7]F(1, 2, 5, 7) = [1 + 2, 1 + 5, 2 + 5] = [3, 6, 7] .

You are given an array of non-negative integers a1,a2,,ana_1, a_2, \ldots, a_n . Determine the single element of the array F(F(FFn1(a1,a2,,an)))\underbrace{F(F(F\ldots F}_{n-1}(a_1, a_2, \ldots, a_n)\ldots)) . Since the answer can be quite large, output it modulo 109+710^9+7 .

输入格式

The first line contains one integer nn ( 2n30002 \le n \le 3000 ) — the initial length of the array.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 0ai1090 \le a_i \le 10^9 ) — the array elements.

输出格式

Output a single number — the answer modulo 109+710^9 + 7 .

输入输出样例

  • 输入#1

    5
    1 2 4 5 6

    输出#1

    34
  • 输入#2

    9
    1 1 1 7 7 7 9 9 9

    输出#2

    256
  • 输入#3

    7
    1 7 9 2 0 0 9

    输出#3

    20
  • 输入#4

    3
    1000000000 1000000000 777

    输出#4

    1540

说明/提示

In the first test, the array is transformed as follows: [1,2,4,5,6][3,5,6,6][8,9,9][17,17][34][1, 2, 4, 5, 6] \to [3, 5, 6, 6] \to [8, 9, 9] \to [17, 17] \to [34] . The only element of the final array is 3434 .

In the second test, F(a1,a2,,an)F(a_1, a_2, \ldots, a_n) is [2,2,2,8,8,8,8,8][2, 2, 2, 8, 8, 8, 8, 8] . This array is made up of 33 numbers of the form 1+11 + 1 and 55 numbers of the form 1+71 + 7 .

In the fourth test, the array is transformed as follows: [109,109,777][109+777,109+777][2109+1554][10^9, 10^9, 777] \to [10^9+777, 10^9+777] \to [2 \cdot 10^9 + 1554] . 2109+15542 \cdot 10^9 + 1554 modulo 109+710^9+7 equals 15401540 .

首页