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=sorted(list(map(int,input().split())),reverse=True)
x,y=0,0
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
b=groupby(a)
l=len(b)
for i in range(l):
    if x==0:
        if b[i][1]>=4:
            x,y=b[i][0],b[i][0]
        elif b[i][1]>=2:
            x=b[i][0]
    elif y==0:
        if b[i][1]>=2:
            y=b[i][0]
    else:
        break
print(x*y)

Solution (Python):
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if not ans_lis:
    print(0)
    sys.exit()

if len(ans_lis) == 1 and ans_lis[0][1] < 4:
    print(0)
elif len(ans_lis) == 1 and ans_lis[0][1] >= 4:
    print(ans_lis[0][0] ** 2)
elif len(ans_lis) >= 2:
    area_1 = ans_lis[0][0] * ans_lis[1][0]
    area_2 = 0
    if ans_lis[0][1] >= 4:
        area_2 = ans_lis[0][0] ** 2
    print(max(area_1, area_2))

Solution (Python):
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if len(ans_lis) <= 1 or ans_lis[0][1] is None:
        print(0)
        sys.exit()

area_1 = ans_lis[0][0] * ans_lis[1][0]
area_2 = 0
if ans_lis[0][1] >= 4:
    area_2 = ans_lis[0][0] ** 2
print(max(area_1, area_2))

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
H=0
W=0
for i in range(N-1):
  if A[i]==A[i+1]:
    H=A[i]
    A[i]=0
    A[i+1]=0
    break
A.sort(reverse=True)
for i in range(N-1):
  if A[i]==A[i+1]:
    W=A[i]
    A[i]=0
    A[i+1]=0
    break
print(H*W)

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

A_dic = dict()
for i in range(N):
    if A[i] in A_dic:
        A_dic[A[i]] += 1
    else:
        A_dic[A[i]] = 1
        
max_key = 0
sub_max_key = 0
for k, v in A_dic.items():
    if v <= 1:
        pass
    elif v <= 3:
        if k > max_key:
            sub_max_key = max_key
            max_key = k
        elif k > sub_max_key:
            sub_max_key = k
    else:
        if k > max_key:
            sub_max_key = k
            max_key = k
            
print(max_key * sub_max_key)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]
import collections
c = collections.Counter(A)
d = c.items()
e = []
for i in d:
    if i[1] >= 4:
        e.append(i[0])
        e.append(i[0])
    elif i[1] >= 2:
        e.append(i[0])
if len(e) < 2:
    print(0)
    sys.exit()
e = sorted(e,reverse=True)
print(e[0] * e[1])

Solution (Python):
import sys

n, *l = map(int, sys.stdin.read().split())

def main():
    l.sort(reverse=True)

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [a[0]]
cnt = 1
for i in range(1, n):
	if a[i] == b[-1]:
		b.append(a[i])
		cnt = cnt + 1
	else:
		if (cnt & 1):
			b.pop()
		b.append(a[i])
		cnt = 1
if (cnt & 1):
	b.pop()
if len(b) < 4:
	print(0)
else:
	print(b[-1] * b[-3])

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

r = []
i = 0
while i < n:
    if i < n - 1 and a[i] == a[i + 1]:
        r.append(a[i])
        i += 2
    else:
        i += 1
    if len(r) == 2:
        break
if len(r) == 2:
    print(r[0] * r[1])
else:
    print(0)

Solution (Python):
import collections
dd = collections.defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
candidate = []
for i in range(n):
    dd[str(a[i])] += 1
for k in dd.keys():
    if dd[k] >= 2:
        candidate.append(int(k))
    if dd[k] >= 4:
        candidate.append(int(k))
candidate.sort(reverse=True)
if len(candidate) < 2:
    print(0)
else:
    print(candidate[0] * candidate[1])

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
C=collections.Counter(A)
S=sorted(C.items(),reverse=True)

