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):
import collections
n = int(input())
a_lst = list(map(int, input().split()))

c = collections.Counter(a_lst)
cand = [k for k, v in c.items() if v >= 2]
cand = sorted(cand)

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

Solution (Python):



class Counter(dict):
    def __missing__(self, i):
        return 0

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

a.sort()
a.reverse()

counter = Counter()
for i in a:
    counter[i] += 1

first = -1
second = -1
for item in a:
    if second != -1:
        break;
    if counter[item] >= 2:
        if first == -1:
            first = item
            counter[item] -= 2
        elif second == -1:
            second = item

if first != -1 and second != -1:
    print(first*second)
else:
    print(0)

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

b= defaultdict(int)
ans = []
ans2 = []
for i in range(n):
    b[a[i]] += 1
    if b[a[i]] == 2:
       ans.append(a[i])
    if b[a[i]] == 4:
        ans2.append(a[i])
ans = sorted(ans,reverse=True)
ans2 = sorted(ans2,reverse=True)
if len(ans) <= 1 and len(ans2) == 0:
    print(0)
    exit()
if len(ans2) == 0:
    print(ans[0]*ans[1])
elif len(ans) <= 1:
    print(ans2[0]**2)
else:
    print(max(ans[0]*ans[1],ans2[0]**2))

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

while True:
    if ans == 0:
        break
    if a[i+j] == a[i+j+1]:
        ch[1] = a[i+j]
        break
    else:
        j += 1
    if i+j == n-1:
        ans = 0

if ans == 0:
    print(0)
else:
    print(ch[0]*ch[1])

Solution (Python):
from collections import *
N = int(input())
C = Counter(map(int,input().split()))
A = [0,0]
B = [0]

for k,v in C.items():
  if 2<=v:
    A+=[k]
  if 4<=v:
    B+=[k]

A.sort()
B.sort()
print(max(A[-1]*A[-2],B[-1]**2))

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

import collections

c = sorted(collections.Counter(a).items(), reverse=True)

leng_1 = 0
for leng,count in c:
  if count >=4:
    if leng_1 != 0:
      print(leng_1 * leng)
      exit()
    else:
      print(leng**2)
      exit()
  elif count >=2:
    if leng_1 != 0:
      print(leng_1*leng)
      exit()
    else:
      leng_1 = leng
