cswork / OAOpen practice workspace

AmazonOA #260

Max Transfer Rate

Estimated HardJudge-ready

Topics (AI-labelled)Binary SearchTwo PointersStacks & Heaps

Choose pipelineCount distinct ordered index pairs (i,j); each pair contributes throughput[i]+throughput[j]. i=j is allowed, and (i,j) and (j,i) are different; different servers with the same capacity also have different identities. Find the maximum total.

Input

The first line contains n pipelineCount; the second line contains throughput. The original text had no numeric bounds; this site uses 1≤n≤200000, 1≤throughput[i]≤10^9, 1≤pipelineCount≤n²; use 64 bits for K. This site requires the exact integer to be output; the maximum answer 8×10^19 exceeds the signed 64-bit range, and no modulo is taken.

Output

Output a single integer, the answer.

Example 1

Input:

3 4
4 2 5

Output:

36

Example 2

Input:

2 4
2 2

Output:

16

Example 3

Input:

2 3
1 10

Output:

42

Example notes

The answers are 36, 16 and 42. In the third example the top 3 are 20, 11 and 11, and both directions must be counted.

Editorial

Loading solution…