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

#include<stdio.h>
int main()
{
    long long n,i,a[100000],count=0,t,j,b[10000],C,c,d[100],e,f=0,max;
    scanf("%lld",&n);
     t=0;count=0;e=0;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        for(j=0;j<i;j++)
        {
            if(a[j]==a[i])
            {
                if(count==0)
                {
                b[t]=a[i];
                e++;
                count++;
                }
                else
                {
                if(a[i]!=b[t])
                {
                    t++;
                    e=0;
                  b[t]=a[i];
                }
                if(a[i]==b[t])
                {
                    e++;
                }
                if(e==3||e==4)
                {
                    d[f]=b[t];
                    f++;
                }
                }
                break;
            }
        }
    }
    if(f==0)
    {
    if(t==0)printf("0\n");
    else if(t==1)
    {
        printf("%lld\n",b[0]*b[1]);
    }
    else
    {
    C=b[0];
    for(j=0;j<=t;j++)
    {
        if(C<b[j])
            C=b[j];
    }
    if(C==b[0])
        c=b[1];
   else c=b[0];
    for(j=0;j<=t;j++)
    {
        if(c<b[j]&&b[j]!=C)
        c=b[j];
    }
    printf("%lld\n",C*c);
    }
    }
    else
    {
        max=d[0];
        for(j=0;j<f;j++)
        {
            if(max<d[j])
                max=a[j];
        }
        C=b[0];
        for(j=0;j<=t;j++)
       {
        if(C<b[j])
            C=b[j];
       }
    if(t==0)printf("0\n");
    else
    {
        if(C=b[0])
            c=b[1];
    else
    c=b[0];
    for(j=0;j<=t;j++)
    {
        if(c<b[j]&&b[j]!=C)
        c=b[j];
    }
    if(max*max>C*c)
    {
        printf("%lld\n",max*max);
    }
    else
    printf("%lld\n",C*c);
    }
    }
}