for si in S:
    c=si[1]//2
    if count==0 and c==1:
        ans=si[0]
        count +=1
    elif count==0 and c>=2:
        print(si[0]**2)
        exit()
    elif count==1 and c>=1:
        print(ans*si[0])
        exit()
    
print(0)

Solution (Python):
from collections import Counter
n = int(input())
l = [int(i) for i in input().split()]
c = sorted(Counter(l).most_common(),key = lambda x : -x[0])

edge = []
for i in c:
    if i[1] >= 4:
        edge.append(i[0])
        break
    elif i[1] >= 2:
        edge.append(i[0])
        if len(edge) == 2:
            break
    else:
        pass
    
print(edge[0]**2 if len(edge) == 1 else edge[0]*edge[1] if edge else 0)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=list(Counter(a).items())
c.sort(reverse=True)
ans=0
for a,b in c:
    if(b>=4):
        if(ans==0):
            print(a*a)
            exit()
        else:
            print(ans*a)
            exit()
    elif(b>=2):
        if(ans!=0):
            print(ans*a)
            exit()
        else:
            ans=a
print(0)

Solution (Python):
import collections

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

over_two = collections.Counter(A)
Over_two = []
Over_four = []

for key, val in over_two.items():
    if val <= 1:
        pass
    elif val >= 4:
        Over_four.append(key)
        Over_two.append(key)
    else:
        Over_two.append(key)

Over_four.append(0)
Over_two.append(0)
Over_two.append(0)

Over_two = sorted(Over_two, reverse=True)
Over_four = sorted(Over_four, reverse=True)

can_one = Over_four[0] * Over_four[0]
can_two = Over_two[0] * Over_two[1]

ans = max(can_one, can_two)

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=list(Counter(a).items())
c.sort(reverse=True)
hen=0
ans=[0]
for a,b in c:
  if b>=4:
    if hen==0:
      ans.append(a**2)
    else:
      ans.append(hen*a)
  elif b>=2:
    if hen==0:
      hen=a
    else:
      ans.append(hen*a)
  else:
    continue
print(max(ans))

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

flag = True
pairs = []
for i in range(1, len(a)):
    if flag:
        if a[i] == a[i-1]:
            pairs.append(a[i])
            if len(pairs) == 2:
                print(pairs[0]*pairs[1])
                exit()
            flag = False
    else:
        flag = True
print(0)

Solution (Python):
import sys
from collections import Counter
from operator import itemgetter
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

C = Counter(A).most_common()
C = sorted(C, key=itemgetter(0), reverse=True)

x, y = 0, 0
for c in C:
	if c[1] >= 4:
		if c[0] >= x:
			x, y = c[0], c[0]
		else:
			y = c[0]
	elif c[1] >= 2:
		if x != 0: y = c[0]
		else: x = c[0]
	if x!=0 and y!=0: break


print(x*y)

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))
 
from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v >= 4:
        if w == 0:
            w = h = k
            break
        else:
            h = k
            break
    elif v >= 2:
        if w == 0:
            w = k
        elif h == 0:
            h = k
            break
print(w*h)

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

from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v < 2:
        continue
    if v >= 4:
        if w == 0:
            w = h = k
            break
        else:
            h = k
            break
    elif v >= 2:
        if w == 0:
            w = k
        elif h == 0:
            h = k
            break
print(w*h)

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

from collections import defaultdict
dic = defaultdict(int)

for a in al:
    dic[a] += 1


a = [k for k, v in dic.items() if v >= 2]
b = [k for k, v in dic.items() if v >= 4]
a = sorted(a + b)

if len(a) < 2:
    print(0)
    import sys
    sys.exit()
print(a[-1] * a[-2])

