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())
a=list(map(int,input().split()))
a.sort(reverse=True)
k=1
i=1
l=[]
while i<n:
    if a[i]==a[i-1]:
        l.append(a[i])
        i+=2
    else:
        i+=1
l.append(0)
l.append(0)
print(l[0]*l[1])

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

import collections
C=collections.Counter(A)
values,counts=zip(*C.most_common())
R=[]
for i in range(len(values)):
    R.append([values[i],counts[i]])
R.sort(reverse=True)

Long=0
Short=0

for i in range(len(values)):
    if R[i][1]>=4 and Long==Short==0:
        Long=R[i][0]
        Short=R[i][0]
        break
    elif R[i][1]>=2 and Long==0:
        Long=R[i][0]
    elif R[i][1]>=2 and Long!=0:
        Short=R[i][0]
        break

print(Long*Short)

Solution (Python):
from collections import Counter

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

tmp = 0
for x, y in sorted(list(a.items()), key=lambda x: x[0], reverse=True):
    if tmp != 0 and y >= 2:
        print(tmp * x)
        break
    if y >= 4:
        print(x**2)
        break
    if y >= 2:
        tmp = x
else:
    print(0)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    rods = string_to_int(inputs[0])
    rods_counter = collections.Counter(rods)
    available_rods = []
    four_count_rods = []
    for length, count in rods_counter.items():
        if count >= 2:
            available_rods.append(length)
        if count >= 4:
            four_count_rods.append(length)
    available_rods.sort()
    four_count_rods.sort()

    max_square = []

    if len(available_rods) < 2:
        max_square.append(0)
    else:
        max_square.append(available_rods[-1] * available_rods[-2])

    if len(four_count_rods) < 1:
        max_square.append(0)
    else:
        max_square.append(four_count_rods[-1] * four_count_rods[-1])
    return max(max_square)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Solution (Python):
import collections

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

l4=sorted([Ai for Ai in c if c[Ai]>=4])
l2=sorted([Ai for Ai in c if c[Ai]>=2])

S=R=0

if len(l4)>=1:
    S=l4[-1]**2
if len(l2)>=2:
    R=l2[-1]*l2[-2]

print(max(S,R))

Solution (Python):
import sys
import collections

def solve(N: int, A: "List[int]"):
    counter = collections.Counter(A)
    counter = sorted(counter.items(), key=lambda x:x[0], reverse=True)

    w =0
    h =0
    for i,item in enumerate(counter):
        if item[1] >=2:
            w = item[0]
            counter[i] = (item[0],item[1]-2)
            break
    
    for i,item in enumerate(counter):
        if item[1] >=2:
            h = item[0]
            break
    
    print(w*h)
    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 = list(input().split())

dic = {}

memo1 = 0
memo2 = 0
for i in range(len(a)):
    if a[i] in dic.keys():
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

for i,j in dic.items():
    if j >= 2 and j<4:
        if memo1 < int(i):
            c = memo1
            memo1 = int(i)
            if memo2 < c:
                memo2 = c
        elif memo2 <= int(i):
            memo2 = int(i)
    
    elif j >= 4:
        if memo1 < int(i):
            memo1 = int(i)
        if memo2 < int(i):
            memo2 = int(i)


print(memo1*memo2)

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

e = []
pre = 0
for i in range(N):
    if pre == A[i]:
        e.append(A[i])
        if len(e) >= 2: break
        pre = 0
    else:
        pre = A[i]
if len(e) < 2: print(0)
else: print(e[0] * e[1])