print(0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
square = []
s1= a[0]
c = 0
result = 0
for i in range(1, n):
    s2 = a[i]
    if s1 == s2:
        c += 1
        if c % 2 == 1:
            square.append(s1)
            if len(square) == 2:
                result = square[0] * square[1]
                break
    else:
        s1 = a[i]
        c = 0
print(result)

Solution (Python):
from collections import Counter

N = int(input())
A = list(input().split())
A = [int(A[i])for i in range(N)]
A_count = list(Counter(A).most_common())

rectangle = sorted([A_count[i][0] for i in range(len(A_count)) if A_count[i][1] >= 2],reverse=True)
square = sorted([A_count[i][0] for i in range(len(A_count)) if A_count[i][1] >= 4], reverse=True)

S_rec = (rectangle[0] * rectangle[1] if len(rectangle) >= 2 else 0)
S_squ = (square[0] ** 2 if len(square) >= 1 else 0)

print(max(S_rec, S_squ))

Solution (Python):
from collections import Counter

n = int(input())
d = Counter(list(map(int, input().split())))
ans = -1

for k in sorted(d.keys())[::-1]:
    if ans == -1 and d[k] >= 4:
        print(k*k)
        exit()
    elif ans == -1 and d[k] >= 2:
        ans = k
    elif ans != -1 and d[k] >= 2:
        print(ans*k)
        exit()

print(0)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
ans = -1

for k in sorted(d.keys())[::-1]:
    if ans == -1 and d[k] >= 4:
        print(k*k)
        exit()
    elif ans == -1 and d[k] >= 2:
        ans = k
    elif ans != -1 and d[k] >= 2:
        print(ans*k)
        exit()

print(0)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
ans = 0
j = False

for k, v in sorted(d.items(), key = lambda x: -x[0]):
    if v >= 4:
        if ans == 0:
            ans = k*k
            j = True
            break
        else:
            ans *= k
            j = True
            break
    elif v >= 2:
        if ans == 0:
            ans = k
        else:
            ans *= k
            j = True
            break
if j == True:
    print(ans)
else:
    print(0)

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

a = Counter(a)
a = {key: val for key, val in a.items() if val >= 2}
a = dict(sorted(a.items(), reverse=True))

if len(a) == 0:
    print(0)
    exit()

side1 = max(a)
a[side1] -= 2

a = {key: val for key, val in a.items() if val >= 2}
a = dict(sorted(a.items(), reverse=True))

if len(a) == 0:
    print(0)
    exit()

side2 = max(a)

print(side1 * side2)

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

dic={}
for i in range(N):
    tmp=S[i]
    if tmp in dic:
        dic[tmp]+=1
    else:    
        dic[tmp]=1
kouho1=0
keys = [k for k, v in dic.items() if v >= 4]
keys.sort()
keys.reverse()
if len(keys)>=1:
    kouho1=keys[0]*keys[0]

kouho2=0
keys = [k for k, v in dic.items() if v >= 2]
keys.sort()
keys.reverse()
if len(keys)>=2:
    kouho2=keys[0]*keys[1]

print(max(kouho1,kouho2))

Solution (Python):
import collections
import sys
n = int(input())
ls = list(map(int,input().split()))
c =collections.Counter(ls)
d = list(c)
p = []
q = []
mm = 0
mx3 = 0
for i in range(len(d)):
    if c[d[i]] >=4:
        p.append(d[i])
    if c[d[i]] >=2:
        q.append(d[i])
if p == [] and len(q) < 2:
    print(0)
    sys.exit()
if len(q) >= 2:
    mx1 = max(q)
    q.remove(mx1)
    mx2 = max(q)
    mm = mx1 * mx2
if p != []:
    mx3 = max(p)**2
print(max(mm,mx3))

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

a.sort()
ans = [0,0]
temp_1 = 0
sign = 0

for i in range(1,n+1):
  temp = a[-i]

  if temp == temp_1:
    temp_1 = 0
    ans[sign] = temp
    if sign == 1:
      break
    sign = 1
  else:
    temp_1 = temp

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

Solution (Python):
import collections
n=int(input())
c=collections.Counter(list(map(int,input().split())))
p=-1
for x in sorted(c.keys())[::-1]:
    if p==-1 and c[x]>=4:print(x*x);break
    elif p==-1 and c[x]>=2:p=x
    elif p!=-1 and c[x]>=2:print(p*x);break
else:print(0)

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

count = 0
area = 1

for i in range(len(lista)- 1):
  if(lista[i] == lista[i+ 1]):
    del lista[i]
    area*= lista[i]
    count+= 1
    if(count == 2):
      break
      
if(count == 2):
  print(area)
else:
  print(0)

Solution (Python):
import collections

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

CNT_A = collections.Counter(A_s).most_common()
sorted_A = sorted(CNT_A, reverse=True)


verticle = []
ans = 0


for i in range(len(CNT_A)):
    key = sorted_A[i][0]
    value = sorted_A[i][1]
    
    if (value > 1):
        verticle.append(key)
    

    if (len(verticle) == 1 and value > 3):
        ans = key * key
        break

    elif (len(verticle) >= 2):
        ans = verticle[0] * verticle[1]
        break


print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
kouho = set([])
kouho2 = set([])
for i in c.most_common():
	if i[1] >= 2:
		kouho.add(i[0])
	if i[1] >= 4:
		kouho2.add(i[0])
kouholist = list(kouho)
kouholist2 = list(kouho2)
kouholist = kouholist + kouholist2
kouholist = sorted(kouholist)[::-1]
if len(kouholist) >= 2:
	print(kouholist[0]*kouholist[1])
else:
	print(0)

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

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

b = collections.Counter(a)
l = []

for k,v in b.items():
    if v >= 2:
        l.append((k,v))

l = sorted(l,reverse = True)
if not l:
    print(0)
else:
    if l[0][1] >= 4:
        print(l[0][0]**2)
    else:
        print(l[0][0]*l[1][0])

Solution (Python):
from collections import Counter

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

C = Counter(A)
C = [[k, v] for k, v in C.items() if v >= 2]
C.sort(key=lambda x:x[0], reverse=True)

ans = 0
if len(C) >= 1:
    if C[0][1] >= 4:
        ans = C[0][0] * C[0][0]
    elif len(C) >= 2:
        ans = C[0][0] * C[1][0]

print(ans)

Solution (Python):
def main():
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A, reverse = True)
  flag = True
  num = 0
  ans = 1
  for i in range(N-1):
    if A[i] == A[i+1] and flag:
      ans *= A[i]
      num += 1
      if num == 2:
        break
      flag = False
    elif not flag:
      flag = True
  if num < 2:
    ans = 0
  print(ans)
