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):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
cnt = Counter(LI())
L = []
for k, v in cnt.items():
    if v >= 4:
        L += [k] * 2
    elif v >= 2:
        L += [k]


L.sort(reverse=True)


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

Solution (Python):

from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
rod1 = 0
rod2 = 0
A = sorted(A)[::-1]
for i in range(len(A)-2):
    if rod1:
        i += 1
    
    if A[i] == A[i+1]:
        if rod1:
            rod2 = A[i]
        else:
            rod1 = A[i]
    if rod1 and rod2:
        break

if (not rod1) and (not rod2):
    print(0)
else:
    print(rod1*rod2)

Solution (Python):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
C=sorted(Counter(A).items(),key=lambda x:x[0],reverse=True)
m=len(C)
for i in range(m):
    if C[i][1]>=4:
        print(C[i][0]**2)
        exit()
    elif C[i][1]>=2:
        a=C[i][0]
        for j in range(i+1,m):
            if C[j][1]>=2:
                print(a*C[j][0])
                exit()
print(0)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


from collections import Counter

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

c = Counter(A)


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

    elif v >= 2:
        key.append(k)

if len(key) < 2:
    print(0)
    exit()

key.sort(reverse=True)
print(key[0]*key[1])

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

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

    dic = {}
    for t in a:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    
    ans = []
    ok = False
    for l, count in sorted(dic.items(), reverse=True):
        if count >= 4:
            if len(ans) == 0:
                print(l*l)
                ok = True
                break
            else:
                print(ans[0] * l)
                ok = True
                break
        elif count >= 2:
            if len(ans) == 1:
                print(ans[0] * l)
                ok = True
                break
            else:
                ans.append(l)

    if not ok:
        print(0)

if __name__ == "__main__":
    main()

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

li=[]

for i,j in dic.items():
    if j>=2:
        li.append(i)
    if j>=4:
        li.append(i)
li.sort()


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

Solution (Python):
from collections import Counter

N = int(input().strip())
A = Counter(list(map(int, input().strip().split(' '))))
tmp = 0
for k,v in sorted(A.items(), reverse=True):
  if v >= 4:
    if tmp > 0:
      print(k*tmp)
      exit()
    else:
      print(k*k)
      exit()
  elif v >= 2:
    if tmp > 0:
      print(k*tmp)
      exit()
    else:
      tmp = k
print(0)

Solution (Python):
import collections

N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = []
for a,c in B.items():
    C += [a] * (c//2)
C.sort()

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

Solution (Python):
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
c = Counter(li)
hen = [i[0] for i in c.items() if i[1] >= 2]
hen2 = [i for i in hen if c[i] >= 4]
hen.sort()
if len(hen) <= 1:
    if len(hen2) == 0:
        print(0)
    else:
        print(max(hen2) ** 2)
else:
    if len(hen2) == 0:
        print(hen[-1] * hen[-2])
    else:
        print(max(hen[-1] * hen[-2], max(hen2) ** 2))

Solution (Python):
c={}
input()
for i in list(map(int,input().split())):
    if i in c:
        c[i]+=1
    else:
        c[i]=1
d=[i for i in c.items() if i[1]>1]
c=sorted(d)
if len(d)==0 or (len(d)==1 and c[-1][1]<4):
    print(0)
else:
    if c[-1][1]>3:
        print(c[-1][0]**2)
    else:
        print(c[-1][0]*c[-2][0])

Solution (Python):


import collections

N = int(input().split()[0])
a_list = list(map(int, input().split()))

counter = collections.Counter(a_list)
count_dict = {k: v for k, v in counter.items() if v >= 2}
if count_dict:
    length_list = sorted(list(count_dict.keys()), reverse=True)

    if len(length_list) == 1 and counter[length_list[0]] < 4:
        area = 0
    elif counter[length_list[0]] >= 4:
        area = length_list[0] ** 2
    else:
        area = length_list[0] * length_list[1]
else:
    area = 0

print(area)

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
arr.reverse()

b = [0,0]

ind = 0
bef = -1
for a in arr:
    if a != bef:
        bef = a
    else:
        b[ind] = a
        ind += 1
        bef=-1
    if ind > 1:
        break

if ind > 1:
    print(b[0]*b[1])
else:
    print(0)

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

tmp1 = 0
tmp2 = 0
flg = True

for i in range(N-1):
    if A[i] == A[i+1] and tmp1 == 0 and flg:
        tmp1 = A[i]
        flg = False
    elif A[i] == A[i+1] and tmp2 == 0 and flg:
        tmp2 = A[i]
        break
    else:
        flg = True

print(tmp1 * tmp2)

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

A.sort(reverse=1)

R = [0, 0]
r_ind = 0
a_ind = 0
while r_ind < 2 and a_ind < n-1:
    if A[a_ind] == A[a_ind + 1]:
        R[r_ind] = A[a_ind]
        a_ind += 2
        r_ind += 1
    else:
        a_ind += 1

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

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = []
n = inp()
a = inpl()
aa = set(a)
aa = sorted(list(aa),reverse=True)

d = defaultdict(int)

for key in a:
    d[key] += 1
for i in aa:
    if d[i] >= 4:
        if ans == []:
            print(i**2)
            quit()
    if d[i] >= 2:
        ans.append(i)
        if len(ans) == 2:
            print(ans[0]*ans[1])
            quit()
print(0)

Solution (Python):
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split())))
s = []
for k, v in sorted(a.items(), key=lambda x: -x[0]):
    
        
    if v > 1:
        s.append(k)
        if len(s) > 1:
            print(s[0] * s[1])
            exit()

    if v >= 4:
        print(k ** 2)
        exit()
