Interesting Array

Time limit: 1s Memory limit: 256MB Input: Output:

You are given an array of NN elements. You are required to find the interval that is the most interesting.

We measure the value of interest of an interval as the product between AA and BB, where AA is the frequency of the rarest element in the interval and BB is the frequency of the most common element. So, for the array {1,3,2,3,1,2,3}\{1, 3, 2, 3, 1, 2, 3\} we choose A=2A = 2 and B=3B = 3 for the interval [1,7][1, 7].

Input

The first line of the input will contain the integer NN (1N100 0001 \leq N \leq 100\ 000).
The second line of the input will contain NN integers separated by space representing the values of the array (the values will be between 11 and NN).

For 20%20\% of the points, 1N2 0001 \leq N \leq 2\ 000.

Output

The output will contain only one integer representing the highest value asked in the statement.

Example

stdin

5
1 2 1 3 2

stdout

2

Explanation

In the sample you may choose the intervals [1,3][1, 3], [1,5][1, 5] or [2,5][2, 5]; all of them have the rarest occurence of once (22 appears once in the interval [1,3][1, 3]) and the most common occurence of twice (11 appears twice in the interval [1,3][1, 3]).
Finally, 12=21 \cdot 2 = 2.

Log in or sign up to be able to send submissions!