main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
x=1
l=[]
for i in range(n-1):
    if i!=n-2:
        if a[i]==a[i+1]:
            x+=1
        else:
            if x>=4:
                l.append(a[i])
                l.append(a[i])
                break
            elif x==2 or x==3:
                l.append(a[i])
                x=1
                if len(l)>=2:
                    break
    else:
        if a[i]==a[i+1]:
            x+=1
            if x>=4:
                l.append(a[i])
                l.append(a[i])
                break
            elif x==2 or x==3:
                l.append(a[i])
                x=1
                if len(l)>=2:
                    break
        else:
            if x>=4:
                l.append(a[i])
                l.append(a[i])
                break
            elif x==2 or x==3:
                l.append(a[i])
                x=1
                if len(l)>=2:
                    break

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

Solution (Python):
def find_max_rectangle(pair):
  """
  Args:
    pair (list): reversely sorted 
  Returns:
    area (int)
  """
  if len(pair) >= 2:
    M = pair[0]
    second_max = pair[1]
    return M * second_max
  else:
    return 0



n = int(input())
L = list(map(int, input().split()))
L.sort()
pair = []
prev = None
while L:
  popped = L.pop()
  if prev == popped:
    pair.append(prev)
    prev = None
  else:
    prev = popped

print(find_max_rectangle(pair))

Solution (Python):
from collections import Counter

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


length_num = Counter(A)

lengths = sorted(list(length_num.keys()), reverse=True)

ans = 0
sides = []


for l in lengths:
  if length_num[l] >= 4:
    ans = max(ans, l * l)
  if length_num[l] >= 2:
    sides.append(l)
  if len(sides) == 2:
    ans = max(ans, sides[0] * sides[1])
    break

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
A = LIST()
A = Counter(A)

ans = 1
for k in sorted(A, reverse=True):
	if A[k] >= 4:
		if ans == 1:
			ans = k**2
			break
		else:
			ans *= k
			break
	elif A[k] >= 2:
		if ans == 1:
			ans *= k
		else:
			ans *= k
			break
else:
	ans = 0
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
A = LIST()
A = Counter(A)


a = []
for x in A:
	if 4 <= A[x]:
		a.extend([x, x])
	elif 2 <= A[x]:
		a.append(x)


a.sort(reverse = True)

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

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

x = 0
y = 0
selection = sorted(list(set(A)))[::-1]
c = collections.Counter(A)
for i in selection:
    if c[i] >= 4:
        if x == 0:
            x = i
        if y == 0:
            y = i
    elif c[i] >= 2:
        if x == 0:
            x = i
        elif y == 0:
            y = i
    if x != 0 and y != 0:
        print(x * y)
        exit()

print(x * y)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=LI()
c=Counter(lis)
nums=[]
for i in c.keys():
    if c[i]>=2:
        nums.append(i)
nums.sort(reverse=True)

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

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

import collections

c = collections.Counter(al)
temp = sorted(list(set(al)),reverse = True)
x = 0
y = 0

for i in temp:
    if c[i]>=4:
        if x ==0:
            x = i
        if y ==0:
            y = i
    elif c[i] >=2:
        if x ==0:
            x =i
        elif y ==0:
            y = i
    if x*y != 0:
        print(x*y)
        exit()    
