cho.sh
Notes
Loading...

Number Grouping

Time limit

2s

Memory limit

128 MB

Problem

You are given an integer sequence of length N. To make the sum as large as possible, you may choose two different numbers and group them together. When two numbers are grouped, their product is added to the total instead of adding the two numbers separately.

Each number may be used in at most one group, and ungrouped numbers are added to the total as they are. Two numbers may be grouped regardless of their positions in the sequence, but an element cannot be grouped with itself.

For example, if the sequence is {0, 1, 2, 4, 3, 5}, the ordinary sum is 15. If 2 is grouped with 3 and 4 is grouped with 5, the total becomes 0 + 1 + (2 * 3) + (4 * 5) = 27, which is larger.

Given the sequence, find the maximum total obtainable by grouping or leaving numbers ungrouped.

Input

The first line contains the size of the sequence, N. N is a positive integer less than 50.

Each of the next N lines contains one integer from the sequence. Each integer is between -1000 and 1000, inclusive.

Output

Print the maximum total obtainable by grouping the numbers optimally. The answer is always less than 2^31.