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 (Python):
N = int(input())
d = {}

a = [int(x) for x in input().split()]

for i in a :
    if i not in d.keys() :
        d[i] = 1
    else :
        d[i] += 1

s1 = sorted(d.items(), key = lambda x : x[0], reverse=True)

l1 = -1
l2 = -1

for i in range(N) :
    if s1[i][1] >= 4 and l1 == -1 and l2 == -1:
        l1, l2 = s1[i][0], s1[i][0]
        break
    elif s1[i][1] >= 2 and l1 == -1 :
        l1 = s1[i][0]
    elif s1[i][1] >= 2 and l1 != -1 :
        l2 = s1[i][0]
        break
        
if l1 == -1 or l2 == -1 :
    print("0")
else :
    print(l1 * l2)

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

a, b = 0, 0
idx = 0
while idx < len(A) - 1:
    if A[idx] == A[idx + 1]:
        if a == 0:
            a = A[idx]
            idx += 1
        else:
            b = A[idx]
            break

    idx += 1

print(a * b)

Solution (Python):


from collections import Counter 

N = int(input())
AN = list(map(int, input().split()))


AN_dict = Counter(AN)
AN_list = sorted(AN_dict.items())

hen1 = 0
hen2 = 0

for AN in AN_list:
    
    if AN[1] >= 4:
        hen1 = AN[0]
        hen2 = AN[0]
    
    elif AN[1] >= 2:
        hen2 = hen1
        hen1 = AN[0]      

print(hen1 * hen2)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
d={}
chk=0
for i in a[::-1]:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    if d[i]==4:
        print(i*i)
        exit()
    if d[i]==2 and chk==1:
        for j in d:
           if i!=j and d[j]>=2:
                print(i*j)
                exit()
    elif d[i]==2:
           chk=1
   
print(0)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=1
count=2
i=1
while i<N:
    if count==0:
        break
    if a[i]==a[i-1]:
        ans*=a[i]
        count-=1
        i+=2
    else:
        i+=1    
if count==0:
    print(ans)
else:
    print(0)

Solution (Python):

N=int(input())
a=list(map(int, input().split()))

a.sort()
a.reverse()

count=1
ans=[]