print(x*y)

Solution (Python):
from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    l1, l2 = 0, 0
    for k, v in c.items():
        if k > l1:
            if v >= 4:
                l1, l2 = k, k
            elif 2 <= v <= 3:
                l1, l2 = k, l1
            else:
                pass
        elif l2 < k <= l1 and v >= 2:
            l2 = k
    print(l1 * l2) 

if __name__ == '__main__':
    main()

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

for i in a:
  if i not in dict:
    dict[i] = 1
  else:
    dict[i] += 1
  
dictlis = sorted(dict.items())
count = 0
ans = 1


for i in range(len(dictlis)):
  if dictlis[len(dictlis) -1 -i][1] >= 4 and ans == 1: 
    print((dictlis[len(dictlis) -1 -i][0])**2)
    exit()
  elif  dictlis[len(dictlis) -1 -i][1] >= 2:
    count += 1
    ans = dictlis[len(dictlis) -1 -i][0]*ans
    if count == 2:
      print(ans)
      exit()
      
print(0)

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

now = A[0]
tateyoko = [0, 0]
count = 0
nowflag = False
for i in range(1, N):
  if (A[i] == now) and (not nowflag):
    tateyoko[count] = now
    count += 1
    nowflag = True
  else:
    nowflag = False
  if count == 2:
    break
  now = A[i]
  
print(tateyoko[0] * tateyoko[1])

Solution (Python):
from collections import Counter
def solve():
    ans = 0
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    D = [[0,0],[0,0]]
    for k,v in C.items():
        if v>=2:
            D.append([k,v])
    D.sort(reverse=True)
    if D[0][1]>=4:
        return D[0][0]**2
    return D[0][0]*D[1][0]
print(solve())

Solution (Python):
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    dupl_bars = [length for length, cnt in counter.items() if cnt > 1]
    dupl_bars.sort(reverse=True)
    if len(dupl_bars) > 1:
        if counter[dupl_bars[0]] > 3:
            print(dupl_bars[0] ** 2)
        else:
            print(dupl_bars[0] * dupl_bars[1])
    else:
        print(0)


if __name__ == '__main__':
    main()

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

dic = {}
for i in s:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

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

i = 0
h = 0
w = 0
while i < len(dic2):
    if dic2[i][1] >= 4 and h == 0 and w == 0:
        print(dic2[i][0]**2)
        exit()
    if dic2[i][1] >= 2 and h == 0:
        h = dic2[i][0]
    elif dic2[i][1] >= 2 and h != 0:
        print(h*dic2[i][0])
        exit()
    i += 1

print(0)

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

dic = {}
for i in s:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

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

i = 0
tmp = 0
sq = 0
while i < len(dic2):
    if dic2[i][1] >= 4 and sq == 0:
        sq = (dic2[i][0])**2
    if dic2[i][1] >= 2 and tmp == 0:
        tmp = dic2[i][0]
    elif dic2[i][1] >= 2 and tmp != 0:
        print(max(sq,tmp*dic2[i][0]))
        exit()
    i += 1

if sq == 0:
    print(0)
else:
    print(sq)

Solution (Python):
import sys

import math


from collections import deque

from fractions  import gcd


n=int(input())
a=list(map(int,input().split()))
a.sort()
res=a.pop()
ans=[]
while a:
    l=a.pop()
    if res==l:
        ans.append(l)
        if a:
            res=a.pop()
        else:
            break
    else:
        res=l
    if len(ans)==2:
        break
if len(ans)<2:
    print(0)
else:
    print(ans[0]*ans[1])

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

Solution (Python):
M = int(input())
A = list(map(int,input().split()))
B = {}
C = [0]*2
D = [0]*2

for i in range(len(A)):
	a = str(A[i])
	
	if (a in B): B[ str(A[i]) ] += 1 
	
	else: B[ str(A[i]) ] = 1 
	

for i in B:
	
	
	if B[i] < 2: continue

	
	C.append(int(i))

	
	if B[i] >= 4: D.append(int(i))


C = sorted(C, reverse=True)

