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 Counter

def solve():
    N = int(input())
    R = map(int, input().split())
    counter = Counter(R)
    rect = []
    ret = 0
    edges = sorted(counter.items(), key=lambda x: -1*x[0])
    for a,b in edges:
        if b >= 4:
            rect.append(a)
            rect.append(a)
        elif b >= 2:
            rect.append(a)
        
        if len(rect) >= 2: 
            ret = rect[0]*rect[1]
            break
            
    print(ret)
    
solve()

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

a.sort()
res = []
while a and len(res) < 2:
    
    if len(a) >= 2 and a[-1] == a[-2]:
        res.append(a[-1])
        a.pop()
        a.pop()
    else:
        a.pop()



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

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

kl1 = sorted([k for k, v in c if v >= 2], reverse=True)
kl2 = sorted([k for k, v in c if v >= 4], reverse=True)
if len(kl1) < 2:
  print(0 if not kl2 else kl2[0] ** 2)
else:
  print(kl1[0] * kl1[1] if not kl2 else max(kl1[0] * kl1[1], kl2[0] ** 2))

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    for e in a:
        d[e] += 1
    sq = []
    re = []
    for k in d:
        if d[k] > 1:
            re.append(k)
        if d[k] > 3:
            sq.append(k)
    sq.sort()
    re.sort()
    ans = 0
    if sq:
        ans = sq[-1] * sq[-1]
    if len(re) > 1:
        ans = max(ans, re[-1] * re[-2])
    print(ans)

        



t = 1

for case in range(1,t+1):
    ans = solve()


"""



"""

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
hashmap = {}
for a in A:
    if a not in hashmap:
        hashmap[a] = 0
    hashmap[a]+=1

len1 = 0
len2 = 0

for k,v in hashmap.items():
    if v>=4:
        len1, len2 = max(len1,k), max(len2,k)
    elif v>=2:
        if len1<k:
            len1, len2 = k, len1
        else:
            len2 = max(len2,k)
print(len1*len2)

Solution (Python):
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    As = [int(item) for item in input().split()]

    cnt = collections.Counter(As)
    cnt = sorted(cnt.items(), reverse=True)
    
    edges = []
    lim = 0
    res = 0
    if len(cnt) >=2:
        for i, v in cnt:
            if v >= 4:
                edges.append(i)
                edges.append(i)
                lim += 2
            elif v>=2:
                edges.append(i)
                lim += 1

            if lim >= 2:
                res = edges[0]*edges[1]
                break
    print(res)

if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

counter = Counter(A)
ans = 0
pair = []
for l, count in sorted(counter.items(), reverse=True):
    
    if count < 2:
        continue
    if count >= 4 and len(pair) == 0:
        pair = [l, l]
        break
    pair.append(l)
    if len(pair) == 2:
        break
if len(pair) == 2:
    print(pair[0] * pair[1])
else:
    print(0)

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

tmp = a[0]
ans = []
cnt = 0
for i in range(1,len(a)):
    if tmp == a[i]:
        cnt += 1
        if cnt == 1 or cnt == 3:
            ans.append(tmp)
    else:
        tmp = a[i]
        cnt = 0


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

Solution (Python):
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
c = sorted((e for e in c.items() if e[1] > 1), key=lambda e: -e[0])
if len(c) < 2:
  print(0)
elif c[0][1] >= 4:
  print(c[0][0] ** 2)
else:
  print(c[0][0] * c[1][0])

Solution (Python):
from collections import Counter

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

P = sorted([i for i in A.items() if i[1] >= 2])

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

Solution (Python):
from collections import defaultdict
N = int(input())

A = list(map(int, input().split()))
stick = defaultdict(int)

for a in A:
  stick[a] += 1

stick = {key: value for key, value in stick.items() if value >= 2}


if len(stick) >= 2:
  len1 = max(stick.keys())
  if stick[len1] < 4:
    stick.pop(len1)
  len2 = max(stick.keys())
  print(len1 * len2)
