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-----
6
3 1 2 4 2 1

-----Sample Output-----
2

1 \times 2 rectangle can be formed.

Difficulty: introductory

Starter code:

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


a.sort()

count=0


def get_num(a):
    count=1
    taishou = a.pop()
    while a!=[]:
        second=a.pop()
        if taishou==second:
            count+=1
        else:
            a.append(second)
            break
    if count==1:
        return taishou,0
    elif count==2 or count==3:
        return taishou,1
    else:
        return taishou,2

one=0
two=0


while a!=[] and (one==0 or two==0):
    hen,length=get_num(a)
    if length==1:
        if one==0:
            one=hen
        else:
            two=hen
    elif length==2:
        if one==0:
            one=hen
            two=hen
        else:
            two=hen

print((one*two))



N = int(input())
data = list(map(int, input().split()))
data.sort()
ans = []
N -= 1
while N > 0:
    if data[N] == data[N - 1]:
        ans.append(data[N])
        N -= 1
    N -= 1
    if len(ans) >= 2:
        break

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



n = int(input())
a = list(map(int, input().split()))
from collections import Counter
a = Counter(a)
lis = []
 
for i,j in a.items():
    lis += [i]*(j//2)
 
#print(lis)
 
lis.sort(reverse=True)
if len(lis) <= 1:
    ans = 0
else:
    ans = lis[0]*lis[1]
 
print(ans)

from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
xy = []
a = sorted(a.items(), key=lambda x: x[0], reverse=True)
for i in a:
    if len(xy) == 2:
        break
    if i[1] >= 4:
        xy.append(i[0])
        xy.append(i[0])
        break
    if i[1] >= 2:
        xy.append(i[0])

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

from collections import Counter as C

_ = input()
a = C([int(x) for x in input().split()])

b = []
for k, v in a.items():
    b.extend([k] * (v // 2))
else:
    if 2 <= len(b):
        b.sort()
        print(b[-1] * b[-2])
    else:
        print(0)

from collections import Counter as C

_ = input()
a = C([int(x) for x in input().split()])

b = []
for k, v in a.items():
    for _ in range(v // 2):
        b.append(k)
else:
    if 2 <= len(b):
        b.sort()
        print(b[-1] * b[-2])
    else:
        print(0)

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

c=Counter(a)
can_make=[i[0] for i in c.items() if i[1]>=2]
can_make_square=[i[0] for i in c.items() if i[1]>=4]
can_make+=can_make_square
can_make.sort()

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

n = int(input())
A = list(map(int, input().split()))
d = {0:4}
for a in A:
    d[a] = d.get(a, 0)+1
longest = 0
for i in d:
    if d[i]>=2:
        longest = max(longest, i)
d[longest]-=2

longest_2nd = 0
for i in d:
    if d[i]>=2:
        longest_2nd = max(longest_2nd, i)
print(longest*longest_2nd)

from collections import Counter as C

_ = input()
a = C([int(x) for x in input().split()])

b = [0, 0]
for k, v in a.items():
    b.extend([k] * (v // 2))
else:
    b.sort()
    print(b[-1] * b[-2])

n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in range(n):
    dic.setdefault(a[i],0)
    dic[a[i]] += 1
ans = []
for item in list(dic.items()):
    if item[1]>=2:
        ans.append(item[0])
if len(ans)<=1:
    print((0))
else:
    ans.sort()
    if dic[ans[-1]]>=4:
        print((ans[-1]**2))
    else:
        print((ans[-1]*ans[-2]))


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

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

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

import sys
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
box,box2,ans = [],[],0
acnt = dict(Counter(a))
acnt = sorted(acnt.items(), key=lambda x:x[0],reverse=True)
a_val = [acnt[x][1] for x in range(len(acnt))]
a_key = [acnt[y][0] for y in range(len(acnt))]
for i in range(len(a_val)):
	if a_val[i] >= 4:
		box2.append(a_key[i]**2)
	if 2 <= a_val[i]:
		box.append(a_key[i])
box.sort(reverse=True)
if len(box2) >= 2:	
	ans = max(box2)
if len(box) >= 2:
    print(max(ans,(box[0]*box[1])))
    return
print(0)

import collections
n=int(input())
a=list(map(int,input().split()))
c = collections.Counter(a)
b=[0,0]
d=[0,0]
for i in c:
    if c[i]>=4:
        b.append(i)
    elif c[i]>=2:
        d.append(i)
b.sort(reverse=True)
d.sort(reverse=True)
if b[0]>d[0]:
    print((b[0]*b[0]))
elif b[0]<d[1]:
    print((d[0]*d[1]))
else:
    print((b[0]*d[0]))


import sys

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

d = {}
a = []
for i in A:
    if i in d:
        d[i] += 1
        if d[i] == 2:
            a.append(i)
            d[i] = 0
    else:
        d[i] = 1

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

from collections import Counter as C

_ = input()
a = C(map(int, input().split()))

b = []
for k, v in a.items():
    b.extend([k] * (v // 2))
else:
    if 2 <= len(b):
        b.sort()
        print(b[-1] * b[-2])
    else:
        print(0)

from collections import Counter

N = int(input())
A = list(map(int, input().split()))
counter = dict(Counter(A))
four = []
tow = []
for key in counter.keys():
    if counter[key] >= 4:
        four.append(key)
        tow.append(key)
    elif counter[key]>=2:
        tow.append(key)

if len(four) == 0 and len(tow) <= 1:
    print(0)
else:
    ans = 0
    four.sort(reverse=True)
    tow.sort(reverse=True)
    if len(four) >= 1:
        ans = max(ans, four[0]**2)
    if len(tow) >= 2:
        ans = max(ans, tow[1] * tow[0])
    print(ans)

from collections import Counter

input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if len(R)==0:
  print(0)
  return
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])

N=int(input())
A=sorted(list(map(int,input().split())))
l=[]
s=set()
for i in range(N):
    if A[N-i-1] in s:
        l.append(A[N-i-1])
        s.discard(A[N-i-1])
    else:
        s.add(A[N-i-1])
l.sort()
print(0 if len(l)<2 else l[-1]*l[-2])

from collections import Counter
n=int(input())
c=Counter(list(map(int, input().split())))
l=list()
for k,v in c.items():
    for _ in range(v//2):
        l.append(k)

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

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

a.sort(reverse = True)
ans = 0
b = a.copy()
b = list(set(b))
b.sort(reverse = True)
c = [0]*len(b)
j = 0
c[j] = 1
for i in range(1,n):
    if a[i-1] == a[i]:
        c[j] +=1
    else:
        j+=1
        c[j] +=1
for i in range(len(b)):
    if c[i] >= 4:    
        
        ans = b[i]*b[i]
        break
    elif c[i] >= 2:
        for j in range(i+1,len(b)):
            if c[j] >= 2:
                ans = b[i]*b[j]
                break
        break
print(ans)

n = int(input())
A = tuple(map(int, input().split()))
A = sorted(A, reverse=True)
from collections import Counter
CA = Counter(A)

b = 0
for a in A:
    if CA[a] >= 2:
        CA[a] -= 2
        b = a
        break

c = 0
for a in A:
    if CA[a] >=2:
        c = a
        break
print((b*c))


from collections import Counter as C

_ = input()
a = C([int(x) for x in input().split()])

b = [0] * 2
for k, v in a.items():
    if 4 <= v:
        b.append(k)
    if 2 <= v:
        b.append(k)
else:
    b.sort()
    print(b[-1] * b[-2])

import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
lsline = []
for i in counterA.keys():
    if counterA[i] >= 2:
        lsline.append(i)
lsline.sort(reverse=True)
if bool(lsline):
    if counterA[lsline[0]] >= 4:
        ans = lsline[0]*lsline[0]
    elif len(lsline) < 2:
        ans = 0
    else:
        ans = lsline[0]*lsline[1]
else:
    ans = 0
print(ans)

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

count = {}
rect = {}
for i in range(N):
    if A[i] in rect:
        rect[A[i]] += 1
    elif A[i] in count:
        rect[A[i]] = 2
    else:
        count[A[i]] = 1

if len(rect) < 1:
    ans = 0
else:
    x = max(rect)
    if rect[x] >= 4:
        ans = x * x 
    else:
        del rect[x]
        if len(rect) < 1:
            ans = 0
        else:
            y = max(rect)
            ans = x * y
print(ans)


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

d={}

for n in range(N):
    if d.get(A[n])==None:
        d[A[n]]=1
    else:
        d[A[n]]+=1

d=sorted(list(d.items()),reverse=True)

cnt=0
ans=0
for i in range(len(d)):
    if cnt==0:
        if d[i][1]>=4:
            ans=d[i][0]**2
            break
        elif d[i][1]>=2:
            temp=d[i][0]
            cnt+=1
    else:
        if d[i][1]>=2:
            ans=temp*d[i][0]
            break
print(ans)


with open(0) as f:
    N, *A = map(int, f.read().split())

pair = []
unpair = set()
for a in A:
    if a in unpair:
        unpair.remove(a)
        pair.append(a)
    else:
        unpair.add(a)
pair.sort()
print(pair.pop()*pair.pop() if len(pair) > 1 else 0)

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

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

store = 0
big = 0

for i in range (0, N-1):
	if store == 1:
		store = 0
	else:
		if A[i] == A[i+1] and big == 0:
			big = A[i]
			store = 1
		elif A[i] == A[i+1]:
			print(A[i]*big)
			return
            
print(0)

from collections import Counter

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

c = Counter(A)
mc=[]
for k in c.keys():
  if c[k]>=2:mc.append(k)
    
if len(mc)==0:
  print(0)
  return

elif len(mc)==1:
  if c[mc[0]]<4:
    print(0)
    return
  else:
    print(mc[0]**2)
    return
  
mc = sorted(mc,reverse=True)
if c[mc[0]] < 4:print(mc[0]*mc[1])
else:print(mc[0]**2)

N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse = True)
ans = [0, 0]
j = 0
now = -1
count = 1
for i in range(N):
  if A[i] == now:
    count += 1
    if count == 2:
      ans[j] = now
      if j == 1:
        print(ans[0] * ans[1])
        return
      j += 1
    if count == 4:
      print(now * now)
      return
      
  else:
    now = A[i]
    count = 1

print(0)

import sys

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

a.sort(reverse=True)
c=0
f=0
ans=[]
for i in range(n-1):
  if a[i]==a[i+1]:
    c+=1
    f+=1
    ans.append(a[i])
  else:
    f=0
  if (c>1 and f==1) or (c>2 and f==3):
    print((ans[0]*ans[-1]))
    return
print((0))
  
  


#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


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

    A.sort(reverse=True)
    l1 = l2 = 0
    for i in range(1, N):
        if l1 == 0:
            if A[i] == A[i-1]:
                l1 = A[i-1]
        else:
            if i < N-1 and A[i+1] == A[i]:
                l2 = A[i]
                break

    print((l1*l2))


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

from collections import Counter as C

_ = input()

b = []
for k, v in C([int(x) for x in input().split()]).items():
    b.extend([k] * (v // 2))
else:
    if 2 <= len(b):
        b.sort()
        print(b[-1] * b[-2])
    else:
        print(0)

def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort(reverse=True)
    line = -1
    lines = []
    for an in a:
        if line == an:
            lines.append(an)
            if len(lines) == 2:
                break
            line = -1
        else:
            line = an
    print((lines[0] * lines[1] if len(lines) == 2 else 0))


def __starting_point():
    main()

__starting_point()

n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

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

two_over = []
counter = 0
res = 1
for i in keys:
    if num_map[i] >= 4:
        res *= i ** (2 - counter)
        counter += 2
    elif num_map[i] >= 2:
        counter += 1
        res *= i
    if counter >= 2:
        print(res)
        break
else:
    print((0))


n=int(input())
a=list(map(int,input().split()))
d={}
sei=[]
tyo=[]
for s in a:
  if s not in d:
    d[s]=0
  d[s]+=1
  
for t in a:
  if d[t]>=2:
    tyo.append(t)
  if d[t]>=4:
    sei.append(t)
  d[t]=0
  
if len(sei)==0 and len(tyo)<=1:
  print(0)
  
else:
  tyos=0
  seis=0
  if len(tyo)>1:
    tyo=sorted(tyo)
    tyos+=tyo[-1]*tyo[-2]
  if len(sei)>0:
    sei=sorted(sei)
    seis+=sei[-1]**2
    
  print(max(tyos,seis))

input()
d = {}
for i in map(int, input().split()):
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if len(ans) < 2 and j >= 4:
        ans.append(i)
        d[i] -= 2
    if len(ans) < 2 and j >= 2:
        ans.append(i)
        d[i] -= 2
    if len(ans) == 2:
        print(ans[0] * ans[1])
        break
else:
    print(0)

input();a=list(map(int,input().split()));d={}
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
d={i:j for i,j in d.items() if j>1}
if len(d)<2:
  print(0)
else:
  d=sorted(d.items(),key=lambda x:(-x[0],-x[1]))
  print(d[0][0]*d[1][0] if d[0][1]<4 else d[0][0]*d[0][0])

n = int(input())
a = list(map(int, input().split()))
from collections import Counter
a = Counter(a)
lis = []

for i,j in a.items():
    lis += [i]*(j//2)

#print(lis)

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

print(ans)

from collections import deque

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

A.sort(reverse=True)
q = deque()
for i in range(N):
    q.append(A[i])

s = []
w = True
while q:
    if len(q) == 1:
        break
    else:
        i = q.popleft()
        j = q.popleft()
        if i == j:
            s.append(i)
        else:
            q.appendleft(j)
        if len(s) == 2:
            print((s[0] * s[1]))
            w = False
            break
if w:
    print((0))


from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    B = sorted([(k, v) for k, v in list(c.items()) if v >= 2], reverse = True, key = lambda x: x[0])
    if len(B) < 2:
        print((0))
    elif B[0][1] >= 4:
        print((B[0][0] ** 2))
    else:
        print((B[0][0] * B[1][0]))

def __starting_point():
    main()

__starting_point()

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

d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d = sorted(d.items(), key=lambda x:x[0], reverse=True)

m = len(d)
ans = 0
flg = True
for i in range(m):
    k, v = d[i][0], d[i][1]
    if ans == 0:
        if v >= 4:
            ans = k**2
            flg = True
            break
        elif v >= 2:
            ans = k
    elif v >= 2:
        ans *= k
        flg = True
        break
print(ans) if flg else print(0)
        

N = int(input())
a = list(map(int,input().split()))
c = {}
d = [0,0]
ans = 0

for i in a:
    if i not in c:
        c[i]=0
    c[i]+=1

for i,v in zip(c.keys(),c.values()):
    if v >= 4:
        d.append(i)
        d.append(i)
    elif v >= 2:
        d.append(i)
        
d.sort(reverse = True)

if len(d) <= 3:
    ans = max(ans,0)
else:
    ans = max(ans,d[0]*d[1])

print(ans)

def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    lst = [0, 0]

    a_lst.sort()
    a_lst.reverse()

    length = a_lst[0]
    count = 0
    for i in range(n):
        if a_lst[i] == length:
            count += 1

            if count == 2:
                lst.append(a_lst[i])
                count = 0

            if len(lst) == 4:
                break

        else:
            count = 1
            length = a_lst[i]

    area = lst[-1] * lst[-2]
    print(area)


def __starting_point():
    main()
__starting_point()

from collections import Counter
 
input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

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

dic = {}
for a in A:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
    
dic = sorted(dic.items(), reverse=True)

ans = 1
check = 0
bool1 = False
for (i,j) in dic:
  cnt = j // 2
  for _ in range(cnt):
    ans *= i
    check += 1
    if check == 2:
      bool1 = True
      break
  if bool1:
    break

print(ans if ans != 1 else 0)

N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse = True)

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

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

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
i = 0
c = 0
x = 0
y = 0 
while i < len(a) - 1:
	if a[i] == a[i+1] and c == 0:
		x = a[i]
		i += 2
		c += 1
		continue
	if a[i] == a[i+1] and c == 1:
		y = a[i]
		break
	i += 1
if x != 0 and y != 0:
	print(x*y)
else:
	print(0)

n = int(input())
a = list(map(int,input().split()))
import collections
b = collections.Counter(a).most_common()
li4 = []
li2 = []
ansli = []
for k in b:
    if k[1]>=4:
        li4 +=[k[0]]
        ansli += [k[0]**2]
    if k[1]>=2:
        li2 +=[k[0]]

if len(li2)>=2:
    li22 = sorted(li2)
    ansli += [li22[-1]*li22[-2]]
if ansli:
    print(max(ansli))
else:
    print(0)

n = int(input())
#a, b = map(int,input().split())
al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
dic = {}
for ai in al:
    dic[ai] = dic.get(ai, 0)+1

edges = sorted(list(dic.items()), reverse=True)
ans = 0
partial = False
temp = 0
for tup in edges:
    e, num = tup
    if num == 1:
        continue
    elif num == 2 or num == 3:
        if partial:
            ans = temp*e
            break
        else:
            partial = True
            temp = e
    else:
        if partial:
            ans = temp*e
            break
        else:
            ans = e**2
            break
print(ans)


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

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

t = 0
ans = []
for k,v in sorted(d.items(), key=lambda x: x[0], reverse=True):
  if v >= 4 and t == 0:
    print(k*k)
    return
  elif v >= 2:
    ans.append(k)
    t += 1
  if t == 2:
    print(ans[0]*ans[1])
    return
print(0)

n = int(input())
a = list(map(int, input().split()))
rods = []
tmp = {}
for i in a:
    if i in tmp:
        tmp[i] += 1
        if tmp[i] >= 2:
            rods.append(i)
            tmp[i] = 0
    else:
        tmp[i] = 1

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

n = int(input())
A = list(map(int, input().split()))
A.sort()
l = 0
h = 0
i = n-1
while i >= 0:
    if i > 0 and A[i] == A[i-1] and l == 0:
        l = A[i]
        i -= 2
    elif i > 0 and A[i] == A[i-1] and h == 0:
        h = A[i]
        break
    else:
        i-=1
print (l*h)

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
A.sort(reverse=True)

for i in A:
  D[i] += 1

L = []

for i, x in D.items():
  if x >= 4:
    L.append(i)
    L.append(i)
    break
  elif x >= 2:
    L.append(i)

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

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

A.sort(reverse=True)
l1 = 0
c1 = 0
l2 = 0
c2 = 0

L1 = 0
L2 = 0

for i in range(len(A)):
  if L1 and L2:
    break
  elif L1:
    if l2 == A[i]:
      c2 += 1
    elif l2 != A[i]:
      l2 = A[i]
      c2 = 1
    if c2 == 2:
      L2 = l2
  else:
    if l1 == A[i]:
      c1 += 1
    elif l1 != A[i]:
      l1 = A[i]
      c1 = 1
    if c1 == 2:
      L1 = l1

print(L1 * L2)

import collections

_=input()
a=list(map(int,input().split()))
c=collections.Counter(a)
l=sorted(c.items(), key=lambda x: x[0])
x=0
for i in l[::-1]:
    if i[1]>3:
        if x:
            print(i[0]*x)
            return
        else:
            print(i[0]*i[0])
            return
    elif i[1]>1:
        if x:
            print(i[0]*x)
            return
        else:
            x=i[0]
print(0)

from collections import defaultdict

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

for i in A:
  D[i] += 1

L1 = [0, 0]
L2 = [0]

for i, x in D.items():
  if x >= 4:
    L2.append(i)
  if x >= 2:
    L1.append(i)

L1.sort(reverse=True)
L2.sort(reverse=True)

print(max(L1[0]*L1[1], L2[0]**2))

from collections import defaultdict

d = defaultdict(int)

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

ans = []
for i in a:
  d[i] += 1
  if d[i] == 2:
    d[i] = 0
    ans.append(i)
ans.sort(reverse=True)
if len(ans) >= 2:
  print((ans[0]*ans[1]))
else:
  print((0))


from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split())))
B = dict(sorted(list(A.items()), reverse=True))
ans = []
for i, j in list(B.items()):
    if j >= 4:
        ans.append(i)
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    print((ans[0] * ans[1]))
else:
    print((0))


import collections

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

A = collections.Counter(A).most_common()
N = len(A)

ans = [0]

for i in range(N):
    if A[i][1] >= 4:
        ans.append(A[i][0]**2)

ref = []
for j in range(N):
    if A[j][1] >= 2:
        ref.append(A[j][0])
ref = sorted(ref)
if len(ref) >= 2:
    ans.append(ref[-2]*ref[-1])

print((max(ans)))


n = int(input())
a1 = list(map(int, input().split()))
from collections import Counter
a = Counter(a1).most_common()
l = []
for i in range(len(a)):
    if 2 <= a[i][1]:
        for h in range(a[i][1]//2):
            l.append(a[i][0])
l.sort()
if 2 <= len(l):
    print(l[-1]*l[-2])
else:
    print(0)

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

i=N-1
ans=1
count=0
while i>=1:
    if A[i-1]==A[i]:
        ans*=A[i]
        i-=2
        count+=1
    else:
        i-=1
    if count==2:
        print(ans)
        break
else:
    print((0))


import collections

N = int(input())
a = [int(i) for i in input().split()]
check = []
dict = collections.Counter(a)
for a, b in dict.items():
    if b >= 2:
        check.append(a)

if len(check) >=2:
    check.sort()
    if dict[check[-1]] >= 4:
        print(check[-1] ** 2)
    else:
        print(check[-1] * check[-2])
elif len(check) == 1:
    if dict[check[-1]] >= 4:
        print(check[-1] ** 2)
    else:
        print(0)
else:
    print(0)

N = int(input())
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)
b = []
for i, j in a.items():
    if j >= 2:
        b.append([i,j])
b.sort(reverse=True)
if len(b) >= 1 and b[0][1] >= 4:
    print(b[0][0] ** 2)
elif len(b) >= 2:
    print(b[0][0] * b[1][0])
else:
    print(0)

from collections import Counter as C

_ = input()
a = C([int(x) for x in input().split()])

b = []
for k, v in a.items():
    if 4 <= v:
        b.append(k)
    if 2 <= v:
        b.append(k)
else:
    if len(b) <= 1:
        print(0)
    else:
        b.sort()
        print(b[-1] * b[-2])

from collections import deque
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

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

q = deque()
for i in keys:
    if num_map[i] >= 2:
        q.append([i, num_map[i]])
res = 1
counter = 0
while len(q) != 0:
    key, value = q.popleft()
    res *= key
    if value - 2 >= 2:
        q.appendleft([key, value - 2])
    counter += 1
    if counter == 2:
        print(res)
        break
else:
    print((0))


from collections import defaultdict
Lineger_Dict = defaultdict(int)
N = int(input())
N_List = list(map(int,input().split()))
for i in N_List:
    Lineger_Dict[i] += 1

    
Rec = sorted([k for k,v in Lineger_Dict.items() if v >= 2] + [k for k,v in Lineger_Dict.items() if v >= 4])
if len(Rec) < 2:
    print(0)
else:
    print(Rec[-1]*Rec[-2])

import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = 0
    counter = Counter(A)
    vec1 = [k for k, v in list(counter.items()) if v >= 2]
    vec2 = [k for k, v in list(counter.items()) if v >= 4]

    vec1.sort()
    if len(vec1) >= 2:
        ans = vec1[-2] * vec1[-1]

    vec2.sort()
    if len(vec2) >= 1:
        ans = max(ans, vec2[-1] ** 2)

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
ans = [i[0] for i in c.items() if i[1] >= 2]
ans.extend([i[0] for i in c.items() if i[1] >= 4])
ans.extend([0,0])
ans.sort(reverse=True)
print(ans[0]*ans[1])

n = int(input())
a = sorted(list(map(int, input().split())))
i = n - 1
p = 0
q = 0
while i > 0:
  if a[i] == a[i-1]:
    if p == 0:
      p = a[i]
      i -= 1
    else:
      q = a[i]
      break
  i -= 1
print(p*q)

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

a.sort()
a.reverse()

c = [0,0]
i = 0

while i < N-1:
    if a[i] == a[i+1]:
        c.append(a[i])
        i+=2
    else:
        i+=1
        
c.sort()
c.reverse()
print(c[0]*c[1])

N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse = True)

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

from collections import Counter

input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if len(ans) < 2 and j >= 4:
        ans.append(i)
        d[i] -= 2
    if len(ans) < 2 and j >= 2:
        ans.append(i)
        d[i] -= 2
    if len(ans) == 2:
        print(ans[0] * ans[1])
        break
else:
    print(0)

N=int(input())
A=sorted(list(map(int,input().split())),reverse=True)
def sameA(List):
  for i in range(len(List)):
    try:
      if List[i]==List[i+1]:
        ans=List[i]
        anslist=A[i+2:]
        return ans,anslist
    except IndexError:
      return False,False
a1,list1=sameA(A)
if not a1==False:
  a2,list2=sameA(list1)
  if not a2==False:
    print(a1*a2)
  else:
    print(0)
else:
  print(0)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-04 15:20:21 +0900
# LastModified: 2020-09-04 15:31:03 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    a_cnt = [[key, val] for key, val in list(Counter(a).items()) if val >= 2]
    if len(a_cnt) == 0:
        print((0))
        return
    a_cnt.sort(key=lambda x: x[0], reverse=True)
    if a_cnt[0][1] >= 4:
        print((a_cnt[0][0]**2))
    elif len(a_cnt) == 1:
        print((0))
    else:
        print((a_cnt[0][0]*a_cnt[1][0]))


def __starting_point():
    main()

__starting_point()

N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse = True)
L = []
cnt = 0
i = 0
while i <= N-2:
    if A[i] == A[i+1]:
        L.append(A[i])
        i += 1
        cnt += 1
        if cnt == 2:
            break
    i += 1
if len(L) == 2:
    print(L[0]*L[1])
else:
    print(0)

n=int(input())
l=list(map(int,input().split()))
d={}
for a in l:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
ks=sorted(d,reverse=True)
f=0
for i,k in enumerate(ks):
    if d[k]>=4:
        print((k*k))
        return
    if d[k]>=2:
        f=k
        break
s=0
for k in ks[i+1:]:
    if d[k]>=2:
        s=k
        break
print((f*s))


from collections import Counter as C

_ = input()
a = C([int(x) for x in input().split()])

b = [0] * 2
for k, v in a.items():
    b.extend([k] * (v // 2))
else:
    b.sort()
    print(b[-1] * b[-2])

N = int(input())
A = list(map(int,input().split()))
ans = []
flg = 0

A.sort(reverse=True)

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

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

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

if n == len(num)+1 or n == len(num):
    print((0))
    return

ans = []

for i in num:
    if num[i] >= 2:
        ans.append(i)
    if num[i] >= 4:
        ans.append(i)     
n = max(ans)
ans.pop(ans.index(max(ans)))
m = max(ans)
print((n*m))


from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
a = [list(x) for x in a.items() if x[1]>=2]
a.sort(reverse=True, key=lambda x: (x[0], x[1]))
count = 0
base = 4
for i in range(len(a)):
    if count == 1:
        print(l*a[i][0])
        return
    else:
        l = a[i][0]
        count += 1

    if a[i][1]>=4:
        print(a[i][0]*a[i][0])
        return

print(0)

from collections import Counter

input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
    if len(ans) >= 2:
        print(ans[0] * ans[1])
        break
else:
    print(0)

import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    A.sort(reverse=True)

    i = 0
    w = h = 0
    while i < N - 1:
        if A[i] == A[i + 1]:
            if w == 0:
                w = A[i]
            else:
                h = A[i]
                break
            i += 2
        else:
            i += 1

    print((w * h))
    return


def __starting_point():
    main()

__starting_point()

import heapq
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
l = []
for i in set(a):
    if c[i] >= 2:
        for j in range(c[i]//2):
            l.append(i)
if len(l) >= 2:
    print(heapq.nlargest(2, l)[0]*heapq.nlargest(2, l)[1])
else:
    print(0)

from collections import Counter

input()
ans = [0, 0]
for i, j in list(Counter(list(map(int, input().split()))).items()):
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
ans.sort()
print((ans[-1] * ans[-2]))


import collections
N = int(input())
A = sorted(collections.Counter(int(T) for T in input().split()).most_common(),reverse=True)
Flag = False
LS = 0
SS = 0
for T in range(0,len(A)):
    if LS==0 and A[T][1]>=4:
        Sq = A[T][0]**2
        Flag = True
        break
    if A[T][1]>=2:
        if LS==0:
            LS = A[T][0]
        else:
            SS = A[T][0]
            Sq = LS*SS
            Flag = True
            break
if Flag:
    print(Sq)
else:
    print(0)

from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
dd=defaultdict(lambda:0)
for aa in a:
  dd[aa]+=1
x,y=0,0
for k in sorted(dd.keys(), reverse=True):
  if x==0 and dd[k]>=2:
    x=k
    dd[k]-=2
  if y==0 and dd[k]>=2:
    y=k
    break
print(x*y)

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()

    a.sort()

    l = []
    start = a[0]
    cnt = 1
    for i in a:
        if i == start:
            cnt += 1
        else:
            start = i
            cnt = 1
        if cnt == 2:
            l.append(i)
            cnt = 0
    if cnt == 2:
        l.append(i)
    if len(l) < 2:
        print((0))
    else:
        print((l[-1]*l[-2]))



def __starting_point():
    main()

__starting_point()

from collections import Counter


def solve():
    c = Counter(arr)
    four_edges = [k for k, v in list(c.items()) if v >= 4]
    two_edges = [k for k, v in list(c.items()) if 1 < v < 4]
    four_edges.append(0)
    two_edges.append(0)
    four_edges.sort(reverse=True)
    two_edges.sort(reverse=True)

    area_f = four_edges[0] * four_edges[0]
    if len(two_edges) >= 2:
        area_t = two_edges[0] * two_edges[1]
    else:
        area_t = 0
    area_t_t = two_edges[0] * four_edges[0]
    max_area = max(area_f, max(area_t, area_t_t))
    return max_area


N = int(input())
arr = list(map(int, input().split()))
res = solve()
print(res)


n=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)


import collections
d=collections.Counter(L)
M=0
m=[0,0]
for v in d:
	if d[v]>=4:
		M=max(M,v)
	elif d[v]>=2:
		m.append(v)
m.sort(reverse=True)

print(max(M**2,m[0]*m[1],M*m[0]))

import sys

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

cnt = 0
for i in range(N-1):
  if A[i] - A[i+1] == 0:
    cnt +=1
if cnt < 2:
  print("0")
  return

leng1 = 0
leng2 = 0
diff = 10**9

i = 0
while diff != 0:
  diff = A[i] - A[i+1]
  i += 1  
leng1= A[i]

A.remove(leng1)
A.remove(leng1)

i = 0
diff = 10**9
while diff != 0:
  diff = A[i] - A[i+1]
  i += 1  
leng2= A[i]

print(leng1*leng2)

import collections

_, *a = map(int, open(0).read().split())
c=collections.Counter(a)
tmp=[]
for k,v in c.items():
    if v>3:
        tmp.append(k)
    if v>1:
        tmp.append(k)
tmp.sort()
print(tmp[-1]*tmp[-2] if len(tmp) >1 else 0)

from collections import Counter

input()
ans = []
for i, j in list(Counter(list(map(int, input().split()))).items()):
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    ans.sort()
    print((ans[-1] * ans[-2]))
else:
    print((0))


import sys
import collections

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

count = collections.Counter(AN)


edge1 = 0
edge2 = 0
for c in sorted(list(count.keys()),reverse=True):
  if count[c] >= 4:
    if edge1 == 0:
      print((c*c))
      return
    else:
      print((edge1*c))
      return
  elif count[c] >= 2:
    if edge1 == 0:
      edge1 = c
    else:
      print((edge1*c))
      return
else:
  print((0))


from collections import Counter

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

A_ = sorted([[k, v] for k, v in cnt_A.items() if v >= 2], reverse=True)

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

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

pair = []
unpair = set()
for a in A:
    if a in unpair:
        pair.append(a)
        unpair.remove(a)
    else:
        unpair.add(a)

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

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 23 20:22:31 2020

@author: liang
"""

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

A.sort(reverse=True)

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

import numpy as np
#print(ans)
if len(ans) < 2:
    print(0)
else:
    print(np.prod(ans))

N = int(input())

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

A.sort()

s1 = 0
s2 = 0

at = -1
atc = 0

for a in A:
    if at == a:
        atc += 1

    else:
        if atc >= 4:
            s1 = at
            s2 = at
        elif atc >= 2:
            s2 = s1
            s1 = at
        
        at = a
        atc = 1

if atc >= 4:
    s1 = at
    s2 = at
elif atc >= 2:
    s2 = s1
    s1 = at

print((s1 * s2))