for i in range(N-1):
    if a[i]==a[i+1]:
        count+=1
    else:
        if count//2>0:
            tmp=[a[i], count//2]
            ans.append(tmp)
        count=1
else:
    if count//2>0:
        tmp=[a[i], count//2]
        ans.append(tmp)
        
ans.sort()
ans.reverse()

if len(ans)>0:
    if ans[0][1]>1:
        print(ans[0][0]*ans[0][0])
    else:
        print(ans[0][0]*ans[1][0])
else:
    print(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
max1=0;max2=0
count=0
for i in range(n-3):
  if a[i]==a[i+1]:
    max1=a[i]
    a[i+1]=0
    count=i+1
    break
if count==0:
  print(0)
  exit()
for j in range(count,n-1):
  if a[j]==a[j+1]:
    max2=a[j]
    break
print(max1*max2)

Solution (Python):
from collections import Counter

N = int(input())
A_list = list(map(int, input().split()))
c = Counter(A_list)

l = sorted(c.items(), key=lambda x: x[0], reverse=True)

first = 0
second = 0
square = 0

for i in l:
    k, v = i[0], i[1]
    if v >= 4:
        if square == 0:
            square = k
        if first == 0:
            first = k
        elif second == 0:
            second = k
    elif v >= 2:
        if first == 0:
            first = k
        elif second == 0:
            second = k
print(max(first * second, square * square))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
dic={}
mx=[0,0]
for x in a:
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
    if dic[x]==2:
        dic[x]=0
        for i in range(2):
            mx.sort()
            if mx[i]<x:
                mx[i]=x
                break
print(mx[0]*mx[1])

Solution (Python):
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)

l = None
for k,v in sorted(ctr.items(),reverse=True):
    if l:
        if v >= 2:
            print(l*k)
            exit()
    else:
        if v >= 4:
            print(k*k)
            exit()
        elif v >= 2:
            l = k
print(0)

Solution (Python):

n=int(input())
a=list(map(int,input().split()))
dic={}
mx=[0,0]
for x in a:
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
    if dic[x]==2:
        dic[x]=0
        for i in range(2):
            mx.sort()
            if mx[i]<x:
                mx[i]=x
                break
print(mx[0]*mx[1])

Solution (Python):

N = int(input())
A = list(map(int, input().split()))

A = sorted(A, reverse = True)
pair = 0
ans = []

i = 0
while i < N - 1:
    if A[i] == A[i + 1]:
        ans.append(A[i])
        pair += 1
        i += 2
    else:
        i += 1
    if pair == 2:
        print(ans[0] * ans[1])
        break

if pair < 2:
    print(0)

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]

import collections

c = collections.Counter(A)
xs = [x for x, n in c.items() if n >= 2]
xs.sort()

if len(xs) >= 1 and c[xs[-1]] >= 4:
    print(xs[-1] ** 2)
elif len(xs) >= 2:
    print(xs[-1] * xs[-2])
else:
    print(0)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
top1 = 0
top2 = 0
c = Counter()

for a in A:
    c[a] += 1
    if c[a] % 2 == 0:
        L = [a, top1, top2]
        L.sort()
        top1 = L[2]
        top2 = L[1]
print(top1 * top2)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
import collections
k=list(collections.Counter(a).items())
x=[k[i][0] for i in range(len(k)) if k[i][1]>=2]
y=[k[i][0] for i in range(len(k)) if k[i][1]>=4]
x.sort()
y.sort()
if len(x)>1 and len(y)>1:
    print(max(x[-1]*x[-2], y[-1]**2))
elif len(x)>1:
    print(x[-1]*x[-2])
else:
    print(0)

Solution (Python):
N=int(input())

a=list(map(int,input().split()))

a.sort(reverse=True)
TATE=0
count=0

for i in range(N):
  if i!=N-1 and a[i]==a[i+1] and count!=1:
    if TATE==0:
      TATE=a[i]
      i+=1
      count=1
    else:
      YOKO=a[i]
      print(TATE*YOKO)
      exit()
  else:
    count=0

print(0)

Solution (Python):


n = int(input())
A = list(map(int, input().split()))

B = {}
for a in A:
    if a not in B:
        B[a] = 1
    else:
        B[a] += 1

C = []
for b in B.keys():
    if B[b] >= 4:
        C.append(b)
        C.append(b)
    elif B[b] >= 2:
        C.append(b)

C.sort(reverse=True)

if len(C):
    print(C[0] * C[1])
else:
    print(0)

Solution (Python):
from collections import Counter

N = int(input())
input_list = sorted([int(i) for i in input().split()])
inupt_dict = Counter(input_list)
sorted_input_dict = sorted(dict(filter(lambda x:x[1]>1, inupt_dict.items())).items(), key=lambda x: x[0], reverse=True)
result = 1

if sorted_input_dict == []:
    result = 0
else:
    result *= sorted_input_dict[0][0]
    if sorted_input_dict[0][1] > 3:
        result *= sorted_input_dict[0][0]
    else:
        result *= sorted_input_dict[1][0]

print(result)

Solution (Python):
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
for i in a:
    dic[i] += 1

t = sorted(set(a), reverse=True)
rec = []
flag = False
for k in t:
    if dic[k] >= 4 and len(rec) == 1:
        print(k * rec[0])
        flag = True
        break
    elif dic[k] >= 4:
        print(k * k)
        flag = True
        break
    elif dic[k] >= 2 and len(rec) == 1:
        print(k * rec[0])
        flag = True
        break
    elif dic[k] >= 2:
        rec.append(k)

if not flag:
    print(0)

Solution (Python):
from collections import Counter

a = input()
a = map(int,input().split())
a = Counter(a)
li = []
for i,v in sorted(a.items(),key = lambda x: x[0],reverse = True):
    if(v >= 2 and v < 4):
        li.append(i)
    elif(v >= 4):
        li.extend([i,i])
    if(len(li) >= 2):
        print(li[0]*li[1])
        exit()
print(0)

Solution (Python):
N = int(input())






A = list(map(int, input().split()))
A.sort()
A.reverse()


tapu = 0
tapi = 0

i = 0
while i + 1 < N:
    if A[i] == A[i + 1]:
        if tapu == 0:
            tapu = A[i]
            i += 1
        elif tapi == 0:
            tapi = A[i]
            i += 1
            break
    i += 1

ans = tapu * tapi
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse = True)