else:
  print(0)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
d = Counter(a)
lg = 0
lt = 0
for k in d.keys():
  if d[k]>=2 and k>lg:
    lg = k
d[lg] -= 2
for k in d.keys():
  if d[k]>=2 and k>lt:
    lt = k
print(lg*lt)

Solution (Python):






import collections





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





a_cnt = collections.Counter(A)
p = sorted([i for i in a_cnt.items() if i[1] >= 2], reverse=True)
if len(p) > 0:
    if p[0][1]>=4:
        print(p[0][0]**2)
    elif len(p) > 1:
        print(p[0][0]*p[1][0])
    else:
        print(0)
else:
    print(0)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()

d = Counter(readInts())

d = [i for i in sorted(d.items(), reverse=True) if i[1]>=2]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()
if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))

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

Solution (Python):
from collections import Counter

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

acnt = Counter(A)

b = []

for k, v in acnt.items():
    if v < 2:
        continue
    if v >= 4:
        b.append(k)
    b.append(k)

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

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

cnt=Counter(a)
edge=[0,0]

for i in cnt:
    if cnt[i]>=4:
        edge.append(i)
    if cnt[i]>=2:
        edge.append(i)

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

Solution (Python):
from collections import defaultdict

n = int(input())
A = map(int, input().split())
C = defaultdict(int)
for a in A:
    C[a] += 1
C = sorted(C.items(), key=lambda x: x[0], reverse=True)
rods = []
for k, v in C:
    if v >= 4:
        rods.append(k)
        rods.append(k)
        break
    if v >= 2:
        rods.append(k)
    if len(rods) == 2:
        break
if len(rods) >= 2:
    ans = rods[0]*rods[1]
else:
    ans = 0
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
A = Counter(list(map(int, input().split())))
A = sorted(A.most_common(), reverse=True)
rods = []
for a in A:
    if a[1] >= 4:
        rods.append(a[0])
        rods.append(a[0])
        break
    if a[1] >= 2:
        rods.append(a[0])
    if len(rods) == 2:
        break
if len(rods) >= 2:
    ans = rods[0]*rods[1]
else:
    ans = 0
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

from collections import Counter
c = Counter(As)

area = 0
for n, c in sorted(c.most_common())[::-1]:
    if c<2:
        pass
    elif c>=4:
        area = max(area*n, n**2)
        break
    else:
        if area:
            area = area*n
            break
        else:
            area = n

print(area)

Solution (Python):
from collections import Counter

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

C_al = Counter(al)

al.sort(reverse=True)

tate = 0
yoko = 0

lst = list(C_al.keys())
lst.sort(reverse=True)

for edge in lst:
    if C_al[edge] >= 2:
        if tate == 0:
            tate = edge
            if C_al[edge] >= 4 and yoko == 0:
                yoko = edge
                print(tate * yoko)
                exit()
            else:
                pass
        else:
            yoko = edge
            print(tate * yoko)
            exit()
print(tate * yoko)

Solution (Python):
import sys
from collections import Counter
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    l = list(IL())
    a = Counter(l)
    f = s = 0
    l = list(set(l))
    l.sort(reverse=True)
    for rep in l:
        if 4<=a[rep]:
            f = max(f,rep)
            s = max(s,rep)
            break
        elif 2<=a[rep]:
            if f==0:
                f = rep
            else:
                s = rep
                break
    
    print(f*s)
    return

if __name__=='__main__':
    Main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
B2 = []
B4 = []
for a in C:
    if 3>=C[a]>=2:
        B2.append(a)
    elif C[a]>=4:
        B4.append(a)
B2 = sorted(B2,reverse=True)
B4 = sorted(B4,reverse=True)
cmax = 0
if len(B2)>=2:
    cmax = max(cmax,B2[0]*B2[1])