Solution (Python):
n=int(input())
b=sorted([int(i) for i in input().split()],reverse=True)
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
A=groupby(b)
l=len(A)
B=[]
for i in range(l):
    A[i][1]=min(A[i][1]//2,2)
    if A[i][1]!=0:
        B.append(A[i])

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

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

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

E =  sorted([(k,v) for k,v in D.items() if v>=2] + [(0,4)])

l1, n1 = E[-1]
if n1>=4:
    print(l1*l1)
else:
    l2, n2 = E[-2]
    print(l1*l2)

Solution (Python):
from collections import Counter


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

    B = []
    for a, b in D.items():
        if b >= 4:
            B.append(a)
            B.append(a)
        elif b >= 2:
            B.append(a)

    B.append(0)
    B.append(0)

    B = sorted(B)[::-1]
    print(B[0] * B[1])


main()

Solution (Python):
from collections import Counter

N = int(input())
A = sorted(Counter(list(map(int, input().split()))).most_common(), reverse=True)

tmp = []
for elt, cnt in A:
    if 1 >= cnt:
        continue
    if cnt >= 4:
        tmp.append(elt)
        tmp.append(elt)
        break
    if cnt >= 2:
        tmp.append(elt)

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

Solution (Python):
import collections

N = int(input())
A = list(map(int,input().split()))
cc = dict(collections.Counter(A))
ans = 0
max_1 = 0
max_2 = 0
max_3 = 0
for i in cc.items():
  if (i[0] > max_1 and i[1] >= 2):
    max_2 = max_1
    max_1 = i[0]
  elif (i[0] > max_2 and i[1] >= 2):
    max_2 = i[0]
  if (i[1] >= 4):
    max_3 = max(max_3,i[0])
print(max(max_1*max_2,max_3**2))

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
Flag = False
base = 0
height = 0
ans = 0
for i in range(N - 1):
    if Flag:
        Flag = False
        continue
    if A[i] == A[i + 1] and base == 0:
        base = A[i]
        Flag = True
    elif A[i] == A[i + 1]:
        height = A[i]
        Flag = True
    area = base * height
    if area > ans:
        ans = area
print(ans)

Solution (Python):
import collections

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

d1 = []
d2 = []
for num,v in c.items():
  if v >= 2:
    d1.append(num)
  if v >= 4:
    d2.append(num)
    
d1.sort()
d2.sort()

if d2:
  ans = max(d2[-1]**2, d1[-1]*d1[-2])
  print(ans)
else:
  if len(d1)>=2:
    print(d1[-1]*d1[-2])
  else:
    print(0)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
l1 = []
l2 = []
for key,value in D.items():
    if value > 1:
        l1.append(key)
    if value > 3:
        l2.append(key)
if len(l1) < 2:
    print(0)
    exit()
l1.sort()
l2.sort()
if len(l2) > 0:
    print(max(l1[-1]*l1[-2],l2[-1]*l2[-1]))
else:
    print(l1[-1]*l1[-2])

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    cnt=Counter(aa)
    mx=-1
    for a,an in sorted(cnt.items(),reverse=True):
        if an>3 and mx==-1:
            print(a*a)
            break
        elif an>1:
            if mx==-1:mx=a
            else:
                print(mx*a)
                break
    else:
        print(0)



main()

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=1)
p=0
ans=1
c=0
for x in a:
  q=x
  if p==q:
    ans*=p
    p,q=0,0
    c+=1
    if c==2:
      print(ans)
      exit()
  else:
    p=q
print(0)

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

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

cnt = 0
prev = 0
candidates = []
for i in A:
    if i == prev:
        cnt += 1
        prev = i
    elif i != prev:
        prev = i
        cnt = 0
    if cnt >= 3:
        print(i**2)
        exit()
    if cnt == 1:
        candidates.append(i)
    if len(candidates) == 2:
        print(candidates[0]*candidates[1])
        exit()

print(0)

Solution (Python):
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
d = defaultdict(int)
for a in A:
  d[a] += 1
x = 1
cnt = 0
d = sorted(d.items(), key=lambda x:-x[0])
for i, j in d:
  if x == 1 and j >= 4:
    print(i**2)
    exit()
  if j >= 2:
    x *= i
    cnt += 1
    if cnt == 2:
      break
if cnt >= 1:
  print(x)
