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 = sorted(a,reverse=True)

flag = True
for i in range(n-1):
  if flag :
    if a[i]==a[i+1]:
      hen1 =a[i]
      a[i+1]=-1
      flag =False
  elif not flag:
    if a[i]==a[i+1]:
      hen2 = a[i]
      print(hen1*hen2)
      exit()
print(0)

Solution (Python):



















from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

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

c = dict(Counter(A))
c = sorted(c.items(), key=lambda x: x[0])

max_one = None
max_two = None
max_sub = None
for k, v in c[::-1]:
    if v >= 4:
        if max_sub is None:
            max_sub = k
    if v >= 2:
        if max_one is None:
            max_one = k
        else:
            max_two = k
            break

if max_two is None:
    print(0)
elif max_sub is not None:
    sub_S = max_sub**2
    S = max_one * max_two
    if sub_S > S:
        print(sub_S)
    else:
        print(S)
else:
    print(max_one*max_two)

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
a=IL()
da={}
for l in a:
    if l in da:
        da[l]+=1
    else:
        da[l]=1
sda=sorted(da.keys(),reverse=True)
lens=[]
for l in sda:
    if da[l]>=4:
        if len(lens)==1:
            lens.append(l)
        else:
            print(l*l)
            break
    elif da[l]>=2:
        lens.append(l)
    
    if len(lens)==2:
        print(lens[0]*lens[1])
        break
else:
    print(0)

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
x, y = 0, 0
for k, v in d.items():
  if(v >= 2 and k > y):
    if(k >= x):
      if(v >= 4):
        y = k
      else:
        y = x
      x = k
    else:
      y = k
print(x * y)

Solution (Python):
import collections
n, c = int(input()), collections.Counter(sorted(list(map(int,input().split()))))
ck, cv, match, ans = list(c.keys()), list(c.values()), [], 0
for i in range(len(c)):
    if cv[i] >= 2:
        match.append([ck[i],cv[i]])
match.sort(key=lambda x:x[0])
ans = match[-1][0]**2 if len(match) >= 1 and match[-1][1] >= 4 else match[-1][0]*match[-2][0] if len(match) >= 2 else 0
print(ans)

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
l=[]
s=0
while True:
  if len(l)==2:print(l[0]*l[1]);exit()
  if s==n-1:print(0);exit()
  if a[s]==a[s+1]:
    s+=1
    l.append(a[s])
  s+=1

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

s=0
t=0
prev=-1
c=0
for a in A:
    if prev==a:
        c+=1
    else:
        prev=a
        c=1
    if c==2:
        if s==0:
            s=a
        elif t==0:
            t=a
            break
    if c==4 and t==0:
        t=a
        break
print(s*t)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
p=Counter(a)
c=0
d=0
for a,b in p.items():
    if b>3:
        if c<a:
            c=a
        if d<a:
            d=a
    elif b>1:
        if c==0:
            c=a
        else:
            if d>c and c<a:
                c=a
            elif d<=c and d<a:
                d=a
print(c*d)

Solution (Python):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
C=Counter(A)
cnt2=[]
cnt4=[]
for k,v in C.items():
    if v>=4:
        cnt4.append(k)
    if v>=2:
        cnt2.append(k)
ans=0
if len(cnt4)!=0:
    S_4=max(cnt4)**2
    ans=S_4
if len(cnt2)>=2:
    cnt2=sorted(cnt2,reverse=True)
    S_2=cnt2[0]*cnt2[1]
    ans=max(ans,S_2)
print(ans)

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

ans = 1
flag = 0
count = 0
for i in range(N-1):
    if count >= 2:
        break
    if A[i+1] == A[i] and A[i] > 0:
        ans *= A[i]
        A[i],A[i+1] = 0,0
        flag = 1
        count += 1
        
if flag == 0:
    print(0)
else:
    print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