print(0)

Solution (Python):
import collections

n=int(input())
a=list(map(int, input().split()))  
a = collections.Counter(a)
a=a.most_common()
b=0
c=0
a.sort(key=lambda x:x[0])

for i in range(len(a)):
    if a[len(a)-i-1][1]>=4:
        if b==0:
            b=a[len(a)-i-1][0]
            print(b**2)
            exit()
            
    if a[len(a)-i-1][1]>=2:
        if b==0:
            b=a[len(a)-i-1][0]
        else:
            c=a[len(a)-i-1][0]
            print(b*c)
            exit()
        
print(0)

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
cnt = sorted(collections.Counter(A).items())
cnt_2 = [x for x in cnt if x[1] >= 2]
if len(cnt_2) == 0:
    print(0)
elif cnt_2[-1][1] >= 4:
    print((cnt_2[-1][0])**2)
else:
    if len(cnt_2) == 1:
        print(0)
    else:
        print(cnt_2[-1][0]*cnt_2[-2][0])

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

a.sort(reverse= True)

cnt = 0
top = []

for i in range(n-1):
    
    if len(top) == 2:
        break    
    if a[i] == a[i+1]:
        if len(top) == 2:
            break
        if cnt%2 == 0:
            top.append(a[i])
        cnt += 1
    else:
        cnt = 0

if len(top) < 2:
    print(0)
    exit()

print(int(top[0]*top[1]))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
t=A[0]
a,b=0,0
g=0
for i in range(1,N):
    if A[i]==t:
        a=t
        g=i
        break
    else:
        t=A[i]
t=A[g+1]
if a!=0:
    for i in range(g+2,N):
        if t==A[i]:
            b=t
            break
        else:
            t=A[i]
print(a*b)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
squ = 0
rec = []
count = 0
tmp = 0
for i in l:
  if i == tmp:
    count += 1
    if count == 2:
      rec.append(tmp)
    elif count == 4:
      squ = max([squ,tmp])
  else:
    tmp = i
    count = 1
if len(rec)<2:
  print(squ*squ)
else:
  print(max([squ*squ,rec[0]*rec[1]]))

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
squ = 0
rec = []
count = 0
tmp = 0
for i in l:
  if i == tmp:
    count += 1
  else:
    tmp = i
    count = 1
  
  if count == 2:
    rec.append(tmp)
  elif count == 4:
    squ = max([squ,tmp])

if len(rec)<2:
  print(squ*squ)
else:
  print(max([squ*squ,rec[0]*rec[1]]))

Solution (Python):
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
c=Counter(l)