else:
  print(0)

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

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

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
lar=sec=i=0
while(i<n-1):
    if a[i]==a[i+1]:
        i+=1
        if a[i]>lar:
            sec=lar
            lar=a[i]
        elif a[i]>sec:
             sec=a[i]
    i+=1
print(lar*sec)

Solution (Python):
n = int(input())
vals = list(map(int, input().split()))
d= {}
a = [0, 0]

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


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

print(a[-1]*a[-2])

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

tmp = []
from collections import Counter
c = Counter(a)
for k in c.keys():
    if c[k] >= 2:
        tmp.append(k)
    if c[k] >= 4:
        tmp.append(k)

tmp.sort()

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

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

A.sort(reverse=True)
ans = 0
x = 0
y = 0
i = 0

while i in range(len(A) - 1):
    if A[i] == A[i+1]:
        x = A[i]
        A[i] = -1
        A[i+1] = -1
        break

    i += 1

A.sort(reverse=True)
i = 0
while i in range(len(A) - 1):
    if A[i] == A[i+1]:
        y = A[i]
        A[i] = -1
        A[i+1] = -1
        break

    i += 1

if x <= 0 or y <= 0:
    print(0)
else:
    print(x * y)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
import collections as c
d=c.Counter(a)
d=list(d.items())
d=sorted(d,reverse=True)
x,y=0,0
for i in d:
    if i[1]>=4 and x==0 and y==0:
        print(i[0]**2)
        exit()
    if x==0 and i[1]>=2:
        x=i[0]
        continue
    if y==0 and i[1]>=2:
        y=i[0]
        break
print(x*y)

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

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

A.sort(reverse=True)
c1 = 0
c2 = 0
i = 1
while i < N:
    if A[i] == A[i-1]:
        if c1 == 0:
            c1 = A[i]
            i += 1
        else:
            c2 = A[i]
            break
    i += 1
    
print(c1*c2)

Solution (Python):
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort(reverse=True)
lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))

mae = 0
ato = 0
for i in lin:
    if i[1] >= 4 and mae == 0:
        mae = i[0]
        ato = i[0]
    elif i[1] >= 2 and mae == 0:
        mae = i[0]
    elif i[1] >= 2 and ato == 0:
        ato = i[0]

print(mae*ato)

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

for a in A:
	if a in dic:
		dic[a] += 1
	else:
		dic[a] = 1

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

res = []

for i in range(len(dic_sorted)):
	if len(res) == 2: break
	remain = dic_sorted[i][1]
	while remain >= 2:
		res.append(dic_sorted[i][0])
		remain -= 2
		if len(res) == 2: break

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

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

i=0
find=0
ans=1
while i<len(a)-1:
  if a[i]==a[i+1]:
    find+=1
    ans*=a[i]
    i+=2
    if find==2:
      print(ans)
      break
  else:
    i+=1
else:
  print(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
import collections
counter=collections.Counter(a)
parts=[]
for item in counter.items():
  key=item[0]
  val=item[1]
  if val<2:
    continue
  loop=val//2
  for i in range(loop):
    parts.append(key)
    
if len(parts)<2:
  print(0)
else:
  parts=sorted(parts)
  print(parts[-1]*parts[-2])

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

c = col.Counter(li)

c = sorted(list(c.items()),key = lambda x:-x[0])
tmp1 = 0
tmp2 = 0
for i in range(n):
  if c[i][1] >= 2:
    if tmp1 != 0:
      tmp2 = c[i][0]
      
      break
    elif c[i][1] < 4:
      tmp1 = c[i][0]
      
    else:
      tmp1 = c[i][0]
      tmp2 = c[i][0]
      
      break
else:
  print(0)
  exit()
print(tmp1*tmp2)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from collections import Counter
def resolve():
    int(input())
    C=Counter(map(int,input().split()))
    C=[(k,v) for k,v in C.items()]
    C.sort(reverse=1)
    ans=0
    for k,v in C:
        if(v>=4):
            ans=k*k
            break

    a=0; b=0
    for i in range(len(C)):
        k,v=C[i]
        if(v>=2):
            a=k
            C[i]=(0,0)
            break

    for i in range(len(C)):
        k,v=C[i]
        if(v>=2):
            b=k
            C[i]=(0,0)
            break

    print(max(ans,a*b))
resolve()

Solution (Python):

from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))