cur = A[0]
cnt = 0
ans = []
for ai in A:
    if ai==cur: cnt += 1
    else: 
        cur = ai
        cnt = 1
    if cnt==2 or cnt==4:
        ans.append(cur)
    if len(ans)==2:
        print(ans[0]*ans[1])
        break
else:
    print(0)

Solution (Python):

N=int(input()) 
A=list(map(int,input().split()))
A.sort() 
max1=0
max2=0
if A[0]==A[1]:
        a=max1
        max1=A[0]
        max2=a     
for i in range(2,len(A)-1): 
    if A[i]==A[i+1] and (A[i]!=A[i-1] or  A[i]==A[i-1]==A[i-2]):
        a=max1
        max1=A[i]
        max2=a 
print(max1*max2)

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
a = collections.Counter(A)
alist = a.most_common()
alen = len(a)
alist.sort(reverse=True)
kari = 0
flag = 0
for i in range(alen):
    if alist[i][1] >= 4 and kari == 0:
        print(alist[i][0]*alist[i][0])
        flag = 1
        break
    elif alist[i][1] >= 2:
        if kari > 0:
            print(kari*alist[i][0])
            flag = 1
            break
        else:
            kari = alist[i][0]
    else:
        pass
if flag == 0:
    print(0)

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

print(max(s,t))

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

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

b.sort(reverse=True)
f.sort(reverse=True)

d = 0
if len(f) != 0:
    d = max(f)**2

if len(b) >= 2:
    print(max(b[0]*b[1],d))
else:
    print(0)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
b = set()
now = float("inf")
now3 = [float("inf")]*3
for k in a:
        if k == now3[0] == now3[1] == now3[2]:
            print(k**2)
            break
        if k == now:
                b.add(k)
        if len(b) == 2:
            b = list(b)
            print(b[0]*b[1])
            break
        now = k
        now3.append(k)
        now3.pop(0)
else:
    print(0)

Solution (Python):
from collections import Counter


def solve(N, As):
    c = Counter(As)
    two = sorted([i for i, v in c.items() if v >= 2])
    four = [i for i, v in c.items() if v >= 4]
    ans = 0
    if len(two) >= 2:
        ans = two[-1] * two[-2]
    if len(four):
        ans = max(max(four) * max(four), ans)
    return ans


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

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

d = {}
for i in range(N):
    if A[i] not in d.keys():
        d[A[i]] = 0
    d[A[i]] += 1

m1 = 0
m2 = 0
for k in sorted(list(d.keys()),reverse=True):
    if d[k] >= 2 and m1 == 0:
        m1 = k
    elif d[k] >= 2 and m1 != 0:
        m2 = k
        break


if m1 != 0:
    if d[m1] >= 4:
        print(m1*m1)
    else:
        print(m1*m2)
else:
    print(0)

Solution (Python):
def solve():
    N = int(input())
    a = [int(x) for x in input().split()]

    import collections
    count = collections.Counter(a)

    valid = {k: v for k, v in count.items() if v >= 2}

    

    m = sorted(valid.items(), reverse=True)

    if len(valid) == 0:
        return 0
    elif m[0][1] >= 4:
        return m[0][0] ** 2
    elif len(valid) >= 2:
        return m[0][0] * m[1][0]
    else:
        return 0


def main():
    print(solve())


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
x1, x2, x3 = 0, 0, 0
for k, v in c.items():
    if v >= 4:
        if k > x1:
            x1 = k
    if v >= 2:
        if k > x2:
            x2, x3 = k, x2
        elif k > x3:
            x3 = k
print(max(x1*x1, x2*x3))

Solution (Python):
from collections import Counter
n = int(input())
A = Counter([int(i) for i in input().split()])
l4 = [0]
l2 = [0]

for k, v in A.items():
    if v >= 4:
        l4.append(k)
        l2.append(k)
    elif v >= 2:
        l2.append(k)
        
if max(l4) >= max(l2):
    print(max(l4) ** 2)
else:
    x = sorted(l2, reverse=True)
    print(x[0] * x[1])

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