T = []
for i in range(N-1):
    if i > 1 and  A[i] == A[i-1] and not(A[i] == A[i-2]): continue
    if i == 1 and A[i] == A[i-1]: continue

    if A[i] == A[i+1]:
        T.append(A[i])
    if len(T) >= 2: break

if len(T) < 2: print(0)
else: print(T[0]*T[1])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
dict = {}
for i in a:
    if(i in dict):
        dict[i] += 1
    else:
        dict[i] = 1
dict = sorted(dict.items(), reverse = True)
for i in dict:
    if(i[1] >= 2):
        if(ans):
            print(ans*i[0])
            exit()
        else:
            ans = i[0]
        if(i[1] >= 4):
            print(ans*i[0])
            exit()
print(0)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
b = []
m = 2
x = a[0]
for i in range(1,n):
    if a[i] == x:
        b.append(x)
        m -= 1
        if m == 0:
            break
        x = -1
    else:
        x = a[i]
if len(b) < 2:
    print(0)
else:
    print(b[0]*b[1])

Solution (Python):
from collections import Counter
input();a=sorted(Counter(map(int,input().split())).most_common())[::-1];c=b=0
for i in range(len(set(a))):
    if b and c:break
    if a[i][1]>3 and a[i][0]*c<a[i][0]**2:b=c=a[i][0]
    elif a[i][1]>1:b,c=c,a[i][0]
print(c*b)

Solution (Python):
def m():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    edge = []
    tmp = 0
    for i in range(N):
        if A[i] == tmp:
            edge.append(tmp)
            tmp = 0
        else:
            tmp = A[i]
    if len(edge) < 2:
        return 0
    else:
        return edge[-1] * edge[-2]

print(m())

Solution (Python):
def c_make_a_rectangle(N, A):
    from collections import Counter
    count = Counter(A)  
    cond = []  
    for k, v in count.items():
        cond.extend([k] * (v // 2))  
    if len(cond) <= 1:
        return 0  
    cond = sorted(cond, reverse=True)
    ans = cond[0] * cond[1]  
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_make_a_rectangle(N, A))

Solution (Python):
def judge(lst):
	x = 0
	y = 0
	memo = 0
	for i in range(0, len(lst)-1):
		if lst[i] == lst[i+1]:
			x = lst[i]
			memo = i
			break
	for i in range(memo+2, len(lst)-1):
		if lst[i] == lst[i+1]:
			y = lst[i]
			break
	return x*y

N = int(raw_input())
A = map(int, raw_input().split())
A.sort(reverse=True)

print judge(A)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
Adict = {}
for i in A:
    if i in Adict:
        Adict[i]=Adict[i]+1
    else:
        Adict.update({i:1})
B = [0, 0]
for i in Adict.keys():
    if Adict[i] >= 2:
        B.append(i)
    if Adict[i] >= 4:
        B.append(i)
B.sort()
print(B[-1]*B[-2])

Solution (Python):
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
B = [0, 0]
for i in A.keys():
    if A[i] >= 2:
        B.append(i)
    if A[i] >= 4:
        B.append(i)
B.sort()
print(B[-1]*B[-2])

Solution (Python):
N = int(input())
A = list(map(int, input().split(' ')))
rod = {}
for i in A:
    if i in rod:
        rod[i] += 1
    else:
        rod[i] = 1
if len([i for i in rod.values() if i >= 2]) < 2:
    print(0)
else:
    length4 = [k for k, v in rod.items() if v >= 4]
    length4.sort()
    length2 = [k for k, v in rod.items() if v >= 2]
    length2.sort()
    if len(length4) > 0 and length4[-1] == length2[-1]:
        print(length4[-1]**2)
    else:
        print(length2[-2] * length2[-1])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
data=Counter(a)
two=[0]*n
four=[0]*n
for i,j in data.items():
    if 2<=j<=3:
        two.append(i)
    elif 4<=j:
        four.append(i)
two.sort()
two.reverse()
four.sort()
four.reverse()
print(max(four[0]*four[0],four[0]*four[1],two[0]*two[1],two[0]*four[0]))

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

C = list(dict(Counter(A)).items())
C.sort(reverse=True)
use = []
ans = 0
for length, num in C:
    if num >= 4:
        ans = max(length**2, ans)
        use.append(length)
    elif num >= 2:
        use.append(length)

    if len(use) >= 2:
        ans = max(ans, use[-1]*use[-2])

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = sorted(Counter(A).most_common(),reverse=True)
D = list(filter(lambda x: x[1]>=2,C))
if len(D)<2:
    print(0)
else:
    print(D[0][0]**2 if D[0][1]>=4 else D[0][0]*D[1][0])

Solution (Python):
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)
a = b = 0
for k,v in sorted(ctr.items(),reverse=True):
    if v == 1: continue
    if not a:
        a = k
        if v >= 4:
            print(a*a)
            exit()
    elif not b:
        b = k
        print(a*b)
        exit()