first = 0
second = 0

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

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

for a in A:
    if 4 <= d[a]:
        if first>0:
            second = a
            break
        first = a
        second = a
        break
    elif 2<= d[a] <4:
        if first==0:
            first = a
            continue
        if first>0:
            second = a
            break

if first*second == 0:
    print(0)
else:
    print(first*second)

Solution (Python):
import heapq
n=int(input())
a=list(map(int,input().split()))
a=[-b for b in a]
heapq.heapify(a)
x=0
y=0
c=0
cnt=0
while len(a)>0:
    d=heapq.heappop(a)
    if c!=d:
        c=d
        cnt=1
    elif c==d:
        if x==0:
            x=d
            c=0
            continue
        elif x!=0 and y==0:
            y=d
            break
print(x*y)

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))
b = collections.Counter(a)
c = [ 0 for _ in range(n)]
i = 0
for l, cnt in b.items():
    if 1 < cnt < 4:
        c[i] = l
        i += 1
    elif 3 < cnt:
        c[i] = l
        c[i + 1] = l
        i += 2
c.sort(reverse=True)
print(c[0] * c[1])

Solution (Python):
N = int(input())
array = list(map(int,input().split()))
array.sort(reverse=True)
array2 = []
tmp = array[0]
for i in range(1,N):
    if tmp == array[i]:
        array2.append(array[i])
    tmp = array[i]
if len(array2) >= 1 and array2.count(max(array2)) >= 4:
    print(max(array2)**2)
    exit()
array3 = list(set(array2))
array3.sort(reverse=True)
if 2 <= len(array3):
    print(array3[0]*array3[1])
else:
    print(0)

Solution (Python):
from collections import Counter as C
N = int(input())
A = C([int(a) for a in input().split()])
L = []
for k in sorted(A.keys())[::-1]:
    if A[k] >= 2:
        if len(L) <= 1:
            L.append(k)
    if A[k] >= 4:
        if len(L) <= 1:
            L.append(k)

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

Solution (Python):
import collections

n = int(input())
A = list(map(int, input().split()))
S = sorted(list(set(A)), reverse=True)
c = collections.Counter(A)

L = []
for s in S:
    if c[s] > 3:
        L.append(s)
        L.append(s)
    elif c[s] > 1:
        L.append(s)
    if len(L) > 1:
        print(L[0]*L[1])
        break
else:
    print(0)

Solution (Python):
def examC():
    N = I()
    A = LI(); A.sort(reverse = True)
    d = defaultdict(int)
    cur = []
    ans = 0
    for i in range(N):
        d[A[i]] +=1
        if d[A[i]]==2:
            cur.append(A[i])
        elif d[A[i]]==4:
            cur.append(A[i])
        if len(cur)==2:
            ans = cur[0] * cur[1]
            break
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):
import collections

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

ca =collections.Counter(a)
res = []
for kca in list(ca.keys()):
    if ca[kca] >= 2:
        res.append(kca)
    if ca[kca] >= 4:
        res.append(kca)

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

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

sameCnt = 1
valueCnt = 0
x, y = 0, 0
i = 0

while i < (num - 1):
  if sequence[i] == sequence[i+1]:
    if valueCnt == 0:
      x = sequence[i]
      valueCnt += 1
    elif valueCnt == 1:
      y = sequence[i]
      break
    i += 1
  i += 1

ans = x * y
print(ans)

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

Solution (Python):
N = int(input())
li = list(map(int,input().split()))
li.sort()
a = 0
b = 0
while len(li) >= 2:
  if li[-1] == li[-2] and a == 0:
    a = li[-1]
    del li[-1]
    del li[-1]
  elif li[-1] != li[-2]:
    del li[-1]
  elif li[-1] == li[-2] and a != 0:
    b = li[-1]
    break