n = int(input())
dic = {}
A = list(map(int, input().split()))
for a in A:
    if a not in dic:
        dic[a] = 1
    else:
        dic[a] += 1
nums = list(dic.items())
nums.sort(reverse = True)
l = len(nums)
l1 = 0
for i in range(l):
    if l1 == 0 and nums[i][1] >= 4:
        ans = nums[i][0]**2
        break
    elif l1 == 0 and nums[i][1] >= 2:
        l1 = nums[i][0]
    elif l1 > 0 and nums[i][1] >= 2:
        ans = l1*nums[i][0]
        break
else:
    ans = 0
print(ans)

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

res = A[0]
cnt = 1
use = []
for i in range(1, N):
    if A[i] == res:
        cnt += 1
    else:
        cnt = 1
        res = A[i]

    if cnt >= 2:
        use.append(A[i])
        cnt -= 2

    if len(use) >= 2:
        break

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

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter()
for a in A:
    c[a] += 1
candidate = []
for k, v in c.most_common():
    if v >= 4:
        candidate.append(k)
        candidate.append(k)
    elif v >= 2:
        candidate.append(k)
candidate.sort()

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

Solution (Python):
import collections as cl

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

sticks.sort(reverse=True)

w = 0
h = 0

for k,v in sorted(cl.Counter(sticks).items(), key=lambda x: x[0], reverse=True):
    if (v < 2) :
        continue
    
    if (v >= 4) :
        
        if (w == 0) :
            w = k
            h = k
        else :
            h = k
        break
    
    if (v >= 2) :
        if (w == 0) :
            w = k
        else :
            h = k
            break


print(w*h)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
switch = 1
ans = []

for i in range(n-1):
    if switch == 1:
        if A[i] == A[i+1]:
            ans.append(A[i])
            switch = 0
    else: 
        switch = 1

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

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

A.sort()

A = A[::-1]

B = []
F = False

for i in range(N-1):
    if F == True:
        F = False
        continue
    elif A[i+1] == A[i]:
        B.append(A[i])
        F = True

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
check = [0,0];c = 0;check_num = 0
for i in range(len(a)-1):
    if c == 1:
        c = 0
        continue
    if check_num == 2:break
    if a[i] == a[i+1]:
        check[check_num] = a[i]
        check_num += 1
        c = 1
print(check[0]*check[1])

Solution (Python):
n = int(input())
a = sorted(list(int(i) for i in input().split()),reverse=True)
ans = []
for i in range (n-1):
 if a[i+1] == a[i]:
  ans.append(a[i])
  a[i+1]= 0
 if len(ans)>=2:
  cand = ans[0]*ans[1]
  break
else:
 cand = 0
print(cand)

Solution (Python):
import collections

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

dic = collections.Counter(A).most_common()

tmp = []
check = 0

dic.sort(reverse=True)

for a, b in dic:
    if b >= 2:
        check += 1
        tmp.append(a)
        if b>= 4:
            break
        if check == 2:
            break

if len(tmp) == 0:
    print(0)
elif len(tmp) == 1:
    print(tmp[0]*tmp[0])
else:
    print(tmp[0] * tmp[1])

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

import collections
 
c=collections.Counter(a)
l=c.most_common()

from operator import itemgetter

l.sort(key=itemgetter(0))   
l.reverse()

ans=[]
for i,j in l:
    if j>=4:
        ans.append(int(i))
        ans.append(int(i))
        break
    if j>=2:
        ans.append(int(i))
        if len(ans)==2:
            break

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

Solution (Python):
N = int(input())
arr = sorted(list(map(int,input().split())))
b = {}
for i in arr:
  if i not in b:
      b[i] = 1
  else:
      b[i] += 1
h = 0
w = 0
b1 = sorted(b)[::-1]
for i in b1:
    if b[i] >= 4:
        if h < i:
            h = i
            w = i
            break
        else:
            w = i
            break
    elif b[i] >= 2:
        if h == 0:
            h = i
        else:
            w = i
            break
        