print(0)

Solution (Python):





if __name__ == '__main__':
    from collections import Counter

    n = int(input())
    a = Counter(list(map(int, input().split())))
    sorted_a = sorted(a.items(), key=lambda x: (x[0], x[1]), reverse=True)
    squares = [key for key, value in sorted_a if value >= 4]
    rectangles = [key for key, value in sorted_a if value >= 2]

    if (len(squares) >= 1) and (len(rectangles) >= 2):
        print(max(squares[0] ** 2, rectangles[0] * rectangles[1]))
    elif (len(squares) >= 1) and (len(rectangles) < 2):
        print(squares[0] ** 2)
    elif len(rectangles) >= 2:
        print(rectangles[0] * rectangles[1])
    else:
        print(0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a_dic = {}

a.sort(reverse=True)
for i in a:
    a_dic[i] = a_dic.get(i, 0) + 1

h = [0, 0]
for i in range(2):
    for j in a:
        if a_dic[j] >= 2:
            h[i] = j
            a_dic[j] -= 2
            break

print(h[0]*h[1])

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)

c = 0
t = 0

for k in B:
    if k*k > c*t and B[k] >= 4:
        c = k
        t = k
    elif c >= k > t and B[k] >= 2:
        t = k
    elif k > c and B[k] >= 2:
        t = c
        c = k

print(t*c)

Solution (Python):
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split()))).most_common()
fA = filter(lambda x: x[1] >= 2, A)
sA = sorted(fA,reverse=True)
if len(sA) < 2:
    print(0)
else:
    print(sA[0][0]**2 if sA[0][1]>=4 else sA[0][0]*sA[1][0])

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
b=Counter(a)
c=[0,0]
for i in b.keys():
    if b[i]>=2: c.append(i)
    if b[i]>=4: c.append(i)
c.sort()
print(c[-1]*c[-2])

Solution (Python):
from collections import defaultdict

N=int(input())
A=[int(x) for x in input().split()]
dict=defaultdict(int)

for i in range(N):
  dict[A[i]]+=1

ans=[]
for x,y in dict.items():
  if 2 <= y < 4:
    ans.append(x)
  elif y>=4:
    ans.append(x)
    ans.append(x)
  else:
    continue
if len(ans) < 2:
  print(0)
else:
  ans.sort(reverse=True)
  print(ans[0]*ans[1])

Solution (Python):
N=int(input())
d,t={},[]
for i in list(map(int,input().split())):
    d[i]=d.get(i,0)+1