Solution (Python):
n=int(raw_input())
l=[int(i) for i in raw_input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in c: 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Solution (Python):
import collections

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

li_count=collections.Counter(li)
a=0
b=0
for k in li_count.keys():
    if li_count[k]>=4:
        if k>a:
            a=k
        if k>b:
            b=k
    elif li_count[k]>=2 and (k>a or k>b):
        if a>=b:
            b=k
        else:
            a=k
print(a*b)

Solution (Python):
def test():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    b = []
    i = 0
    while i + 1 < n:
        if a[i] == a[i+1]:
            b.append(a[i])
            i += 2
        else:
            i += 1
    print(b[-1]*b[-2] if len(b)>=2 else 0)


if __name__ == "__main__":
    test()

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

A.sort(reverse=True)
x,y=0,0
flag=False
for i in range(1,n):
  if flag:
    flag=False
    continue
  if A[i-1]==A[i]:
    if x==0:
      x=A[i]
      flag=True
    else:
      y=A[i]
  if x!=0 and y!=0:
    break
print(x*y)

Solution (Python):
import collections
n = int(input())
list_a = list(map(int, input().split()))
count = collections.Counter(list_a)
sort_count = sorted(count.items(), reverse=True)
rect = []
for k, v in sort_count:
  if v >= 4:
    rect.append(k)
    break
  if v >= 2:
    rect.append(k)
    if len(rect) >= 2:
      break
if len(rect) == 0:
  print(0)
elif len(rect) == 1:
  print(rect[0] ** 2)
else:
  print(rect[0] * rect[1])

Solution (Python):
n,*a=map(int,open(0).read().split())
a.sort()
x,y,i=0,0,0
while i<n:
  if a[i-1]==a[i]:
    x,y=y,a[i]
    i+=1
  i+=1
print(x*y)

Solution (Python):
n,*a=map(int,open(0).read().split())
a.sort(reverse=True)
for i in range(1,n):
    if a[i]==a[i-1]:
        a[i]=0
    else:
        a[i-1]=0
a.sort()
print(a[-1]*a[-2])

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

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

d = {}

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

q = []

for x in d:
    for i in range(d[x]//2):
        heapq.heappush(q,-x)

if len(q) <2:
    print(0)
else:
    h = - heapq.heappop(q)
    w = - heapq.heappop(q)
    print(h * w)

Solution (Python):
N = int(input())
Data = list(map(int,input().split()))
Dic = {}
for d in Data:
    if not d in Dic:
        Dic[d] = 1
    else:
        Dic[d] += 1

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

Data2.sort(reverse=True)

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

Solution (Python):
def main():
    n=int(input())
    a=sorted(list(map(int,input().split(' '))),reverse=True)
    next=0
    long=0
    short=0
    for i in range(n-1):
        if a[i] == a[i+1]:
            long = a[i]
            next=i+2
            break
    for j in range(next,n-1):
        if a[j] == a[j+1]:
            short = a[j]
            break
    print(long*short)



if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
l.append(-1)
i=0
ma=0
while i<n:
    if l[i]==l[i+1] and ma==0:
        ma=l[i]
        i+=2
    elif l[i]==l[i+1] and ma!=0:
        print(ma*l[i])
        exit()
    else:
        i+=1
print(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]
a+=0,0,0
l=[]
i=0
c=0
while i<=n-1:
    if a[i]==a[i+1]==a[i+2]==a[i+3] and c==0:
        print(a[i]*a[i+1])
        break
    elif a[i]==a[i+1]==a[i+2]==a[i+3] and c==1:
        l.append(a[i])
        i=n
    elif a[i]==a[i+1]==a[i+2]:
        l.append(a[i])
        i+=3
        c+=1
    elif a[i]==a[i+1]:
        l.append(a[i])
        i+=2
        c+=1
    else:
        i+=1
    if c==2:
        i=n
else:
    if len(l)<=1:
        print(0)
    else:
        l.sort()
        l=l[::-1]
        print(l[0]*l[1])

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

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

l = [k for k in d if d[k] >= 2]
l.sort(reverse=True)

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

Solution (Python):
import collections

N = int(input())
A = sorted(map(int, input().split()))[::-1]

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

    if dict[a] == 2:
        line.append(a)
    if dict[a] == 4:
        line.append(a)
    if len(line) == 2:
        print(line[0]*line[1])
        break
else:
    print(0)

Solution (Python):


import collections

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



A_count = collections.Counter(A)
A_count = A_count.most_common()
pairs = [A_count[idx] for idx in range(len(list(A_count))) if A_count[idx][1] >= 2]
pairs = sorted(pairs, key = lambda x: x[0], reverse = True)

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

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

for i in nums:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

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

side1 = 0

for side,num in dic_sort:
    if num>=4:
        if side1==0:
            print(side**2)
            exit()
        else:
            print(side1*side)
            exit()
    elif num >=2:
        if side1 ==0:
            side1=side
        else:
            print(side1*side)
            exit()
print(0)

Solution (Python):
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
B = []
cur = 0
for i in range(1,N):
    if A[i]!=A[i-1]:
        n = i-cur
        if n>=2:
            B.append((A[i-1],n))
        cur = i
if N-cur>=2:
    B.append((A[-1],N-cur))
if len(B)<2:
    print(0)
else:
    if B[0][1]>=4:
        s = B[0][0]**2
    else:
        s = B[0][0]*B[1][0]
    print(s)

Solution (Python):
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    counter_as_ = collections.Counter(as_)
    available_edge = [item for item in counter_as_.items() if item[1] >= 2]
    available_edge.sort()
    
    if len(available_edge) == 0:
        print(0)
        exit()

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

if __name__ == '__main__':
    main()

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

A.sort(reverse=True)

l = 0
w = 0

while len(A)>=2:
    temp = A.pop(0)
    if temp==A[0]:
        if l==0:
            l = A.pop(0)
        else:
            w = A.pop(0)
            break

print(l*w)

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

A.sort(reverse=True)
E = [0,0]

j = 0
for i in range(n):
    if E[j] == A[i]:
        j += 1
        if j == 1:
            continue
        else:
            break
    E[j] = A[i]
    
print(E[0]*E[1])

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

A.sort(reverse=True)
E = [0,0]

j = 0
for i in range(n):
    if E[j] == A[i]:
        j += 1
        if j == 1:
            continue
        else:
            break
    E[j] = A[i]
    
print(E[0]*E[1])

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
swi = 0
s = [0, 0]
i = 0
while i < len(a) - 1:
    if a[i] == a[i + 1]:
        s[swi] = a[i]
        i += 1
        swi += 1
        if swi == 2:
            break
    i += 1

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

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

D = dd(int)
for a in A:
  D[a] += 1
a = 0
b = 0

for k, v in D.items():
  if v != 1:
    if k > b:
      b = k
    if b > a:
      b, a = a, b
    if v >= 4:
      if k > b:
        b = k
      if b > a:
        b, a = a, b
print (a*b)

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

b, c, d = 0, 0, 0
for i, v in a.items():
    if v >= 2:
        if b < i:
            b, c = i, b
        elif c < i:
            c = i

    if v >= 4:
        d = max(d, i)
print(max(b*c, d*d))

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

A.sort(reverse=True)


setbar=[]
known=set()

for a in A:
    if a in known:
        setbar.append(a)
        known.remove(a)
    else:
        known.add(a)
    if len(setbar) >= 2:
        break

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

Solution (Python):
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
counter=Counter(a)
c_k=sorted(counter.keys(),reverse=True)
ans=0
l=[0]
for i in c_k:
    if counter[i]>=2:
        ans=max(ans,i*l[-1])
        l.append(i)
    if counter[i]>=4:
        ans=max(ans,i*i)
    if ans!=0:
        print(ans)
        exit()
print(0)

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

for i in range(N-1):
    if A[i]==A[i+1]:
        A[i+1]=0
    else:
        A[i]=0

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

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

arr=[]
for k,v in A.items():
    if v>1:
        arr.append(k)
    if v>3:
        arr.append(k)

if len(arr)<=1:
    print(0)
else:
    arr_s=sorted(arr,reverse=True)
    print(arr_s[0]*arr_s[1])

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
X = []
for i in range(N):
  if i == 0:
    cnt = A[i]
  else:
    if A[i] == cnt:
      X.append(A[i])
      cnt = 0
    else:
      cnt = A[i]
if len(X) >= 2:
    print(X[0]*X[1])
else:
  print(0)

Solution (Python):
N=int(input())
d={}

for i in input().split():
	x=int(i)
	if x not in d:d[x]=1
	else:d[x]+=1

cnt=0
ans=1
for t in sorted(d.items(),reverse=True):
	if t[1]>=2:
		ans*=t[0]
		cnt+=1
	if cnt==1 and t[1]>=4:
		ans*=t[0]
		cnt+=1
	if cnt>=2:
		break

print(ans if cnt>=2 else 0)

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

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
a += [0]
b = -1
ans = [0,0]
count = 0
for i in range(n+1):
    count += 1
    if b != a[i]:
        if count >= 4:
            if ans[0]:
                ans[1] = b
                break
            else:
                ans[0] = b
                ans[1] = b
                break
        elif count >= 2:
            if ans[0]:
                ans[1] = b
                break
            else:ans[0] = b
        b = a[i]
        count = 0
print(ans[0]*ans[1])

Solution (Python):
import collections

n = int(input())
a = list(map(int, input().split()))
li = collections.Counter(a)
square = 0
rectangle = []
for i in li:
    if li[i] >= 2:
        rectangle.append(i)
    if li[i] >= 4:
        square = max(square, i)

rectangle.sort()

if len(rectangle) < 2 and square == 0:
    print(0)
elif len(rectangle) < 2:
    print(square**2)
else:
    print(max(square**2, rectangle[-1] * rectangle[-2]))

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)

for i in a:
    d[i] += 1

tmp = sorted(d.items(), reverse=True)
cnt = 0
ans = 0
for i, j in tmp:
    if cnt == 0 and j >= 4:
        ans = i * i
        break
    if j >= 2 and cnt == 0:
        ans += i
        cnt += 2
    elif j >= 2 and cnt == 2:
        ans = ans * i
        break

print(ans)

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

A.sort(reverse = True)
max_num = []
before_num = 0

for j in A:
        if before_num == j:
                max_num.append(j)
                if len(max_num) == 2:
                        break
                else:
                        before_num = 0
        else:
                before_num = j

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

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
sides = [0, 0]

for i in a.keys():
    if a[i] >= 4:
        sides.append(i)
        sides.append(i)
    elif a[i] >= 2:
        sides.append(i)

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

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
sides = [0, 0]

for i in a.keys():
    if a[i] >= 4:
        sides.append(i)
        sides.append(i)
    elif a[i] >= 2:
        sides.append(i)

sides.sort()
print(sides.pop() * sides.pop())

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):
from collections import Counter
n = int(input())
li = list(map(int, input().split()))
counter = Counter(li)
dic = {}
for key, val in counter.items():
    if val >= 2:
        dic[key] = val