print(h*w)

Solution (Python):
def abc071_c():
    from collections import Counter
    _ = int(input())
    a = list(map(int, input().split()))
    a_count = Counter(a)
    ans = 1

    if len(a_count) == 1:
        print(a[0] ** 2)
    elif a_count.most_common()[1][1] < 2:
        print(0)
    else:
        tmp = 0
        for v in sorted(set(a), reverse=True):
            if tmp == 2:
                break
            if tmp == 0 and a_count[v] >= 4:
                ans = v**2
                break
            if a_count[v] >= 2:
                ans *= v
                tmp += 1
        print(ans)


abc071_c()

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

A.sort(reverse=True)
x = 0
y = 0
prev = 0
cnt = 0
for e in A:
    if e == prev:
        cnt += 1
        if x == 0:
            x = e
        elif e != x or cnt >= 4:
            y = e
            break
    else:
        cnt = 0
    prev = e

print(x*y)

Solution (Python):
from collections import Counter

input()
c = sorted(
    filter(lambda x: x[1] >= 2, Counter([int(i) for i in input().split()]).items()),
    key=lambda x: x[0], reverse=True)
a, b = 0,0
for i in c:
    key = i[0]
    count = i[1]
    if count >= 4 and not a and not b:
        a, b = key, key
        break
    if count >= 2:
        if not a:
            a = key
        else:
            b = key
            break
print(a*b)

Solution (Python):
from collections import Counter


def main():
    _ = input()
    aa = list(map(int, input().split()))
    counts = Counter(aa)
    counts = {k: v for k, v in counts.items() if v >= 2}
    sides = []
    for k in sorted(counts.keys(), reverse=True):
        while counts[k] >= 2:
            counts[k] -= 2
            sides.append(k)
            if len(sides) == 2:
                print(sides[0] * sides[1])
                return
    print(0)


if __name__ == '__main__':
    main()

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
j=[];x=-2
for i in range(n-1):
  if a[i]==a[i+1] and x!=i:
    j.append(a[i])
    x=i+1
  if len(j)>=2:
    break
j.append(0)
j.append(0)
print(j[0]*j[1])

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

b = []
for key, item in a.items():
    if item >= 2:
        b.append((key, item))

b.sort(key=lambda x: -x[0])

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

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

cnt = Counter(a)

first = 0
second = 0

keys = list(cnt.keys())
keys.sort(reverse=True)

for k in keys:
    if first != 0 and second != 0:
        break
    
    if first == 0 and second == 0 and cnt[k] >= 4:
        first = k
        second = k
        
    elif first != 0 and cnt[k] >= 2:
        second = k
        
    elif cnt[k] >= 2:
        first = k
        
print(first * second)

Solution (Python):
input()
a=[int(i) for i in input().split()]
a.sort(reverse=True)
tyo=0
tan=0
tb=0
for i in range(len(a)-1):
  if tb==1:
    tb=0
  else:
    if a[i]==a[i+1] and tyo==0:
      tyo=a[i]
      tb=1
    elif a[i]==a[i+1]:
      tan=a[i]
      break
print(tyo*tan)

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

flag_h = True
flag_v = True
h, v = 0, 0

for i in A:
    if flag_h:
        if h == i:
            flag_h = False
        else:
            h = i
    elif flag_v:
        if v == i:
            flag_v = False
        else:
            v = i

if not (flag_v and flag_h):
    print(h * v)
else:
    print(0)

Solution (Python):
import collections

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

stick_num = collections.Counter(A)
flag = True
ans = 0
for i in sorted(stick_num, reverse=True):
    if stick_num[i] >= 4:
        ans = i * i if flag else a * i
        break
    elif stick_num[i] >= 2:
        if flag:
            a = i
            flag = False
        else:
            ans = a * i
            break

print(ans)

Solution (Python):
n = int(input())
num_list = list(map(int, input().split()))
dic = {}
ans_list = []
for i in num_list:
    dic[i] = 0