edges=[]
for k,v in c.items():
    if v>=2:
        for i in range(v//2):
            edges.append(k)
if len(edges)>=2:
    edges.sort(reverse=True)
    print(edges[0]*edges[1])
else:
    print(0)

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
As.sort(reverse=True)
rs = []
a = -1
for i in range(N):
  A = As[i]
  if A == a:
    rs.append(A)
    a = -1
  else:
    a = A
if len(rs) < 2:
  print(0)
  exit()
r = rs[0]*rs[1]
print(r)

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    d = dict()
    for a in A: d[a] = d.get(a, 0) + 1

    max_area = 0
    edges = list(d.keys())
    for a in edges:
        if d[a] > 3:
            max_area = max(max_area, a*a)
        if d[a] == 1:
            del d[a]

    edges = sorted(d.keys(), reverse = True)
    if len(edges) > 1:
        max_area = max(max_area, edges[0]*edges[1])

    return max_area



if __name__ == '__main__':
    print(main())

Solution (Python):
from collections import Counter
N = int(input())
c = Counter([int(s) for s in input().split()])
a = [(k, v) for k, v in c.items() if v > 1]
a.sort(reverse=True)
if len(a) < 1:
    print(0)
elif a[0][1] >= 4:
    print(a[0][0] ** 2)
elif len(a) < 2:
    print(0)
else:
    print(a[0][0] * a[1][0])

Solution (Python):
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in map(int,input().split()):
  d[i] += 1
c = dict()
for i in d:
  if d[i] >= 2:
    c[i] = d[i]
if len(c) == 0:
  print(0)
  exit()
f = max(c)
if c[f] < 4:
  del c[f]
if len(c) == 0:
  print(0)
  exit()
s = max(c)
print(f*s)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
a=0
H=0
W=0
count=1
for i in range(len(A)):
    
    if A[i]==a:
        count+=1
    else:
        if count>=4:
            if H<A[i-1]:
                H=A[i-1]
            if W < A[i - 1]:
                W=A[i-1]
        elif count>=2:
            if H!=0:
                W=A[i-1]
            else:
                H=A[i-1]
        a=A[i]
        count=1
        if H!=0 and W!=0:
            print(H*W)
            exit(0)
if count>=4:
    if H<A[i-1]:
        H=A[i-1]
    if W < A[i - 1]:
        W=A[i-1]
elif count>=2:
    if H!=0:
        W=A[i-1]
    else:
        H=A[i-1]
print(H*W)

Solution (Python):
from collections import defaultdict

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

A.sort(reverse=True)
i = 0
ret = 0
while i < N :
    if i + 3 < N and A[i] == A[i+1] == A[i+2] == A[i+3] :
        if ret == 0 :
            ret = A[i] * A[i]
        else :
            ret *= A[i]
        break
    elif i + 1 < N and A[i] == A[i+1] :
        if ret == 0 :
            ret = A[i]
            i += 1
        else :
            ret *= A[i]
            break
    
    i += 1
    
print(ret)

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(map(int,input().split()))
four = []
two = []
for k,v in a.items():
  if v  >= 4 :
    four.append(k)
  if v >= 2:
    two.append(k)
f,t = 0,0
if four:
  f = max(four)**2
if len(two) > 1:
  two.sort()
  t = two.pop() * two.pop()
print(max(f,t,0))

Solution (Python):


from collections import Counter

def main(N,A):
    a = b = 0
    count = Counter(A)
    length = sorted(set(A), reverse=True)
    for i in length:
        if(count[i]>=4 and a==b==0):
            a = b = i
            break
        elif(count[i]>=2 and a==0):
            a = i
        elif(count[i]>=2 and b==0):
            b = i
            break
    print(a*b)

if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Solution (Python):
from collections import*
n,*a=map(int,open(0).read().split())
r=[0,0];s=[0]
for k,v in Counter(a).items():
	if v>1:
		r+=[k]
	if v>3:
		s+=[k]
r.sort();s.sort()
print(max(r[-1]*r[-2],s[-1]**2))

Solution (Python):
from collections import*
n,*a=map(int,open(0).read().split())
r=[];s=[]
for k,v in Counter(a).items():
	if v>1:
		r+=[k]
	if v>3:
		s+=[k]
if len(r)<2 and len(s)<1:
	print(0)
	exit()
r+=[0,0]
s+=[0]
r.sort()
s.sort()
print(max(r[-1]*r[-2],s[-1]**2))

Solution (Python):
n = int(input())
l = map(int, input().split())
d = {}
for a in l:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

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

m.sort(reverse=True)
if len(m) == 0:
  print(0)
elif m[0][1] >= 4:
  print(m[0][0]**2)
elif len(m) >= 2:
  print(m[0][0]*m[1][0])
else:
  print(0)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
ac = collections.Counter(a)
side = []

for k,d in ac.items():
    if 2 <= d < 4:
        side.append(k)
    elif d >= 4:
        side.append(k)
        side.append(k)

side.sort(reverse=True)
if len(side) < 2:
    print(0)
else:
    print(side[0]*side[1])

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
count_dict = collections.Counter(A)
d = []
for k,v in count_dict.items():
	d.append([k,v])

d.sort(reverse=True)
ans = []
for i in range(len(d)):
	if d[i][1] >= 2:
		ans.append(d[i])
	if len(ans) == 2:
		break
ans += [[0]*2]*2
if ans[0][1] >= 4:
	print(ans[0][0]**2)
else:
	print(ans[0][0]*ans[1][0])

Solution (Python):
import collections
n = int(input())
a = sorted(collections.Counter(list(map(int, input().split()))).items(), reverse=True)
h = w = 0
for k, v in a:
    if h == 0 or w == 0:
        t = v
        while True:
            if t >= 2:
                if h == 0:
                    h = k
                    t -= 2
                elif w == 0:
                    w = k
                    t -= 2
                else:
                    break
            else:
                break
    else:
        break
print(h * w)

Solution (Python):
from collections import defaultdict

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

A.sort(reverse=True)
lengCount = defaultdict(int)
for a in A:
    lengCount[a] += 1

lengList = [[leng, count] for leng, count in lengCount.items()]
lengList.sort(key=lambda A : A[0], reverse=True)

firstLeng = 0
for i in range(len(lengList)):
    if lengList[i][1] >= 2:
        firstLeng = lengList[i][0]
        lengList[i][1] -= 2
        break

secondLeng = 0
for i in range(len(lengList)):
    if lengList[i][1] >= 2:
        secondLeng = lengList[i][0]
        break
print(firstLeng * secondLeng)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
d = 0
ans = []
ap = 0
for i in range(n):
    if ap == a[i]:
        d += 1
        if d == 2:
            ans.append(a[i])
        elif d == 4:
            ans.append(a[i])
    else:
        d = 1
        ap = a[i]    
    if len(ans)> 1:
      break
ans.append(0)
ans.append(0)
print(ans[0]*ans[1])

Solution (Python):
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for ai in a:
    d[ai] += 1

cand = [k for k, v in d.items() if v >= 2]
cand.sort()

ans = 0
if len(cand) >= 1 and d[cand[-1]] >= 4:
    ans = cand[-1] ** 2
elif len(cand) >= 2:
    ans = cand[-1] * cand[-2]

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
a.reverse()
oktwo = 0
skip = 0
for i in range(1,n):
  if skip == 1:
    skip = 0
    continue
  if a[i-1] == a[i]:
    if oktwo != 0:
      print(oktwo*a[i])
      break
    else:
      oktwo = a[i]
      danger = 1
      skip = 1
else:
  print(0)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
a=b=c=0
for i in sorted(A)[::-1]:
    c+=1
    if a==i:break
    a=i
B=sorted(A)[:-c:]
c=0
d=len(B)
for i in B[::-1]:
    c+=1
    if b==i:break
    b=i
    if c==d:b=0
print(a*b)

Solution (Python):
from collections import Counter

n = int(input())
lst = [int(i) for i in input().split()]

x,y = 0,0

c = Counter(lst)

for k,v in c.items():
    if 4 <= v:
        x = max(x,k)
        y = max(y,k)

    elif 2 <= v:
        s = min(x,y)
        if k > s:
            x = max(x,y)
            y = k
print(x*y)

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

pre = 10**10
cnt = 0
l = [0] * 2
i = N-1
while cnt < 2 and i > 0:
    if A[i] == A[i-1]:
        l[cnt] = A[i]
        cnt += 1
        i -= 2
    else:
        i -= 1

ans = l[0] * l[1]
print(ans)

Solution (Python):

import sys, math, fractions, itertools, collections


def solve(N: int, A: "List[int]"):
    c = collections.Counter(A).items()
    a = [aa[0] for aa in c if aa[1] > 1]
    a.sort()
    s = [aa[0] for aa in c if aa[1] > 3]
    s.sort()

    if len(a) > 1:
        r = a[-1] * a[-2]
    else:
        r = 0
    
    if len(s) > 0:
        ss = s[-1] ** 2
    else:
        ss = 0
    
    print(max(r, ss))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):