if len(dic) == 0:
    print(0)
elif len(dic) == 1:
    key, val = dic.popitem()
    if val >= 4:
        print(key*key)
    if val <= 3:
        print(0)
elif len(dic) >= 2:
    sort = sorted(dic.items(), key=lambda x:x[0], reverse=True)
    k1, v1 = sort[0]
    k2, v2 = sort[1]
    if v1 >= 4:
        print(k1*k1)
    elif v1 <= 3:
        print(k1*k2)

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

x, y = 0, 0

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

while i < n - 1:
    if a[i] == a[i + 1]:
        y = a[i]
        i += 2
        break
    i += 1
print(x * y)

Solution (Python):
from collections import Counter
n=int(input())
a=sorted([int(i) for i in input().split()])
cnt=Counter(a)
key=sorted(list(cnt.keys()))[::-1]
one=two=0
for i in key:
    if cnt[i]>=4 and one==0:
        one=two=i
        break
    elif cnt[i]>=2:
        if one==0:
            one=i
        else:
            two=i
            break
print(one*two)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
A.sort(reverse=True)
cout = 0
for i in range(1, len(A)):
    if A[i] == A[i - 1]:
        cout = i
        break
for i in range(cout + 2, len(A)):
    if A[i] == A[i - 1]:
        print(A[cout] * A[i])
        break
