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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//降順
int desc(const void* a, const void* b){
    long p=*(long*)a;
    long q=*(long*)b;
    if(p<q) return 1;
    else if(p>q) return -1;
    else return 0;
}

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-1]に格納する
    long* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%ld",&A[i]);
    }
    qsort(A,N,sizeof(int),desc);

    long* B;
    NEW(B,N);
    int b=0;
    int tmp=1;
    for(int i=1;i<N;i++){
        if(A[i]==A[i-1]) tmp++;
        else{
            if(tmp>=4){
                B[b]=A[i-1];
                B[b+1]=A[i-1];
                b+=2;
            }
            else if(tmp>=2){
                B[b]=A[i-1];
                b++;
            }
            tmp=1;
        }
    }
    if(tmp>=4){
        B[b]=A[N-1];
        B[b+1]=A[N-1];
        b+=2;
    }
    else if(tmp>=2){
        B[b]=A[N-1];
        b++;
    }

    long ans;
    if(b<2) ans=0;
    else ans=B[0]*B[1];
    printf("%ld\n",ans);

    return 0;
}