d=sorted(list(d.items()))
for j in range(len(d)):
    k=len(d)-j-1
    if d[k][1]>3:
        if len(t)==0:
            print((d[k][0])**2)
            exit()
    if d[k][1]>1:
        t.append(d[k][0])
        if len(t)==2:
            print(t[0]*t[1])
            exit()
print(0)

Solution (Python):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
s = defaultdict(int)
for v in a: s[v]+=1
edge = []
for v in s.items():
    if v[1] > 1: edge.append(v[0])
    if v[1] > 3: edge.append(v[0])
(edge).sort()
if len(edge)>1:
    print(edge[-1]*edge[-2])
else:
    print(0)

Solution (Python):
from collections import Counter

def max_rectangle(sticks):
    
    valid_lengths = list(filter(lambda x: sticks[x] >= 2, sorted(sticks, reverse=True)))
    if valid_lengths and sticks[valid_lengths[0]] >= 4:
        return valid_lengths[0] ** 2
    if len(valid_lengths) >= 2:
        return valid_lengths[0] * valid_lengths[1]
    return 0


if __name__ == '__main__':
    _ = input()
    sticks = Counter(map(int, input().split()))
    print(max_rectangle(sticks))

Solution (Python):
def c_make_a_rectangle(N, A):
    from collections import Counter
    count = Counter(A)  

    cond = []  
    for k, v in count.items():
        if v == 1:  
            continue
        else:
            cond.extend([k] * (v // 2))
    if len(cond) <= 1:
        return 0  
    cond = sorted(cond, reverse=True)
    ans = cond[0] * cond[1]  
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_make_a_rectangle(N, A))

Solution (Python):
d = {}
_ = input()
for x in input().split():
    x = int(x)
    d[x] = d.get(x, 0) + 1
p = []
for k, v in d.items():
    if v >= 4: p.append(k)
    if v >= 2: p.append(k)
if len(p) < 2: print(0)
else:
    p.sort(reverse=True)
    print(p[0] * p[1])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A,reverse=True)
first = 0
bef = 0
count = 0
for i in A:
    if count == 0 or i == bef:
        count += 1
    if count >= 2:
        if first != 0:
            print(first*i)
            exit()
        else:
            first = i
            count = 0
    if bef != i:
        count = 1
    bef = i
print(0)

Solution (Python):
import math
import sys

def getinputdata():

    
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
arr01=arr_data[1]

hash01={}

for v in arr01:
    
    cnt=hash01.setdefault(int(v),0)+1
    
    hash01[int(v)]=cnt
    


menseki01=None
menseki02=None

a=None
b=None

for k, v in sorted(hash01.items(), reverse=True):
    

    
    if(v>=2 and a is None):
    
    

        a=k
        
    elif(v>=2 and a is not None and b is None):
    

        b=k
        menseki02=a*b
    
    if(v>=4 and menseki01 is None):
        
        menseki01=k*k
        

if menseki01 is None and menseki02 is None:
     
     print(0)


elif menseki01 is None and menseki02 is not None:

     print(menseki02)

elif menseki01 is not None and menseki02 is None:
     
    
     print(menseki01)

elif menseki01 is not None and menseki02 is not None:
     
    
    if menseki01 <= menseki02:

        print(menseki02)
        
    else:
        print(menseki01)

Solution (Python):
import collections
n = int(input())
a = [int(i) for i in input().split()]
x,y,z = collections.Counter(a),[0],[0,0]
for i in x.keys():
	if x[i]>=4:
		y.append(i)
	if x[i]>=2:
		z.append(i)
y,z = sorted(y),sorted(z)
print(max(y[-1]**2,z[-1]*z[-2]))

Solution (Python):
N = int(input())
num = list(map(int,input().split()))
dict = {}
dist = []
for i in range(N):
  if num[i] not in dict:
    dict[num[i]] = 1
    dist.append(num[i])
  else:
    dict[num[i]] += 1
dist.sort(reverse=True)
rec = []    
for j in range(len(dist)):
  if 4 <= dict[dist[j]]:
    rec.append(dist[j])
    rec.append(dist[j])
    break
  elif 2<= dict[dist[j]]:
    rec.append(dist[j])
  if 2 <= len(rec):
    break