if cout == 0:
    print(0)

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

a,b = 0,0
i = 0
while i<=len(li)-2:
    if li[i] == li[i+1] and a == 0:
        a = li[i]
        i += 2
    elif li[i] == li[i+1]  and a != 0:
        b = li[i]
        break
    elif li[i] != li[i+1]:
        i += 1
print(a*b)

Solution (Python):
import sys
import math
from fractions import gcd

from collections import Counter



def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))
Ls = sorted(list(set(L[:])),reverse=True)
Lc = Counter(L)

A = 0

for l in Ls:
    if A == 0:
        if Lc[l] >= 4:
            print(l * l)
            exit()
        if Lc[l] >= 2:
            A = l
    else:
        if Lc[l] >= 2:
            print(A * l)
            exit()

print(0)

Solution (Python):
from collections import defaultdict
from collections import deque
N = int(input())
dict = defaultdict(int)
for a in [int(x) for x in input().split()]:
  dict[a] += 1

ab = deque([])
for a, cnt in dict.items():
  if cnt > 1:
    ab.append((a, cnt))

ab = sorted(list(ab), reverse=True)
i = 4
ret = 1
for abc in ab:
  if i == 2:
    ret *= abc[0]
    i = 0
    break
  elif abc[1] >= 4:
    ret = abc[0] ** 2
    i = 0
    break
  else:
    ret *= abc[0]
    i -= 2