if B4:
    cmax = max(cmax,B4[0]**2)
if B2 and B4:
    cmax = max(cmax,B2[0]*B4[0])
print(cmax)

Solution (Python):
import math
import collections
import fractions
import itertools
 
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    box = []
    for i in c:
        if c[i] >= 2:
            for _ in range(c[i]//2):
                box.append(i)
    if len(box) < 2:
        print(0)
    else:
        box.sort(reverse=True)
        print(box[0]*box[1])
    return 0
 
if __name__ == "__main__":
    solve()

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
L = []
for k, v in C.items():
  if v >= 2:
    L.append(k)
  if v >= 4:
    L.append(k)
if len(L) < 2:
  print(0)
else:
  L.sort()
  ans = L[-1] * L[-2]
  print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=sorted(lmp(),reverse=True)
a.append(0)
i=0
ans=[]
while i<n:
    if a[i]==a[i+1]:
        ans.append(a[i])
        i+=1
    i+=1
ans.append(0)
ans.append(0)
print(ans[0]*ans[1])

Solution (Python):
import math
import collections
import fractions
import itertools

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    box = []
    for i in c:
        if c[i] >= 2:
            for _ in range(c[i]//2):
                box.append(i)
    if len(box) < 2:
        print(0)
    else:
        box.sort(reverse=True)
        print(box[0]*box[1])
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

from collections import Counter
import sys

N = INT()
A = LI()
count_A = Counter(A)
ans = 0

if sum([c > 1 for c in count_A.values()]) <= 1:
    print(ans)
    sys.exit()
    
count_st = []

for k, v in count_A.items():
    if v == 1:
        continue
    
    count_st.append(k)
    
    if v >= 4:
        count_st.append(k)
    
count_st.sort(reverse = True)
ans = count_st[0] * count_st[1]
print(ans)

Solution (Python):
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
a = sorted(a)[::-1]
counter = Counter(a).items()
hen4 = [elem[0] for elem in counter if elem[1] >= 4]
hen2 = [elem[0] for elem in counter if elem[1] >= 2]
if len(hen4) == 0 and len(hen2) == 0:
    print(0)
    sys.exit()

if len(hen4) > 0:
    seihoukei = hen4[0] ** 2
    if len(hen2) >= 2:
        chouhoukei = hen2[0] * hen2[1]
        ans = max(seihoukei, chouhoukei)
    else:
        ans = seihoukei
    print(ans)

else:
    print(hen2[0] * hen2[1])

Solution (Python):
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST(), reverse=True)

h = 0
w = 0
reg = n-1
for i in range(n-1):
   if a[i] == a[i+1]:
        h = a[i]
        reg = i
        break
for i in range(reg+2, n-1):
   if a[i] == a[i+1]:
        w = a[i]
        break

print(h*w)

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

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


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



cnt = 0
num = []
n = 0
for i,v in a:
    if 4 <= v:
        n = max(n,(i*i))
    if 2 <= v:
        num.append(i)
        cnt += 1
    if 2 == cnt:
        break
if cnt == 2:
    print(max(num[0]*num[1],n))
else:
    print(n)

Solution (Python):

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


from collections import Counter
A_cnt = Counter(A)
candi = []
for k, v in A_cnt.items():
    if v >= 4:
        candi.extend([k, k])
    if v >= 2:
        candi.append(k)
if len(candi) < 2:
    print(0)
    exit()
A_ls = sorted(candi, reverse=True)
print(A_ls[0] * A_ls[1])

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

c = Counter(a)
m1=0
m2=0
m3=0
for k,v in c.items():
  if v>1:
    if k>=m1:
      m2=m1
      m1=k
    elif m2<k:
      m2=k
  if v>3 and k>m3:
    m3=k
    
print(max(m1*m2,m3**2))

Solution (Python):
import collections
N =int(input())
A =list(map(int,input().split()))
col = (collections.Counter(A))
col_key = sorted(col.keys(),reverse = 1)
hen = []
counter  =0
for i in range(len(col_key)):
    if 2 <= col[col_key[i]] <4:
        hen.append(col_key[i])
        counter += 1
    elif col[col_key[i]] >= 4:
        hen.append(col_key[i])
        hen.append(col_key[i])
        counter +=2
    if counter>=2:
        break
if counter<2:
    print(0)
else:
    print(hen[0]*hen[1])

Solution (Python):
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1

    key = list(d.keys())
    key.sort(reverse=True)
    cnt = 0
    ans = 0
    tmp = 0
    flag = False
    for i in key:
        if d[i] >= 4:
            ans = i * i
            flag = True
            break
    for i in key:
        if d[i] >= 2:
            if cnt == 0:
                tmp = i
            elif cnt == 1:
                tmp *= i
                ans = max(ans, tmp)
                print(ans)
                exit()
            cnt += 1

    if not flag:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
    main()

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

c = Counter(a)

e = []
for k, v in c.items():
    if v > 3:
        e.append(k)
        e.append(k)
    elif v > 1:
        e.append(k)
e.sort(reverse=True)

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

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

c = Counter(A)
check = 0
for i in range(N):
    if (c[A[i]] > 1):
        check += 1
if (check <= 1):
    print(0)
    exit()

L = []
for i, v in c.items():
    if (v > 3):
        L.append(i)
        L.append(i)
    elif (v > 1 and v <= 3):
        L.append(i)

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

Solution (Python):
from collections import Counter

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


kouho = []

ans = 0

for key in cnt_A:
    if cnt_A[key] >= 2:
        kouho.append(key)
    if cnt_A[key] >= 4:
        ans = max(ans, key ** 2)

if len(kouho) < 2:
    print(ans)
    exit()

kouho.sort()
ans = max(ans, kouho[-1] * kouho[-2])
print(ans)

Solution (Python):
from collections import Counter

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

acnt = Counter(a)
num = [0,0]
for i in acnt:
    if acnt[i] >= 4:
        num.append(i)
    if acnt[i] >= 2:
        num.append(i)
num.sort()
print(num[-1] * num[-2])

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

dic={}

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

lst=list(dic.keys())
lst.sort(reverse=True)

anslst=[]
for i in lst:
    if dic[i]>=2:
        anslst.append(i)
    if dic[i]>=4:
        anslst.append(i)
    if len(anslst)>=2:
        print(anslst[0]*anslst[1])
        break
else:
    print(0)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
from collections import Counter
AA = Counter(A)
B = []
C = []
for k,v in AA.items():
    if v>=2:
        B.append(k)
    if v>=4:
        C.append(k)
B.sort(reverse=True)
C.sort(reverse=True)
if len(B)<=1 and len(C)==0:
    print(0)
else:
    if len(B)<=1:
        print(C[0]*C[0])
    elif len(C)==0:
        print(B[0]*B[1])
    else:
        print(max(B[0]*B[1],C[0]*C[0]))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
val = set()
ans = []

for i in a:
    if i in val:
        ans.append(i)
    else:
        val.add(i)
ans.sort()
if len(ans) == 0:
    print(0)
else:
    if ans.count(ans[-1]) >= 4:
        print(ans[-1]**2)
    elif ans.count(ans[-1]) == 3:
        print(ans[-1]*ans[-4])
    elif ans.count(ans[-1]) == 2:
        print(ans[-1]*ans[-3])
    else:
        print(ans[-1]*ans[-2])

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
c = dict(c)
c = sorted(c.items(), key=lambda x:x[0], reverse=True)
h = 0
w = 0
for i in range(len(c)):
  if c[i][1] >= 2 and h == 0:
    h = c[i][0]
    if c[i][1] >= 4:
      w = c[i][0]
  elif c[i][1] >= 2 and w == 0:
    w = c[i][0]
ans = h * w
print(ans)

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in a:
  if i in dic:
    dic[i]+=1
  else:
    dic[i]=1
a=[0,0]
mx=0
for i in dic:
  if dic[i]>=2:
    a.append(i)
    if dic[i]>3:
      mx=max(i**2,mx)
a=sorted(a)
mx=max(a[-1]*a[-2],mx)
print(mx)

Solution (Python):
n = input()
*a, = map(int, input().split())
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
b = [i for i in d.keys() if d[i] >= 2]
if len(b) == 0:
    print(0)
elif len(b) == 1:
    if d[b[0]] >= 4:
        print(b[0]**2)
    else:
        print(0)
else:
    b.sort()
    if d[b[-1]] >= 4:
        print(b[-1]**2)
    else:
        print(b[-1]*b[-2])

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
A_count = Counter(A)
x = [0, 0]
for a in A_count:
  if A_count[a] > 1:
    x.append(a)
  if A_count[a] > 3:
    x.append(a)
x.sort()
print(x[-1]*x[-2])

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
As=sorted(A,reverse=True)
B=0
C=0
for i in range(len(As)-1):
    tmp=As[i]
    if tmp==As[i+1]:
        if tmp>B:
            B=tmp
            del As[0:i+2]
            break
for j in range(len(As)-1):
    tmp=As[j]
    if tmp==As[j+1]:
        if tmp>C:
            C=tmp
print(B*C)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
s=set([])
ans=[]
A.sort(reverse=True)
for a in A:
  if a not in s:
    s.add(a)
  else:
    ans.append(a)
    s.discard(a)
  if len(ans)>=2:
    break
if len(ans)<2:
  print(0)
else:
  print(ans[0]*ans[1])

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

    A.sort(reverse=True)
    tmp = 0
    bar1 = 0
    bar2 = 0

    for a in A:
        if tmp == 0:
            tmp = a
        elif tmp == a:
            if bar1 > 0:
                bar2 = a
                print(bar1*bar2)
                exit()
            else:
                bar1 = a
                tmp = 0
        elif a < tmp:
            tmp = a

    print(0)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
c = []
for i, j in a.items():
    if j >= 2:
        for _ in range(j//2):
            c.append(i)
c.sort(reverse = True)
print(c[0]*c[1] if len(c)>=2 else 0)

Solution (Python):
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
lis = sorted(list(set(a)),reverse=True)
ans1,ans2 = 0,0
for val in lis:
    if ans1==0:
        if cnt[val]>=2:
            cnt[val]-=2
            ans1=val

        if cnt[val]>=2:
            ans2=val
            break
    else:
        if cnt[val]>=2:
            ans2=val
            break
print(ans1*ans2)

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

dic = {}
cnt = 0

for x in A:
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1

dic = sorted(dic.items(), reverse=True)

ans = 0
for i in range(len(dic)):
    if dic[i][1] >= 4 and cnt == 0:
        ans = dic[i][0]**2
        break
    elif dic[i][1] >= 2:
        if cnt == 1:
          ans = t*dic[i][0]
          break 
        if cnt == 0:
            t = dic[i][0]
            cnt = 1
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
l = list(map(int, input().split()))
d = Counter(l)
ite = sorted(d.items(), key=lambda x: (-x[0], -x[1]))
first = 0
taken = False
second = 0
for i in range(len(ite)):
    if ite[i][1] >= 4:
        if not taken:
            print(ite[i][0] * ite[i][0])
            exit()
        elif taken:
            second = ite[i][0]
            break
        exit()
    elif ite[i][1] >= 2 and not taken:
        first = ite[i][0]
        taken = True
    elif ite[i][1] >= 2 and taken:
        second = ite[i][0]
        break
print(first * second)

Solution (Python):
import collections

n = int(input())
l = list(map(int, input().split()))
l = sorted(l, reverse=True)

i = 1
a = 0
b = 0
while i < n:
    if l[i] == l[i-1]:
        if a == 0:
            a = l[i]
        else:
            b = l[i]
            break
        i += 2
    else:
        i += 1

print(a*b)

Solution (Python):
import collections

n = int(input())
l = list(map(int, input().split()))
l = sorted(l, reverse=True)

i = 1
a = 0
b = 0
while i < n:
    if l[i] == l[i-1]:
        if a == 0:
            a = l[i]
        else:
            b = l[i]
            break
        i += 2
    else:
        i += 1

print(a*b)

Solution (Python):


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

ans = 0 
d = {}
for i in a:
    if i not in d:
        d[i] = 1 
    else:
        d[i] += 1

d = sorted(d.items(), key=lambda x:x[0], reverse=True)
area = 1 
cnt = 0 
allone = True
for i in d:
    if i[1] != 1:
        allone = False
        if i[1] >= 4:
            if cnt == 0:
                area = i[0]*i[0]
                break
        if cnt == 2:
            break
        area *= i[0]
        cnt += 1

if allone:
    print(0)
else:
    print(area)

Solution (Python):


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

ans = 0 
d = {}
for i in a:
    if i not in d:
        d[i] = 1 
    else:
        d[i] += 1

d = sorted(d.items(), key=lambda x:x[0], reverse=True)
area = 1 
cnt = 0 
allone = True
for i in d:
    if i[1] != 1:
        allone = False
        if i[1] >= 4:
            if cnt == 0:
                area = i[0]*i[0]
                break
            else:
                if cnt == 2:
                    break
                area *= i[0]
                cnt += 1
        else:
            if cnt == 2:
                break
            area *= i[0]
            cnt += 1

if allone:
    print(0)
else:
    print(area)

Solution (Python):


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

ans = 0 
d = {}
for i in a:
    if i not in d:
        d[i] = 1 
    else:
        d[i] += 1

d = sorted(d.items(), key=lambda x:x[0], reverse=True)
area = 1 
cnt = 0 
allone = True
for i in d:
    if 1 < i[1] < 4:
        allone = False
        if cnt == 2:
            break
        area *= i[0]
        cnt += 1
    elif i[1] >= 4:
        allone = False
        if cnt == 0:
            area = i[0]*i[0]
            break
        else:
            if cnt == 2:
                break
            area *= i[0]
            cnt += 1

if allone:
    print(0)
else:
    print(area)

Solution (Python):
import collections
n = int(input())
l = map(int, input().split())
c = collections.Counter(l)
c = sorted(c.items(), key=lambda c:c[0], reverse=True)
 
ans = 1
cnt = 0
 
for key,val in c:
  if cnt==0 and val>=4:
    ans=key**2
    break
  if val>=2:
    ans*=key
    cnt+=1
  if cnt == 2:
    break
else:
  ans = 0
print(ans)

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

a.sort()
a.reverse()

ret = []
my_s = set()

for item in a:
    if item in my_s:
        ret.append(item)
        if len(ret) == 2:
            print(ret[0] * ret[1])
            exit()
        my_s.remove(item)
    else:
        my_s.add(item)

print(0)

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

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

dic = {}
L = set([]) 
S = set([]) 
for i in range(N):
  if A[i] not in dic:
    dic[A[i]] = 1
  else:
    dic[A[i]] += 1
    if dic[A[i]] == 2:
      L.add(A[i])
    elif dic[A[i]] == 4:
      S.add(A[i])
L = list(L)
L.sort(reverse = True)
if len(L) >= 2:
  tyo = L[0]*L[1]
else:
  tyo = 0
S = list(S)
S.sort(reverse = True)
if S:
  sei = S[0]**2
else:
  sei = 0

print(max(tyo,sei))

Solution (Python):
from collections import Counter
n = int(input())
A = Counter(list(map(int, input().split())))
l = []
for x,y in A.items():
    if y >= 2:
        for _ in range(y//2):
            l.append(x)
l.sort(reverse=True)
print(l[0]*l[1] if len(l)>=2 else 0)

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

from collections import Counter
c = Counter(As)
ans = []
for a, c in c.most_common():
    if c<2:
        break
    ans.append(a)
    if c>=4:
        ans.append(a)

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

Solution (Python):
import sys

input = sys.stdin.readline


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

    A.sort(reverse=True)
    rect = []
    prev = 0
    for a in A:
        if a == prev:
            rect.append(a)
            prev = 0
            if len(rect) == 2:
                break
        else:
            prev = a

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


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
ma1 = 0
ma2 = 0
A = list(map(int,input().split()))
A.append(0)
a = sorted(A,reverse = True)

hold = 0
count = 0

for i in a:
  if i == hold:
    count += 1
  else:
    if count > 3 and ma1 == 0:
      ma1 = hold
      ma2 = hold
    elif count > 1:
      if ma1 == 0:
        ma1 = hold
      elif ma2 == 0:
        ma2 = hold
    hold = i
    count = 1
    if ma1 != 0 and ma2 != 0:
      break
    

print(ma1*ma2)

Solution (Python):
import collections
s = set()
N = int(input())
count = []*(10**9+1)
ma1 = 0
ma2 = 0
A = list(map(int,input().split()))
a = collections.Counter(A)
b = sorted(a.items(),reverse = True)

for i in b:
  if ma1 == 0 and i[1] > 1:
    ma1 = i[0]
    if i[1] > 3:
      ma2 = i[0]
  elif ma1 != 0 and i[1] > 1:
    ma2 = i[0]
  if ma1 > 0 and ma2 > 0:
    break
  
print(ma1*ma2)

Solution (Python):
from collections import Counter
n = int(input())
*a, = map(int,input().split())
b = Counter(a)

c = sorted(b.items(), reverse = True)
z = [0] * 2
j = 0
ans = 0
for keys,values in c:
    if values < 2:continue
    if values >= 4:
        ans = max(ans, keys ** 2)
    if j < 2:
        z[j] = keys
        j += 1
    ans = max(ans, z[0] * z[1])
print(ans)

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

d={}


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

can = list(d.items())

edge=[]
for i in range(len(can)):
    if can[i][1]<2:
        continue
    else:
        edge.append(can[i])

if len(edge)==0:
    print(0)
    exit(0)
elif len(edge)==1 and edge[0][1]<4:
    print(0)
    exit(0)
elif len(edge)==1 and edge[0][1]>=4:
    print(edge[0][0]**2)
    exit(0)

edge = sorted(edge,key=lambda x: x[0],reverse=True)

k=len(edge)

s=1
if edge[0][1]>=4:
    print(edge[0][0]**2)
else:
    print(edge[0][0]*edge[1][0])

Solution (Python):
from collections import Counter
n = int(input())
dum = [0]*n
a_li = list(map(int,input().split()))
a_counter = Counter(a_li)
a_most = a_counter.most_common()
count = 0
for i,j in a_most:
    if j >= 2:
        dum[count] = i
    count += 1
dum.sort(reverse=1)
if a_counter[dum[0]] >= 4:
    print(dum[0]**2)
else:
    print(dum[0]*dum[1])

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

C = Counter(A)
x = None

for k, v in reversed(sorted(C.items())):
	if v >= 4:
		if x:
			print(k * x)
			exit()
		else:
			print(k ** 2)
			exit()
	elif v >= 2:
		if x:
			print(k * x)
			exit()
		else:
			x = k
else:
	print(0)

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

c=collections.Counter(a)
d={}
for i in c:
    if c[i]>1:
        d.setdefault(i,c[i])
e=sorted(d,reverse=True)
if len(e)>1:
    if d[e[0]]>3:
        print(e[0]**2)
    else:
        print(e[0]*e[1])
else:
    print(0)