rect = C[0] * C[1]
s = max(D)
square = s * s

print(max(rect,square))

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

import collections
c = collections.Counter(A)

two = []
four = []

for i in sorted(set(A)):
    a = c[i]
    
    if a > 1:
        two.append(i)
        
    if a > 3:
        four.append(i)
        
if len(two) > 0:
    two = sorted(two)
    ans = two[-1] * two[-2]
    
if len(four) > 0:
    ans = max(max(four)**2,ans)
    
print(ans)

Solution (Python):
import collections
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
B = []
i = 0
while i < N-1:
    if A[i]==A[i+1]:
        B.append(A[i])
        i += 2
    else:
        i += 1
if len(B)<2:
    print(0)
else:
    print(B[0] * B[1])

Solution (Python):
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
c=Counter(A)
c=c.most_common()
c.sort(reverse=True,key=lambda x:x[0])
cnt=0
H=0
W=0
for i in range(len(c)):
    if cnt==0 and c[i][1]>=4:
        H,W=c[i][0],c[i][0]
        print(H*W)
        exit()
    elif cnt==0 and c[i][1]>=2:
        H=c[i][0]
        cnt+=1
    elif cnt==1 and c[i][1]>=2:
        W=c[i][0]
        print(H*W)
        exit()
print(H*W)

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
x = [0, 0]
for i in a.keys():
    if a[i] >= 2:
        x.append(i)
    if a[i] >= 4:
        x.append(i)
x.sort(reverse=True)
print(x[0] * x[1])

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1





N = I()
A = IL()
d = DD(int)
for a in A:
  d[a] += 1
  
d = [(k,d[k])for k in d]
d.sort(reverse=True)
ans = []
ans_b = []
for a,b in d:
  if b>=4:
    ans_b.append(a)
  if b>=2:
    ans.append(a)
  if len(ans)==2:
    break
    
if len(ans)==2:
  if ans_b:
    P(max(ans[0]*ans[1],ans_b[0]**2))
  else:
    P(ans[0]*ans[1])
else:
  if ans_b:
    P(ans_b[0]**2)
  else:
    P(0)

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

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

if len(d) < 2:
    print(0)
else:
    d = sorted(d,reverse=True)
    x = d[0]
    y = d[1]

    print(x*y)

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

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

a.sort()


x = []
i = len(a)-1


while i > 0:
    if a[i] == a[i-1]:
        x.append(a[i])
        i-=1

    i-=1
    
    if len(x) == 2:
        print(x[0]*x[1])
        exit()



print(0)

Solution (Python):
from collections import Counter

n=int(input())
l=[int(i) for i in input().split()]
c=Counter(l).most_common()
s=sorted([key,val] for key,val in c if val>=2)

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

print(ans)

Solution (Python):
from collections import Counter

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

c = Counter(a).most_common()
edge = sorted([key, val] for key, val in c if val >= 2)

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

print(ans)

Solution (Python):
n=int(input())
l=[0,0]
from collections import Counter as co
for k,a in co(list(map(int,input().split()))).items():
    if a>=4:l+=[k,k]
    elif a>=2:l.append(k)
    l.sort()
    l=l[-2:]

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
s = set()
s.add(0)
s.add(-1)
for i in range(n-1):
  if a[i] == a[i+1]:
    s.add(a[i])
m = max(s)
s.discard(m)
k = max(s)
if a.count(m) > 3:
  print(m**2)
else:
  print(m*k)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    a.sort()
    ans1,ans2=0,0
    j=-1
    for i in range(n-1,-1,-1):
        if i==n-1:
            m=a[i]
        else:
            if a[i]!=m:
                m=a[i]
            else:
                ans1=m
                j=i
                break

    for i in range(j-1,-1,-1):
        if i==j-1:
            m=a[i]
        else:
            if a[i]!=m:
                m=a[i]
            else:
                ans2=m
                break

    print(ans1*ans2)

if __name__=="__main__":
    main()

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

useable = []
memo = {}

for a in A:
    try:
        memo[a] += 1
    except:
        memo[a] = 1
    if memo[a] == 2:
        useable.append(a)
        memo[a] = 0



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

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