if i:
  ret = 0
print(ret)

Solution (Python):
import collections

n = int(input())
ls = list(map(int, input().split()))
counter = collections.Counter()
for a in ls:
    counter[a] += 1
ls = [(k, v) for k, v in counter.items() if v > 1]
ls.sort(reverse=True)
m = len(ls)
if m >= 1 and ls[0][1] >= 4:
    print(ls[0][0]**2)
elif m >= 2:
    print(ls[0][0] * ls[1][0])
else:
    print(0)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()
A = III()

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1

A = list(set(A))
A.sort(reverse=True)

l1 = 0
l2 = 0
for a in A:
    if d[a]>=2:
        if l1==0:
            l1 = a
        else:
            l2 = a
            break
        d[a] -= 2
        if d[a]>=2:
            l2 = a
            break
    else:
        continue

print(l1*l2)

Solution (Python):


from collections import Counter

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

pair = [0, 0]
c = Counter(a)
for num, cnt in c.items():
    pair += [num] * (cnt // 2)

pair.sort(reverse=True)

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

Solution (Python):


from collections import Counter

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

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

cands = []
for num, cnt in li:
    if cnt >= 4:
        cands += [num, num]
    elif cnt >= 2:
        cands += [num]

cands += [0, 0]
ans = cands[0] * cands[1]
print(ans)

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

Solution (Python):
from collections import Counter
input()
a = list(map(int, input().split()))
ca = Counter(a)
sca = sorted(ca.items(), key=lambda x:-x[0])

h, w = 0, 0
for k, v in sca:
  if v >= 4:
    h = max(h, k)
    w = max(w, k)
  elif v >= 2:
    if h == 0:
      h = max(h, k)
    else:
      w = max(w, k)
  if h != 0 and w != 0:
    print(h*w)
    exit()
print(0)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]
L = []
flag = 0
for i in range(N-1):
    if A[i] == A[i+1] and flag == 0:
        L.append(A[i])
        flag = 1
    else:
        flag = 0

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

Solution (Python):
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        d[ai] += 1
    f = sorted([k for k, v in d.items() if v >= 2], reverse=True)
    if len(f) < 2:
        ans = 0
    else:
        if d[f[0]] >= 4:
            ans = max(f[0] ** 2, f[0] * f[1])
        else:
            ans = f[0] * f[1]
    print(ans)


if __name__ == "__main__":
    resolve()

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

e=[]
a.sort(reverse=True)
for i in range(len(a)-1):
  if a[i] == a[i+1] and a[i] not in e:
    e.append(a[i])
    if len(e) == 2:
      break
e.sort(reverse=True)

c4 = 0
for i in e:
  if a.count(i)>=4:
    c4=i
    break

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

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = collections.defaultdict(int)
    for a in A:
        d[a] += 1
    for k,v in list(d.items()):
        if v < 2:
            d.pop(k)
    d = sorted(d.items(), key=lambda x: x[0], reverse=True)
    if len(d) >= 1 and d[0][1] >= 4:
        print(d[0][0]**2)
    elif len(d) >= 2:
        print(d[0][0]*d[1][0])
    else:
        print(0)

if __name__ == '__main__':
    main()

Solution (Python):
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
two = []
four = []
for j, k in dic.items():
	if k>=4:
		four.append(j)
	if k>=2:
		two.append(j)
