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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void myout(Object text){System.out.println(text);}
	public static String getStr(){return sc.next();}
	public static int getInt(){return sc.nextInt();}
	public static Long getLong(){return sc.nextLong();}
	public static boolean isNext(){return sc.hasNext();}
	public static void main(String[] args){
		//String tmp = getStr();
		//int tmp = getInt();
		//Long tmp = getLong();
      int N = getInt();
      ArrayList<Integer> list = new ArrayList<Integer>();
      for(int i = 0; i < N; i++){
        list.add(getInt());
      }
      Collections.sort(list,Comparator.reverseOrder());
      //同じ値が2個*2種類、または4個*1種類出現していればひとまず問題ない
      
      ArrayList<Integer> hindo = new ArrayList<Integer>();
      int[] countList = new int[100000];
      Arrays.fill(countList,0);
      int counter = 0;
      for(int i = 0; i < N; i++){
        int tmp = list.get(i);
        if(i == 0){
          hindo.add(tmp);
          countList[0] = 1;
          continue;
        }
        if(hindo.get(counter) == tmp){
          countList[counter]++;
        }else{
          hindo.add(tmp);
          countList[counter + 1]++;
          counter++;
        }
      }
      int fourCount = -1;
      int twoCount1 = -1;
      int twoCount2 = -1;
      Long fourMen = new Long(-1);
      Long twoMen = new Long(-1);
      for(int i = 0; i < N; i++){
        if(countList[i] == 4){
          Long tmpLong = new Long(hindo.get(i));
          fourMen = tmpLong * tmpLong;
          break;
        }
      }
      for(int i = 0; i < N; i++){
        if(countList[i] >= 2){
          if(twoCount1 == -1){
            twoCount1 = hindo.get(i);
            continue;
          }else if(twoCount2 == -1){
            twoCount2 = hindo.get(i);
            twoMen = new Long(twoCount1) * new Long(twoCount2);
            break;
          }
        }
      }
      if(fourMen != -1 && twoMen != -1){
        myout(Math.max(fourMen, twoMen));
      }else if(fourMen != -1 && twoMen == -1){
        myout(fourMen);
      }else if(fourMen == -1 && twoMen != -1){
        myout(twoMen);
      }else{
        myout(0);
      }
	}
}