if len(rec) < 2:
  print(0)
else:
  print(rec[0]*rec[1])

Solution (Python):

N=int(input())
Set=set()
List=[]
Data=list(map(int,input().split()))

for i in range(N):
    if Data[i] not in Set:
        Set.add(Data[i])
    else:
        Set.remove(Data[i])
        List.append(Data[i])
if len(List)<2:print("0")
else:
    List=sorted(List)
    print(List[-1]*List[-2])

Solution (Python):
n = int(input())
li = set()
lis = []
l = list(map(int,input().split()))
for i in range(n):
    if l[i] not in li:
        li.add(l[i])
    else:
        lis.append(l[i])
        li.remove(l[i])
if len(lis) < 2:
    print("0")

else:
    lis = sorted(lis)
    print(lis[-1] * lis[-2])

Solution (Python):

n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
cnt = {}
tmp = None
for a in A:
    cnt[a] = cnt.get(a, 0) + 1 
    if cnt[a]>=4:
        print(a*a)
        break
    if cnt[a]==2:
        if tmp:
            print(tmp*a)
            break
        tmp=a
else:
    print(0)

Solution (Python):
import collections

n = int(input())

array = [int(x) for x in input().split()]

count = collections.Counter(array)
count_values = list(count.values())
if count_values.count(1) >= len(count_values) - 1:
    print(0)
else:
    count = list(sorted(count.items(), key=lambda x: x[0], reverse=True))
    res_count = []
    for i in count:
        if i[1] != 1:
            res_count.append(i)
    if res_count[0][1] >= 4:
        print(res_count[0][0] ** 2)
    else:
        print(res_count[0][0] * res_count[1][0])

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
ans=[]

a.sort()
a.reverse()

flag=False
for i in range(n-1):
	if flag:
		flag=False
		continue
	if a[i]==a[i+1]:
		ans.append(a[i])
		flag=True
		if len(ans)==2:
			break
if len(ans)<2:
	print(0)
else:
	print(ans[0]*ans[1])

Solution (Python):
from collections import Counter
n = int(input())
j = Counter(list(map(int, input().split())))
l = r = 0
for m, b in sorted(list(j.items()), key=lambda x: -x[0]):
    if b > 3 and (not l and not r):
        print(m * m)
        exit()
    if b > 1 and (not l or not r):
        if not l:
            l = m
        elif not r:
            r = m
print(l * r)

Solution (Python):
from collections import *
n=int(input())
a=list(map(int,input().split()))
b=sorted(set(a))[::-1]
d=defaultdict(int)
wid=0
hei=0
for i in a:
  d[i]+=1
for i in b:
  if(d[i]>3):
    if(wid==0):wid,hei=i,i
    else:hei=i
    break
  elif(d[i]>1):
    if(wid==0):wid=i
    else:
      hei=i
      break
print(wid*hei)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
import collections
data=collections.Counter(a)
a=[]
a_4=[]
for i,j in data.items():
    if 4<=j:
        a_4.append(i)
    elif 2<=j:
        a.append(i)
x=y=z=0
a.sort()
a.reverse()
a_4.sort()
a_4.reverse()

if len(a_4)==0 and len(a)<=1:
    print(0)
    exit()
if 1<=len(a_4) and 1<=len(a):
    x=a[0]*a_4[0]
if 2<=len(a):
    y=a[0]*a[1]
if 1<=len(a_4):
    z=a_4[0]*a_4[0]
print(max(x,y,z))

Solution (Python):
import sys
line = sys.stdin.readline
n = int(line())
a = list(map(int, line().split()))
h = 0
from collections import Counter
counter = Counter(a)
for key in sorted(counter.keys(), reverse = True):
    if h and counter[key] >= 2:
        print(h * key)
        sys.exit()
    if counter[key] >= 4:
        print(key * key)
        sys.exit()
    if counter[key] >= 2:
        h = key
print(0)

Solution (Python):
import sys
line = sys.stdin.readline