for i in num_list:
    dic[i] += 1
    if dic[i] == 2:
        ans_list.append(i)
    elif dic[i] == 4:
        ans_list.append(i)
re_ans_list = sorted(ans_list, reverse = True)
if len(re_ans_list) < 2:
    print(0)
else:
    print(re_ans_list[0]*re_ans_list[1])

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
table = {}
for a in A:
    if a in table.keys():
        table[a] += 1
    else:
        table[a] = 1
rectangle1 = 0
rectangle2 = 0
square = 0
for k, v in table.items():
    if v > 3:
        square = max(square, k)
    if v > 1:
        rectangle1, rectangle2 = sorted(
            [rectangle1, rectangle2, k], reverse=True)[:-1]
print(max(square**2, rectangle1*rectangle2))

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int,input().split()))
A = Counter(A).most_common()
ans = 0

for i,j in sorted(A,reverse=True):
  if j >=4 and ans ==0:
    ans = i*i
    break
  elif j >= 2 and ans == 0:
    ans = i
  elif j >= 2:
    ans *= i
    break
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
num_list = list(map(int,input().split()))
cntr = Counter(num_list).most_common()
ans = 0

for num,cnt in sorted(cntr,reverse=True):
    if cnt >= 4 and ans == 0:
        ans = num*num
        break
    elif cnt >= 2 and ans == 0:
        ans = num
    elif cnt >= 2:
        ans *= num
        break
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
out = [0, 0]
i = n - 1
while i > 0:
    
    if a[i] == a[i-1]:
        out[0] = a[i]
        i -= 2
        break
    i -= 1

while i > 0:
    if a[i] == a[i-1]:
        out[1] = a[i]
        break
    i -= 1
print(out[0] * out[1])
"""
maxSquare = 0
for i in range(n-3):
    for j in range(i+1, n-2):
        for k in range(j+1, n-1):
            for l in range(k+1, n):
                
                if a[i] == a[j] and a[k] == a[l]:
                    maxSquare = max(maxSquare, a[i]*a[k])
                    
                elif a[i] == a[k] and a[j] == a[l]:
                    maxSquare = max(maxSquare, a[i] * a[j])
                    
                elif a[i] == a[l] and a[j] == a[k]:
                    maxSquare = max(maxSquare, a[i] * a[j])
                    
print(maxSquare)
"""

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
d = {}
for i in c:
    if c[i] >= 2:
        d[i] = c[i]

if d != {}:
    dct = sorted(d.items(), key=lambda x: -x[0])
    if len(d) == 1:
        if dct[0][1] >= 4:
            print(dct[0][0] ** 2)
        else:
            print(0)
    else:
        if dct[0][1] >= 4:
            print(dct[0][0] ** 2)
        else:
            print(dct[0][0] * dct[1][0])
else:
    print(0)

Solution (Python):
import collections

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

con = collections.Counter(A).most_common()
ans = 0

for a, b in sorted(con, reverse= True):
    if b >= 4 and ans == 0:
        print(a**2)
        break
    elif b >= 2 and ans == 0:
        ans = a
    elif b >= 2:
        print(ans*a)
        break
else:
    print(0)

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

A.sort(reverse=True)

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

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

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a).most_common()
b.sort(key=lambda x:x[0],reverse=True)
s=0
t=0
for len in b:
    if s==0 and len[1]>=4:
        print(len[0]**2)
        exit()
    elif s==0 and len[1]>=2:
        s=len[0]
    elif s!=0 and len[1]>=2:
        print(s*len[0])
        exit()
print(0)

Solution (Python):
import collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=list(s.items())

a=0
f=[]
for i in s:
    if i[1]>=4:
        f.append(i[0])
        f.append(i[0])
    elif i[1]>=2:
        f.append(i[0])

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

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
A.sort(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):
N=int(input())
A=[int(i) for i in input().split()]

A.sort(reverse=True)

