Problem:
Score : 300 points

Problem Statement

We have N sticks with negligible thickness.
The length of the i-th stick is A_i.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.

Constraints

4 \leq N \leq 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0.

Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.

Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.

Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <iostream>
const int max = 2000;
bool flag[max + 1][max + 1];
int ht[max + 1] = {- 1},S[max + 1];
inline void chk_max(int & x,int y)
{
	if (x < y)
		x = y;
}
main()
{
	std::ios_base::sync_with_stdio(0),std::cin.tie(0);
	int H,W;
	std::cin >> H >> W;
	for (int i = 1;i <= H;++ i)
	{
		std::cin.get();
		for (int j = 1;j <= W;++ j)
			flag[i][j] = std::cin.get() == '#';
	}
	for (int i = 1;i < H;++ i)
	{
		for (int j = 1;j < W;++ j)
			flag[i][j] ^= flag[i + 1][j] ^ flag[i][j + 1] ^ flag[i + 1][j + 1];
		flag[i][W] = 1;
	}
	if (H == 2 || W == 2)
	{
		if (H == 2 && W == 2)
			std::cout << (* flag ? 2 : 4) << '\n';
		else
			std::cout << (* flag && flag[H - 2][W - 2] ? 3 : 6) << '\n';
	}
	else
	{
		int ans = 0;
		for (int i = 1;i < H;++ i)
			for (int top = 0,j = 1;j <= W;++ j)
			{
				ht[j] = flag[i][j] ? 0 : ht[j] + 1;
				while (ht[S[top]] > ht[j])
					chk_max(ans,(j - S[top - 1]) * (ht[S[top]] + 1)),-- top;
				S[++ top] = j;
			}
		std::cout << ans << '\n';
	}
}