a = int(input())
b = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for i in b:
    d[i]+=1
sorted_d = sorted(d.items(),key=lambda x:x[0],reverse=True)

rec_cnt = 0
rec_len_list = []
for k,v in sorted_d:
    if rec_cnt == 0:
        if v >= 4:
            rec_len_list = [k,k]
            rec_cnt=2
        elif v >= 2:
            rec_len_list.append(k)
            rec_cnt=1
        else:
            pass
    elif rec_cnt == 1:
        if v >= 2:
            rec_len_list.append(k)
            rec_cnt+=1
    else:
        break
if len(rec_len_list) < 2:
    print(0)
else:
    print(rec_len_list[0] * rec_len_list[1])

Solution (Python):
N = int(input())
A = sorted([int(x) for x in input().split()], reverse=True)

from collections import Counter
c = Counter(A)

A = sorted([(l,c) for l, c in c.items() if c >= 2], reverse=True)

if len(A) == 0:
    print(0)
elif A[0][1] >= 4:
    print(A[0][0]**2)
else:
    print(A[0][0]*A[1][0])

Solution (Python):
from collections import Counter

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

c = Counter(A).most_common()
c.sort(key=lambda x: x[0], reverse=True)

tmp = []
for i in range(len(c)):
    if c[i][1] >= 4 and len(tmp) == 0:
        print(c[i][0]**2)
        exit()
    elif c[i][1] >= 2:
        tmp.append(c[i][0])
    if len(tmp) == 2:
        print(tmp[0]*tmp[1])
        exit()