x=0
y=0
for i in range(N-1):
      if A[0]==A[1]:
          x=A[0]
          A.remove(x)
          A.remove(x)
          break
      else:
          A.remove(A[0])
if len(A)>=2:
    for i in range(len(A)-1):
        if A[0]==A[1]:
            y=A[0]
            break
        else:
            A.remove(A[0])

print(x*y)

Solution (Python):
import collections
N=int(input())
A=list(map(int,input().split()))
AC=collections.Counter(A)
AM=AC.most_common()
AM.sort(reverse=True)

H=0
for i in range(len(AM)):
    if H==0:
        if AM[i][1]>=4:
            print(AM[i][0]**2)
            exit()
        elif AM[i][1]>=2:
            H=AM[i][0]
    else:
        if AM[i][1]>=2:
            
            print(AM[i][0]*H)
            exit()
print(0)

Solution (Python):

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

A.sort()

view = 10 ** 9 + 7
lengths = [0] * 2
idx = 0
for Ai in reversed(A):
    if Ai < view:
        view = Ai
        cnt = 0
    cnt += 1
    if cnt >= 2:
        lengths[idx] = view
        cnt = 0
        idx += 1
    if idx > 1: break


print(lengths[0] * lengths[1] if idx > 1 else 0)

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

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

import collections
A_c=collections.Counter(A)


keys = [k for k, v in A_c.items() if v >= 2]

keys.sort()

if len(keys) < 2:
	ans = 0
elif A_c.get(keys[len(keys)-1]) >= 4:
	ans = keys[len(keys)-1] * keys[len(keys)-1] 
else:
	ans = keys[len(keys)-1] * keys[len(keys)-2]

print(ans)

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

choice = []
candidate = set()
for i in range(N):
    if A[i] not in candidate:
        candidate.add(A[i])
    else:
        choice.append(A[i])
        candidate.remove(A[i])

try:
    side1 = max(choice)
except:
    side1 = 0

try:
    choice.remove(side1)
except:
    a = 0

try:
    side2 = max(choice)
except:
    side2 = 0
    
    
ans = side1*side2

print(ans)

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

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

h = []
for x, y in d.items():
    if y >= 4:
        h.append(x)
        h.append(x)
    elif y >= 2:
        h.append(x)

if len(h) < 2:
    print(0)
else:
    h = list(sorted(h))
    print(h[len(h)-1] * h[len(h)-2])

Solution (Python):
import collections
N = int(input())
A = list(map(int, input().split()))
count = collections.Counter(A)
count = count.most_common()
count.sort()
count.reverse()
ans = []
for i in range(len(count)):
    if len(ans) == 0:
        if count[i][1] >= 4:
            ans.append(count[i][0])
            ans.append(count[i][0])
    if count[i][1] >= 2:
        ans.append(count[i][0])
        if len(ans) >= 2:
            break
if len(ans) < 2:
    print(0)
else:
    print(ans[0] * ans[1])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
m = {}
targets = []
for a in A:
    m.setdefault(a, 0)
    m[a] += 1
    if m[a] == 2:
        targets.append(a)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
bars = {}
for i in a:
    if i in bars:
        bars[i] += 1
    else:
        bars[i] = 1
bars = sorted(bars.items(), key=lambda x: -x[0])

ans1 = 0
ans2 = 0
for i in bars:
    if i[1] >= 4:
        if ans1 == 0:
            ans1 = i[0]
            ans2 = i[0]
        else:
            ans2 = i[0]
        break
    elif i[1] >= 2:
        if ans1 == 0:
            ans1 = i[0]
        else:
            ans2 = i[0]
            break
print(ans1 * ans2)

Solution (Python):
def 解():
    iN = int(input())
    m2_2 = 0 
    m2 = 0 
    m3 = 0 
    m4 = 0 
    d = set()
    for a in [int(_) for _ in input().split()]:
        if a in d:
            if  m2 < a :
                m2_2 = m2
                m2 = a
            elif m2 == a :
                if m3 < a :
                    m3 = a
                elif m3 == a:
                    if m4 < a:
                        m4 = a
            elif m2_2 < a:
                    m2_2 = a
        else:
            d.add(a)
    print(max(m2*m2_2,m4**2))