A_count = collections.Counter(A)

keys = sorted(list(A_count.keys()), reverse=True)

hen_list = []
flag = 0
for key in keys:
    if A_count[key] >= 4:
        hen_list.append(key)
        hen_list.append(key)
    elif A_count[key] >= 2:
        hen_list.append(key)
    if len(hen_list) >= 2:
        flag = 1
        break
if flag == 1:
    print(hen_list[0] * hen_list[1])
else:
    print(0)

Solution (Python):
from collections import Counter

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

c = Counter(A)

hen = []

for i,j in zip(c.keys(),c.values()):
    if 2 <= j <= 3:
        hen.append([i,2])
    elif j >= 4:
        hen.append([i,4])


hen.sort(reverse=True)


ans = 0
finished = False
choosen = False

for i,j in hen:
    if choosen:
        ans *= i
        finished = True
        break

    if j == 2:
        ans = i
        choosen = True
    else:
        ans = i**2
        finished = True
        break

print(ans if finished else 0)

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
c = Counter(A)
sticks = []
for i in c:
    s = c[i]
    if s >= 4:
        sticks.append(i)
    if s >= 2:
        sticks.append(i)
if len(sticks) < 2:
    print(0)
else:
    sticks.sort(reverse=True)
    print(sticks[0]*sticks[1])

Solution (Python):
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
dic = Counter(A)
sticks = []
for i in dic:
    s = dic[i]
    if s>=4:
        sticks.append(i)
    if s>=2:
        sticks.append(i)
if len(sticks)<2:
    print(0)
else:
    sticks.sort(reverse=True)
    print(sticks[0]*sticks[1])

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
s = sorted(list(set(a)),reverse=True)
x = []
ans = 0
for si in s:
    if len(x)>=2:
        break
    cs=c[si]
    if cs>=4:
        x.append(si)
        x.append(si)
    elif cs>=2:
        x.append(si)
if len(x)<=1:
    print(0)
else:
    print(x[0]*x[1])

Solution (Python):
from collections import Counter

input()
lengths = tuple(map(int, input().split(' ')))
counter = Counter(lengths)

edges = []

for length in sorted(counter.keys(), reverse=True):
    if counter[length] >= 4:
        edges.append(length)
        edges.append(length)
    elif counter[length] >= 2:
        edges.append(length)

    if len(edges) >= 2:
        break

edges.append(0)
edges.append(0)

edges.sort(reverse=True)

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

Solution (Python):
from collections import Counter
 
N = int(input())
d = Counter(map(int, input().split()))
 
sticks_len = []
for k, v in d.items():
  if v >= 2:
    sticks_len.append(k)
  if v >= 4:
    sticks_len.append(k)
    
sticks_len.sort()
 
if len(sticks_len) >= 2:
  print(sticks_len[-1] * sticks_len[-2])
else:
  print(0)

Solution (Python):

"""
Created on Tue May 12 01:19:32 2020

@author: shinba
"""
import collections

n = int(input())

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

data = collections.Counter(A)

I = sorted(data.items(),reverse = True)

s1 = 0
s2 = 1
cnt1 = 0
cnt2 = 0 

for i,j in I:
    if cnt1 == 0 and j >= 4:
        s1 = i**2
        cnt1 = 1
    if j >= 2:
        s2 *= i
        cnt2 += 1
    if cnt2 == 2:
        print(max(s1,s2))
        break
else:
    if s1 != 0:
        print(s1)
    else:
        print(0)

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
A_col = collections.Counter(A)
length = []
for k,v in A_col.items():
    if v >= 4:
        length.append(k)
    if v >= 2:
        length.append(k)
length.sort()
if len(length) <= 1:
    print(0)
else:
    print(length[-1]*length[-2])

Solution (Python):
n = int(input())
A = sorted(list(map(int, input().split())), reverse = True)
l = 0
ln = []
for a in A:
    if l == a:
        ln.append(a)
        l = 0
    else:
        l = a
    if len(ln) == 2:
        break
if len(ln) == 2:
    print(ln[0]*ln[1])
else:
    print(0)