print(a * b)

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

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 1
j = 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()))

a.sort(reverse=True)
i = 0
flag = False
while i != (n-1):
    if flag is False:
        if a[i] == a[i+1]:
            first = a[i]
            i += 2
            flag = True
        else:
            i += 1
    else:
        if a[i] == a[i+1]:
            second = a[i]
            print(first*second)
            exit()

        else:
            i += 1

print(0)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
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):

import collections

N = int(input())
A_list = [int(e) for e in input().split()]



stick_one = 0
stick_two = 0

c = collections.Counter(A_list)

for stick in sorted(c.items(), reverse=True):
    if stick[1] >= 4 and stick_one == 0:
        stick_one = stick[0]
        stick_two = stick[0]
        print(stick_one * stick_two)
        break
    elif 4 > stick[1] >= 2 and stick_one == 0:
        stick_one = stick[0]
    elif stick[1] >= 2 and stick_one != 0:
        stick_two = stick[0]
        print(stick_one * stick_two)
        break
else:
    print(0)

Solution (Python):
from collections import Counter

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

counter = Counter(aa)
mc = counter.most_common()
mc = sorted(mc,key=lambda x:x[0],reverse=True)

first = 0
second = 0
 
for i,c in mc:  
  if c>=2:
    if first == 0:  
      first=i
      if c>=4:
        second=i
        break
    else:
      second = i
      break    
  
print(first*second)

Solution (Python):
from sys import exit
from collections import Counter
N = int(input())
Alist = Counter(list(map(int, input().split())))
over_2 = []
for A in sorted(Alist.items(), reverse=True):
    if A[1] >= 4:
        if len(over_2) == 0:
            print(A[0] ** 2)
        else:
            print(A[0] * over_2[0])
        exit()
    elif A[1] >= 2:
        over_2.append(A[0])
        if len(over_2) == 2:
            print(over_2[0] * over_2[1])
            exit()
    else:
        continue
else:
    print(0)

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    A.sort(reverse=True)
    lines = []
    prev = ''
    for ai in A:
        if ai == prev:
            lines.append(ai)
            prev = ''
        else:
            prev = ai

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

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

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

A.sort(reverse=True)

lines = []

cnt = 1
before = 'XXX'
for ai in A + ['YYY']:
    if ai == before:
        cnt += 1
    else:
        if cnt >= 4:
            lines.append(before)
            lines.append(before)
        elif cnt >=2:
            lines.append(before)

        if len(lines) >= 2:
            break
        
        cnt = 1
        before = ai


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

Solution (Python):
from collections import Counter

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

c = Counter()

for ai in A:
    c[ai] += 1

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

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

Solution (Python):
from sys import stdin

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

l_count = {}
for l in a:
    l_count.update({l: l_count.get(l, 0) + 1})
  
long_side, short_side = 0, 0
for l, c in sorted(l_count.items(), reverse=1):
    if c != 1:
        if not long_side:
            if c >= 4:
                print(l ** 2)
                exit()
            else:
                long_side = l
        else:
            short_side = l
            break

print(long_side * short_side)

Solution (Python):
from sys import stdin

n, *a = map(int, stdin.read().split())    
a.sort(reverse=1)

l_count = {}
for l in a:
    l_count.update({l: l_count.get(l, 0) + 1})
  
long_side, short_side = 0, 0
for l, c in sorted(l_count.items(), reverse=1):
    if c != 1:
        if not long_side:
            if c >= 4:
                print(l ** 2)
                exit()
            else:
                long_side = l
        else:
            short_side = l
            break

print(long_side * short_side)

Solution (Python):
n=int(input())
a=sorted(map(int,input().split()),reverse=True)
i=1;l=0;r=0
while(i<n):
  if a[i-1]==a[i]:
    if l==0:l=a[i];i+=1
    else:r=a[i];i=n
  i+=1
print(l*r)