解()

Solution (Python):
def 解():
    iN = int(input())
    iNow = 0
    iMem = 0
    iC = 0
    d = {}
    for a in reversed(sorted([int(_) for _ in input().split()])):
        if iNow == a:
            iC += 1
        else:
            iC = 1
            iNow = a
        if iC == 2:
            if iMem :
                print(iMem * iNow)
                exit()
            else:
                iMem = a
        elif iC == 4:
            print(iMem**2)
            exit()
    print(0)
解()

Solution (Python):
def 解():
    iN = int(input())
    iC = 0
    d = {}
    for a in reversed(sorted([int(_) for _ in input().split()])):
        if a in d:
            if d[a] == 3:
                print(a*a)
                exit()
            elif iC and iC != a:
                print(iC * a)
                exit()
            else:
                iC = a
                d[a] += 1
        else:
            d[a] = 1
    print(0)
解()

Solution (Python):
def 解():
    iN = int(input())
    aA = reversed(sorted([int(_) for _ in input().split()]))
    iC = 0
    d = {}
    for a in aA:
        if a in d:
            if d[a] == 3:
                print(a*a)
                exit()
            elif iC and iC != a:
                print(iC * a)
                exit()
            else:
                iC = a
                d[a] += 1
        else:
            d[a] = 1
    print(0)
解()

Solution (Python):
import collections

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

for i in a:
    if a[i] >= 4:
        array += [i, i]
    elif a[i] >= 2:
        array.append(i)

array.sort()
array.reverse()
print(array[0]*array[1])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
flag = 0
result = [0, 0]

while len(A) >= 2 and flag < 2:
    N = A.pop(0)
    if N == A[0]:
        result[flag] = N
        del A[0]
        flag += 1

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

Solution (Python):
N = int(input())
L = list(map(int, input().split()))
L.sort()
a = [0,0]
count = 0
for i in range(N):
    count += 1
    if i == N-1:
        if count >= 2:
            a.append(L[i])
        if count >= 4:
            a.append(L[i])
        count = 0
        
    elif L[i] != L[i+1]:
        if count >= 2:
            a.append(L[i])
        if count >= 4:
            a.append(L[i])
        count = 0
            
print(a[-1]*a[-2])

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

d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
for i in d:
    d[i] //= 2

ans = []
for i in d:
    ans += [int(i)] * int(d.get(i))
if len(ans) >= 2:
    ans.sort()
    print(ans[-1] * ans[-2])
else:
    print(0)

Solution (Python):

import itertools

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

dict1 = {}
for A in An:
    if A in dict1:
        dict1[A] += 1
    else:
        dict1[A] = 1

h,w = 0,0
for k,v in sorted(dict1.items(), key=lambda x: -x[0]):
    if v < 2:
        continue
    if v >= 4 and h == 0 and w == 0:
        h,w = k,k
        break
    if h == 0:
        h = k
        continue
    if w == 0:
        w = k
        break
print(h*w)

Solution (Python):
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]

L = defaultdict(int)
for a in A:
    L[a] += 1
Lkey = sorted(L, reverse = True)

for i in range(len(Lkey)):
    if L[Lkey[i]] >= 4:
        print(Lkey[i]**2)
        break
    elif L[Lkey[i]] >= 2:
        for j in range(i+1, len(Lkey)):
            if L[Lkey[j]] >= 2:
                print(Lkey[i] * Lkey[j])
                break
        break
else:
    print(0)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
l = []
for k in c:
  if c[k] >= 4:
    l += [k, k]
  elif c[k] >= 2:
    l += [k]
l.sort()
l.reverse()
if len(l)<2:
  print(0)
else:
  print(l[0]*l[1])