n = int(line())
a = list(map(int, line().split()))
a.sort(reverse=True)
summ = 0
h = 0
for i in range(len(a)):
    summ += 1
    if i and a[i] != a[i-1]:
        summ = 1
    if summ == 2:
        if h:
            print(a[i] * h)
            sys.exit()
        else:
            h = a[i]
    if summ == 4:
        print(a[i] * a[i])
        sys.exit()
print(0)

Solution (Python):
n=input()
a=[int(i) for i in input().split()]
a.sort(reverse=True)


x1=0
x2=0
i0=0
for i in a:
  if i==i0 and x1==0 and x2==0:
    x1=i
    i0=0
  elif i==i0 and x2==0:
    x2=i
    i0=0
  else:
    i0=i
print(x1*x2)

Solution (Python):
from collections import  Counter
n =int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
num = []

for k,v in c.items():
    if v >= 2:
        num.append([k,v])

if len(num) ==0:
    print(0)
else:
    k = sorted(num,reverse=True)
    l = k[0][0]
    s = k[1][0]
    if k[0][1] >= 4:
        print(l*l)
    else:
        print(l*s)

Solution (Python):
import collections
import sys
N = int(input())
A = map(int,input().split(" "))
count_input = collections.Counter(A)
del count_input[" "]
judge = True
m1 = 0
m2 = 0
count = 0
temp_max=0
for k,v in sorted(count_input.items(),reverse = True):
    
    if temp_max<=k:
        temp_max=k
    
        
        
    if int(v) >= 4 and temp_max<=k:
        print(k**2)
        sys.exit()
    elif int(v) >= 2:
        m2 = m1
        m1 = int(k)
        count += 1
        if count ==2:
            print(m1*m2)
            sys.exit()
print("0")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
data=Counter(a)
two_i=[]
four_i=[]
for i,j in data.items():
    if 4<=j:
        four_i.append(i)
    elif 2<=j:
        two_i.append(i)
two_i.sort()
four_i.sort()
two_i.reverse()
four_i.reverse()
if len(four_i)==0:
    four_i.append(0)
if len(two_i)<=1:
    two_i.append(0)
    two_i.append(0)
four_area=four_i[0]*four_i[0]
two_area=two_i[0]*two_i[1]
mix_area=two_i[0]*four_i[0]
print(max(four_area,two_area,mix_area))

Solution (Python):
N = int(input())
st = input().split()
A = [0 for i in range(N)]
for i in range(N):
  A[i] = int(st[i])

A.sort(reverse = True)
U = []
for i in range(N-1):
  if A[i] == A[i+1]:
    U.append(A[i])
    A[i] = -1
    A[i+1] = -1
  if len(U) >= 2:
    break
if len(U) >= 2:
	print(U[0] * U[1])
else:
  print(0)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
dic = {}

for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

a, b = 0, 0

for k,v in sorted(dic.items(), key=lambda x : -x[0]):
    if a==0:
        if 4 <= v:
            a, b = k, k
            break
        elif 2 <= v:
            a = k
    elif 2 <= v:
        b = k
        break

if not a==0 or not b==0:
    print(a*b)
else:
    print(0)

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    A = sorted(A, reverse=True)
    width, height = 0, 0
    cnt = 0
    last_val = -1
    for i, A_i in enumerate(A):
        if last_val == A_i:
            if width == 0:
                width = max(A_i, width)
                last_val = 0
            elif height == 0:
                height = max(A_i, height)
        else:
            cnt = 0
            last_val = A_i
        if width * height > 0:
            print(width * height)
            return
        
    print(0)
    return


solve()

Solution (Python):
from collections import Counter

n = int(input())
cnt = Counter()
for x in map(int, input().split()):
    cnt[x] += 1

xs = sorted(cnt.items(), key=lambda x: x[0])

def find_pair():
    while xs:
        x = xs.pop()
        if x[1] >= 2:
            xs.append((x[0], x[1] - 2))
            return x[0]
        else:
            continue
    return 0

a = find_pair()
b = find_pair()
print(a*b)