print(0)

Solution (Python):

import sys
from collections import Counter
INF = float("inf")


def solve(N: int, A: "List[int]"):
    counter = Counter(A)
    
    count = 0
    cand = []
    for k in counter:
        if counter[k] >= 4:
            cand.append(k)
            cand.append(k)
        elif counter[k] >= 2:
            cand.append(k)
    if len(cand) < 2:
        print(0)
        return
    else:
        cand.sort(reverse=True)
        area = cand[0]*cand[1]
        print(area)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())),reverse=True)
x, y = 0, 0
for i in range(N-1):
    if A[i] == A[i+1]:
        x = A[i]
        break
for j in range(i+2,N-1):
    if A[j] == A[j+1]:
        y = A[j]
        break
print(x*y)

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]

for i in range(n-3):
  if a[i] == a[i+1]:
    for j in range(i+2, n):
      if a[j] == a[j+1]:
        print(a[i] * a[j])
        exit()

print(0)

Solution (Python):
from bisect import bisect_right, bisect_left

N = int(input())
A = [int(zz) for zz in input().split()]

A.sort()
B = set(A)

ans = []

for i in B:
    p = bisect_right(A, i) - bisect_left(A, i)
    if 4 > p >= 2:
        ans.append(i)
    elif p >= 4:
        ans.append(i)
        ans.append(i)
        

ans.sort(reverse=True)

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

Solution (Python):
N = int(input())
sticks = list(map(int, input().split()))
s_dict = {}
for stick in sticks:
  if stick in s_dict:
    s_dict[stick] += 1
  else:
    s_dict[stick] = 1
sorted_dict = sorted(s_dict.items(), key=lambda x:-x[0])
side1 = 0
side2 = 0
for elem in sorted_dict:
  if elem[1] >= 4:
    if side1 == 0:
      side1 = side2 = elem[0]
    else:
      side2 = elem[0]
  elif elem[1] == 2 or elem[1] == 3:
    if side1 == 0:
      side1 = elem[0]
    else:
      side2 = elem[0]
  if side1 != 0 and side2 != 0:
    print(side1*side2)
    exit()
print(0)

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 




 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    tmp = {}
    for i, val in enumerate(A):
        if val in tmp:
            tmp[val] += 1
        else:
            tmp[val] = 1
            
    ans = []
    for k, v in tmp.items():
        if v >= 4:
            ans.append(k)
            ans.append(k)
        elif v >= 2:
            ans.append(k)
            
    if len(ans) == 0:
        print(0)
        sys.exit()
    ans.sort()
    print(ans[-1] * ans[-2])
    
    
if __name__ == "__main__":
	main()

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
s=t=0
i=n-1
while i>=4 and a[i]!=a[i-1]:i-=1
if a[i]==a[i-1]:s=a[i];i-=2
while i>=2 and a[i]!=a[i-1]:i-=1
if a[i]==a[i-1]:t=a[i]
print(s*t)

Solution (Python):
import collections
import sys
def input():
    return sys.stdin.readline()[:-1]
    
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()

Solution (Python):
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()

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

l = {}
for i in a:
    l.setdefault(i, 0)
    l[i] += 1
l2 = [i for i in l.keys() if l[i] >= 2]
if len(l2) <= 1:
    print(0)