two.sort(reverse=True)
four.sort(reverse=True)
if len(four) == 0:
	if len(two) <= 1:
		print(0)
	else:
		print(two[0]*two[1])	
else:
	if len(two) <= 1:
		print(four[0]**2)
	else:	
		print(max(two[0]*two[1], four[0]**2))

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

a = sorted(a, reverse=True)

count = 0
edge = []

i = 0
for _ in range(n-1):
    if a[i] == a[i+1]:
        count = count + 1
        edge.append(a[i])
        i = i + 1
        if count == 2:
            break
    i = i + 1

s = edge[0]*edge[1] if count == 2 else 0
print(s)

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

a = sorted(a, reverse=True)

count = 0
edge = []

i = 0
for _ in range(n-1):
    if a[i] == a[i+1]:
        count = count + 1
        edge.append(a[i])
        i = i + 1
        if count == 2:
            break
    i = i + 1

s = edge[0]*edge[1] if count == 2 else 0
print(s)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
count = 0
s = 1
i = 0
A.sort()
A.reverse()

while i < N-1 and count < 2:
  if A[i] == A[i+1]:
    s = s * A[i]
    count += 1
    i += 2
  else:
    i += 1

if count >= 2:
  print(s)
else:
  print(0)

Solution (Python):
import collections


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    c = collections.Counter(a)

    l = 0
    w = 0

    max_num = -1
    for k,v in c.items():
        if max_num < k and v >= 2:
            max_num = k

    if max_num != -1:
        l = max_num
        c[max_num] = c[max_num] - 2

    max_num = -1
    for k, v in c.items():
        if max_num < k and v >= 2:
            max_num = k

    if max_num != -1:
        w = max_num
        c[max_num] = c[max_num] - 2

    print(l*w)

Solution (Python):
import collections

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

d = collections.defaultdict(int)
edges = []
for edge in a:
    d[edge] += 1
    if d[edge] % 2 == 0:
        edges.append(edge)

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

Solution (Python):
from collections import Counter as C
input()
A=sorted(C(list(map(int,input().split()))).most_common())
a,b=0,0
for i,j in A:
  if j>=4:
    a=b=i
  elif j>=2:
    a=b
    b=i
print(a*b)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
used = [0] * n
a.sort(reverse=True)
x = 0
y = 0
for i in range(1,n):
    if a[i - 1] == a[i] and used[i-1] == 0 and used[i] == 0:
        if x == 0:
            x = a[i]
            used[i] = 1
            used[i-1] = 1
        elif y == 0:
            y = a[i]
            used[i] = 1
            used[i-1] = 1
            break
print(x*y)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
a = 0
b = 0
check = False

for i in range(1, N):
    if check == True:
        check = False
        pass
    else:
        if A[i-1] == A[i]:
            if a == 0:
                a = A[i]
            elif b == 0:
                b = A[i]
                print(a * b)
                exit()
            check = True

print(0)

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

N = int(input())

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

l = collections.Counter(A)

l24 =list([int(l1[0]) for l1 in l.items() if l1[1]>=2])

l24.sort(reverse=True)

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

Solution (Python):
N,*A=map(int,open(0).read().split());d={};r,c=0,0
for a in A:d[a]=d.get(a,0)+1
for l,n in d.items():r,c=sorted([r,c]+[l]*(n//2))[-2:]
print(r*c)

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

key = list(A.keys())
val = list(A.values())

quad = [key[i] for i in range(len(key)) if val[i] >= 4]
if len(quad) >= 1:
	quad = max(quad)
else:
	quad = 0

bi = sorted([key[i] for i in range(len(key)) if val[i] >= 2], reverse = True)
if len(bi) >= 2:
	bi_1 = bi[0]
	bi_2 = bi[1]
else:
	bi_1 = 0
	bi_2 = 0

print(max(quad**2, bi_1*bi_2))

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

ans = 1
cnt = 0
A.sort(reverse=True)
hikae = None
for e in A:
    if hikae is None:
        hikae = e
    elif hikae == e:
        ans *= e
        cnt += 1
        hikae = None
        if cnt == 2:
            print(ans)
            exit(0)
    else:
        hikae = e
print(0)