Solution (Python):
N = int(input())
P = list(map(int,input().split()))
P.sort(reverse=True)
a = 0
b = 0
for i in range(N-1):
    if P[i] > 0:
        if a == 0:
            if P[i] == P[i+1]:
                a = P[i]
                P[i] = -i
                P[i+1] = -i -1
        elif b == 0:
            if P[i] == P[i+1]:
                b = P[i]
                P[i] = -i
                P[i+1] = -i -1
        else:
            break
    else:
        continue
ans = a * b
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

d = {}
for e in A:
    if e not in d:
        d[e] = 1
    else:
        d[e] = d[e] + 1

edges = []
for k, v in d.items():
    if v >= 4:
        edges.append(k)
        edges.append(k)
    elif v >= 2:
        edges.append(k)

if len(edges) <= 1:
    print(0)
else:
    edges.sort()
    print(edges[-1] * edges[-2])

Solution (Python):

input()
xs = map(int, input().split())

d = dict()
for x in xs:
    if x in d.keys():
        d[x] += 1
    else:
        d[x] = 1

res = 0
for x, c1 in d.items():
    if c1 >= 4:
        if res < x * x: res = x * x

v = sorted(list(map(lambda s: s[0], (filter(lambda x: x[1] >= 2, d.items())))), reverse=True)

if len(v) >= 2:
    if res < v[0] * v[1]: res = v[0] * v[1]

"""
    for y, c2 in d.items():
        if x != y and c1 >= 2 and c2 >= 2:
            if res < x * y: res = x * y
"""


print(res)

Solution (Python):
N = int(input())
A = list(map(int,input().split(" ")))
over2 = []
num = {}

for length in A:
	if length in num:
		num.pop(length)
		over2.append(length)
	else:
		num[length] = 1


over2.sort()

if len(over2) >= 2:
	print(over2[-1]*over2[-2])
else:
	print(0)

Solution (Python):
n = int(input())
li = list(map(int, input().split()))

li.sort(reverse=True)

vert = {}
even = []
ans = 0

for i in li:
	if i in vert:
		vert.pop(i)
		even.append(i)
		if len(even) == 2:
			ans = even[0] * even[1]
			break
	else:
		vert[i] = 1
print(ans)

Solution (Python):
N = int(input())
lis = list(map(int,input().split()))
lis.sort()
a = lis[0];fir=0;sec=0;torf=False
for i in range(N-1):
    if torf:
        torf = False
    elif a == lis[i+1]:
        if a > fir:
            sec = fir
            fir = a
            torf = True
        elif a > sec:
            sec = a
            torf = True
    a = lis[i+1]

print(fir*sec)

Solution (Python):
N = int(input())
lis = list(map(int,input().split()))
lis.sort()
a = lis[0];fir=0;sec=0;torf=False
for i in range(N-1):
    if torf:
        torf = False
    elif a == lis[i+1]:
        if a > fir:
            sec = fir
            fir = a
            torf = True
        elif a > sec:
            sec = a
            torf = True
    a = lis[i+1]

print(fir*sec)

Solution (Python):

from collections import Counter
import sys

n = int(input())
a = list(map(int,input().split()))
cnt = Counter(a)
cntsort = sorted(cnt.items())[::-1]
h = 0
flg2 = False
for k, v in cntsort:
    if(v>=4 and flg2==False):
        print(k*k)
        sys.exit()
    elif(v>=2 and flg2==False):
        flg2 = True
        h = k
    elif(v>=2 and flg2==True):
        print(h*k)
        sys.exit()
else:
    print(0)

Solution (Python):


N = int(input())
A = list(map(int, input().split(" ")))

A.sort()

rectangle_edges = []
prev_edge = A[N - 1]
for i in reversed(range(N - 1)):
    if A[i] == prev_edge:
        rectangle_edges.append(A[i])
        if len(rectangle_edges) == 2:
            break
        prev_edge = -1
    else:
        prev_edge = A[i]

if len(rectangle_edges) != 2:
    print(0)
else:
    print(int(rectangle_edges[0] * rectangle_edges[1]))