else:
    l2.sort()
    if l[l2[-1]] >= 4:
        print(l2[-1] ** 2)
    else:
        print(l2[-1] * l2[-2])

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    from collections import Counter

    c = Counter(A)

    a = 0
    b = 0

    for k,v in sorted(c.items(), reverse=True):
        if(v >= 4):
            if(a == 0 and b == 0):
                a = k
                b = k
                break
            else:
                b = k
                break
        if(2 <= v < 4):
            if(a != 0):
                b = k
                break
            else:
                a = k

    print(a*b)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):
import collections

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

B = collections.Counter(A)

p = []
for k, v in B.items():
    if v >= 2:
        p.append(k)
    if v >= 4:
        p.append(k)

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

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

A_dict = {}

for i in A:
    if i in A_dict:
        A_dict[i] += 1
    else:
        A_dict[i] = 1



A_tuple = sorted(A_dict.items(), key=lambda x: -x[0])
side = []


for i in A_tuple:
    if i[1] >= 4:
        side.append(i[0])
        side.append(i[0])
    elif i[1] >= 2:
        side.append(i[0])
    if len(side) >= 2:
        break


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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
alp = [chr(ord('a') + i) for i in range(26)]

def A():
    x, a, b = LI()
    if abs(x - a) > abs(x - b):
        print("B")
    else:
        print("A")
    return


def B():
    s = S()
    s = set(s)
    for i in s:
        alp.remove(i)
    if len(alp) == 0:
        print("None")
    else:
        print(alp[0])
    return


def C():
    n = II()
    a = LI()
    i = 1
    a.sort(reverse=True)
    ans = []
    while i < n:
        if a[i] == a[i - 1]:
            ans.append(a[i])
            if len(ans) == 2:
                print(ans[0] * ans[1])
                return
            i += 2
        else:
            i += 1
    print(0)


def D():
    return


if __name__ == '__main__':
    C()

Solution (Python):
import copy
import sys
import math

def main():
	n = int(input())
	a = list(map(int,input().split()))
	a.sort()
	tmp = listtodict(a)
	b = {}
	for k,v in tmp.items():
		b[k] = int(v/2)
	b = sorted(b.items(), key=lambda x:x[0])
	w = -1
	for i in reversed(b):
		k=i[0]
		v=i[1]
		if(v>1 and w==-1):
			print(k**2)
			sys.exit()
		elif(v>0 and w==-1):
			w = k
		elif(v>0):
			print(w*k)
			sys.exit()
	print(0)


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

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

long1=0
long2=0
A=sorted(A)
pair=1
for i in range(N-1):
    if A[i]==A[i+1] and pair==1:
        long2=long1
        long1=A[i]
        pair=0
    else:
        pair=1
if long2==0:
    ans=0
else:
    ans=long1*long2
print(ans)

Solution (Python):
import copy
import sys
import math

def main():
	n = int(input())
	a = list(map(int,input().split()))
	a.sort()
	tmp = listtodict(a)
	b = {}
	for k,v in tmp.items():
		b[k] = int(v/2)
	b = sorted(b.items(), key=lambda x:x[0])
	w = -1
	for i in reversed(b):
		k=i[0]
		v=i[1]
		if(v>1 and w==-1):
			print(k**2)
			sys.exit()
		elif(v>0 and w==-1):
			w = k
		elif(v>0):
			print(w*k)
			sys.exit()
	print(0)


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Solution (Python):
import collections 
N = int(input())
A = [int(i) for i in input().split()]
A = collections.Counter(A)
A = sorted(A.items(), key=lambda x:x[0],reverse = True)
e = []

for k,v in A:
  if v >= 4:
    e.append(k)
    e.append(k)
  elif v >= 2:
    e.append(k)
  if len(e) >= 2:
    break
if len(e) < 2:
  ans = 0
else:
  ans = e[0]*e[1]
print(ans)

Solution (Python):
import collections
n=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)
mc=c.most_common()
lec=sorted([i[0] for i in mc if i[1]>=4]+[i[0] for i in mc if i[1]>=2],reverse=True)
if len(lec)<=1:print(0);exit()
else:print(lec[0]*lec[1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
flag=True
for i in range(0,n-4+1):
    if a[i]==a[i+1]:
        for j in range(i+2,n-1+1):
            if a[j]==a[j+1]:
                print(a[i]*a[j])
                flag=False
                break
        break
if flag:
    print(0)