AtCoder Beginner Contest 071 - Make a Rectangle

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: EASY

Starter code:

Solutions:
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)


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 collections
N = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
p = []
for (k, v) in B.items():
	if v >= 2:
		p.append(k)
	if v >= 4:
		p.append(k)
if len(p) < 2:
	print(0)
else:
	p.sort()
	print(p[-1] * p[-2])


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)


n = int(input())
from collections import Counter
a = Counter(list(map(int, input().split())))
l = []
ll = []
ans = 0
for i in a:
	if a[i] >= 2:
		l.append(i)
	if a[i] >= 4:
		ans = max(ans, i * i)
l.sort(reverse=True)
if len(l) < 2:
	print(0)
else:
	print(max(l[0] * l[1], ans))


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)


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]))


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
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])


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
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)


import collections
n = int(input())
A = list(map(int, input().split()))
d = collections.Counter(A)
x = sorted([i for i in d.items() if i[1] > 1])
if len(x) == 0:
	print(0)
elif x[-1][1] > 3:
	print(x[-1][0] ** 2)
elif len(x) == 1:
	print(0)
else:
	print(x[-1][0] * x[-2][0])


N = input()
A = list(map(int, input().split()))
A.sort(reverse=True)
l = 0
w = 0
while len(A) >= 2:
	temp = A.pop(0)
	if temp == A[0]:
		if l == 0:
			l = A.pop(0)
		else:
			w = A.pop(0)
			break
print(l * w)


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)


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


from collections import *
n = int(input())
c = Counter(map(int, input().split()))
x = y = 0
for (k, v) in c.items():
	if v >= 2 and k > y:
		if k >= x:
			if v >= 4:
				x = y = k
			else:
				(x, y) = (k, x)
		else:
			y = k
print(x * y)


import collections
N = int(input())
c = collections.Counter(list(map(int, input().split())))
l4 = sorted([Ai for Ai in c if c[Ai] >= 4])
l2 = sorted([Ai for Ai in c if c[Ai] >= 2])
S = R = 0
if len(l4) >= 1:
	S = l4[-1] ** 2
if len(l2) >= 2:
	R = l2[-1] * l2[-2]
print(max(S, R))


from collections import *
(n, *a) = map(int, open(0).read().split())
r = []
s = []
for (k, v) in Counter(a).items():
	if v > 1:
		r += [k]
	if v > 3:
		s += [k]
if len(r) < 2 and len(s) < 1:
	print(0)
	exit()
r += [0, 0]
s += [0]
r.sort()
s.sort()
print(max(r[-1] * r[-2], s[-1] ** 2))


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)


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)


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)


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]])


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)


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\n3 1 2 4 2 1'
		output = '2'
		self.assertIO(input, output)

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

	def test_入力例_3(self):
		input = '10\n3 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]
		elif i < N - 1 and A[i + 1] == A[i]:
			l2 = A[i]
			break
	print(l1 * l2)

def __starting_point():
	resolve()
__starting_point()


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 = list(map(int, input().split()))
s = set()
cands = []
for i in a:
	if i in s:
		cands.append(i)
		s.remove(i)
	else:
		s.add(i)
x = sorted(cands, reverse=True)
if len(x) < 2:
	print(0)
else:
	print(x[0] * x[1])


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)


n = int(input())
a = map(int, input().split())
a = sorted(a)[::-1]
k = -2
l = -2
for i in range(n - 1):
	if (a[i] == a[i + 1]) & (i > k + 1):
		if k >= 0:
			l = i
			break
		else:
			k = i
if l >= 0:
	print(a[k] * a[l])
else:
	print(0)


import io
import math
data = int(input())
array = list(map(int, input().split()))
array.sort()
tmp = []
i = data - 1
while i > 0:
	if array[i] == array[i - 1]:
		tmp.append(array[i])
		i -= 2
	else:
		i -= 1
if len(tmp) >= 2:
	print(tmp[0] * tmp[1])
else:
	print(0)


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])


n = int(input())
a = list(map(int, input().split()))
x = 0
y = 0
a.sort()
i = n - 1
while i > 0:
	if a[i - 1] == a[i]:
		x = y
		y = a[i]
		if x > 0:
			break
		i -= 2
	else:
		i -= 1
print(x * y)


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = []
i = 0
while i < n - 1:
	if a[i] == a[i + 1]:
		l.append(a[i])
		i += 2
	else:
		i += 1
l.reverse()
if len(l) < 2:
	print(0)
else:
	print(l[0] * l[1])


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 = 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 = input().split()
d = {}
for i in a:
	d[i] = d.get(i, 0) + 1
for i in d:
	d[i] //= 2
ans = []
for i in d:
	ans += [int(i)] * int(d.get(i))
if len(ans) >= 2:
	ans.sort()
	print(ans[-1] * ans[-2])
else:
	print(0)


n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
ans = [0, 0]
i = j = 0
while i + 1 < n:
	if a[i] == a[i + 1]:
		ans[j] = a[i + 1]
		j += 1
		i += 2
		if j == 2:
			break
	else:
		i += 1
print(int(ans[0] * ans[1]))


N = int(input())
As = list(map(int, input().split()))
As.sort(reverse=True)
rs = []
a = -1
for i in range(N):
	A = As[i]
	if A == a:
		rs.append(A)
		a = -1
	else:
		a = A
if len(rs) < 2:
	print(0)
	exit()
r = rs[0] * rs[1]
print(r)


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


n = int(input())
al = list(map(int, input().split()))
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
	elif partial:
		ans = temp * e
		break
	else:
		ans = e ** 2
		break
print(ans)


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)


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])


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
	elif 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)


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


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
pair = []
for (x, cnt) in c.items():
	pair += [x] * (cnt // 2)
pair.sort()
ans = 0
if len(pair) >= 2:
	ans = pair[-1] * pair[-2]
print(ans)


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)


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()


N = int(input())
A = list(map(int, input().split()))
A.sort()
pre = 10 ** 10
cnt = 0
l = [0] * 2
i = N - 1
while cnt < 2 and i > 0:
	if A[i] == A[i - 1]:
		l[cnt] = A[i]
		cnt += 1
		i -= 2
	else:
		i -= 1
ans = l[0] * l[1]
print(ans)


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


n = int(input())
dic = dict()
l = list(map(int, input().split()))
for i in l:
	if i not in dic.keys():
		dic[i] = 1
	else:
		dic[i] += 1
p = [k for (k, v) in dic.items() if v >= 2]
f = 0
s = 0
for i in p:
	if i > f:
		(f, s) = (i, f)
	elif i > s:
		s = i
print(0 if f == 0 else f ** 2 if dic[f] >= 4 else f * s)


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()


import collections
n = int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
mc = c.most_common()
lec = sorted([i[0] for i in mc if i[1] >= 4] + [i[0] for i in mc if i[1] >= 2], reverse=True)
if len(lec) <= 1:
	print(0)
	exit()
else:
	print(lec[0] * lec[1])


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)


N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
for i in range(N - 1):
	if A[i] == A[i + 1]:
		A[i + 1] = 0
	elif A[i] != A[i + 1]:
		A[i] = 0
A.sort(reverse=True)
print(A[0] * A[1])


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)


from collections import Counter
N = input()
A = list(map(int, input().split()))
C = Counter(A)
M = [0, 0]
for (k, v) in C.items():
	if v < 2:
		continue
	M.append(k)
	if v >= 4:
		M.append(k)
	M.sort(reverse=True)
	M = M[:2]
print(M[0] * M[1])


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


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


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)


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()))
A = sorted(A)[::-1]
L = []
flag = 0
for i in range(N - 1):
	if A[i] == A[i + 1] and flag == 0:
		L.append(A[i])
		flag = 1
	else:
		flag = 0
if len(L) >= 2:
	print(L[0] * L[1])
else:
	print(0)


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


import collections
dump = input()
inp = list(map(int, input().split()))
A = collections.Counter(inp)
t_A = [el[0] for el in A.items() if el[1] > 1]
t_A.extend([el[0] for el in A.items() if el[1] > 3])
t_A = sorted(t_A)
if len(t_A) >= 2:
	print(t_A[-2] * t_A[-1])
else:
	print(0)


N = int(input())
d = {}
for i in input().split():
	x = int(i)
	if x not in d:
		d[x] = 1
	else:
		d[x] += 1
cnt = 0
ans = 1
for t in sorted(d.items(), reverse=True):
	if t[1] >= 2:
		ans *= t[0]
		cnt += 1
	if cnt == 1 and t[1] >= 4:
		ans *= t[0]
		cnt += 1
	if cnt >= 2:
		break
print(ans if cnt >= 2 else 0)


N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
flag = 0
result = [0, 0]
while len(A) >= 2 and flag < 2:
	N = A.pop(0)
	if N == A[0]:
		result[flag] = N
		del A[0]
		flag += 1
print(result[0] * result[1])


n = int(input())
list1 = list(map(int, input().split()))
list2 = set()
list1.sort()
list1.reverse()
(a, b) = (0, 0)
for i in list1:
	if i in list2:
		if i > a:
			a = i
			list2.remove(i)
		else:
			b = i
			break
	else:
		list2.add(i)
print('{0}'.format(a * b))


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
l = sorted(filter(lambda x: x[1] > 1, c.items()), reverse=True)
if len(l) == 0:
	print(0)
elif l[0][1] >= 4:
	print(l[0][0] ** 2)
else:
	print(l[0][0] * l[1][0])


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
i = n - 1
s1 = 0
s2 = 0
while i > 0:
	if a[i] == a[i - 1] and s1 == 0:
		s1 = a[i]
		i -= 2
		continue
	if a[i] == a[i - 1]:
		s2 = a[i]
		i -= 1
		break
	i -= 1
print(s1 * s2)


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)


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


from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
dic = Counter(a)
li = []
for (i, j) in dic.items():
	if j >= 2:
		li.append(i)
	if j >= 4:
		li.append(i)
li.sort()
if len(li) >= 2:
	print(li[-1] * li[-2])
else:
	print(0)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a).most_common()
s = [0, 0]
for v in c:
	if v[1] >= 2:
		for _ in range(v[1] // 2):
			s.append(int(v[0]))
s.sort()
print(s[-1] * s[-2])


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)


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


n = int(input())
(*a,) = sorted(map(int, input().split()))
r = [0, 0]
_a = a[0]
for i in range(1, n):
	if _a == a[i]:
		r.append(a[i])
		_a = -1
	else:
		_a = a[i]
print(r[-1] * r[-2])


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()))
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)


import collections
n = int(input())
a = [int(i) for i in input().split()]
(x, y, z) = (collections.Counter(a), [0], [0, 0])
for i in x.keys():
	if x[i] >= 4:
		y.append(i)
	if x[i] >= 2:
		z.append(i)
(y, z) = (sorted(y), sorted(z))
print(max(y[-1] ** 2, z[-1] * z[-2]))


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)


n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
X = []
t = -1
for i in A:
	if t == i:
		t = -1
		X.append(i)
		if len(X) > 1:
			break
	else:
		t = i
if len(X) > 1:
	print(X[0] * X[1])
else:
	print(0)


from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
B = [0, 0]
for i in A.keys():
	if A[i] >= 2:
		B.append(i)
	if A[i] >= 4:
		B.append(i)
B.sort()
print(B[-1] * B[-2])


n = int(input())
a = list(map(int, input().split()))
a.sort()
l1 = a[-1]
i = -2
try:
	while a[i] != l1:
		l1 = a[i]
		i -= 1
	i -= 1
	l2 = a[i]
	i -= 1
	while a[i] != l2:
		l2 = a[i]
		i -= 1
except:
	print(0)
	exit()
print(l1 * l2)


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)


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 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()


from collections import Counter
input()
a = sorted(filter(lambda x: x[1] > 1, Counter(map(int, input().split())).items()), reverse=True)
if a and a[0][1] >= 4:
	print(a[0][0] ** 2)
elif len(a) < 2:
	print(0)
else:
	print(a[0][0] * a[1][0])


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
pair = [0, 0]
c = Counter(a)
for (num, cnt) in c.items():
	pair += [num] * (cnt // 2)
pair.sort(reverse=True)
ans = pair[0] * pair[1]
print(ans)


N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = []
i = 0
while i + 1 < N:
	if len(b) == 2:
		break
	if a[i] == a[i + 1]:
		b += [a[i]]
		i += 2
	else:
		i += 1
if len(b) < 2:
	print(0)
else:
	print(b[0] * b[1])


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])


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


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
A = A + [0, 0, 0, 0]
for (i, a) in enumerate(A):
	if a == A[i + 1]:
		ans = a
		i = i + 2
		break
for (j, a) in enumerate(A[i:], i):
	if a == A[j + 1]:
		ans *= a
		break
print(ans)


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


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)


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


a = int(input())
b = list(map(int, input().split()))
b.sort()
c = 1
d = 0
dd = 0
p = b[0]
for i in range(1, a):
	if p == b[i]:
		c += 1
	elif p != b[i]:
		p = b[i]
		c = 1
	if c == 2:
		d = dd
		dd = p
	elif c == 4:
		d = p
		dd = p
print(d * dd)


N = int(input())
A = list(map(int, input().split()))
B = sorted(A)[::-1]
cnt = 1
a = 0
C = []
for i in B:
	if a == i:
		cnt += 1
		if cnt == 2:
			cnt = 0
			C.append(a)
		if len(C) == 2:
			print(C[0] * C[1])
			exit()
	else:
		a = i
		cnt = 1
print(0)


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


n = input()
a = [int(i) for i in input().split()]
a.sort(reverse=True)
x1 = 0
x2 = 0
i0 = 0
for i in a:
	if i == i0 and x1 == 0 and (x2 == 0):
		x1 = i
		i0 = 0
	elif i == i0 and x2 == 0:
		x2 = i
		i0 = 0
	else:
		i0 = i
print(x1 * x2)


n = int(input())
a = sorted(list(map(int, input().split())))
hen = [0, 0]
(i, j) = (0, 0)
while i < n:
	if a[i] == a[i - 1]:
		hen[j] = a[i]
		j = (j + 1) % 2
		i += 1
	i += 1
print(hen[0] * hen[1])


n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
stack = -1
t = []
for i in a:
	if stack == i:
		t.append(i)
		stack = -1
	else:
		stack = i
	if len(t) >= 2:
		break
try:
	print(t[0] * t[1])
except:
	print(0)


N = int(input())
A = list(map(int, input().split(' ')))
over2 = []
num = {}
for length in A:
	if length in num:
		num.pop(length)
		over2.append(length)
	else:
		num[length] = 1
over2.sort()
if len(over2) >= 2:
	print(over2[-1] * over2[-2])
else:
	print(0)


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)


N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
pre = 0
(e1, e2) = (0, 0)
for a in A:
	if pre == a:
		if e1 == 0:
			e1 = a
		elif e2 == 0:
			e2 = a
		pre = 0
	else:
		pre = a
print(e1 * e2)


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)


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])


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


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = sorted(Counter(A).most_common(), reverse=True)
D = list(filter(lambda x: x[1] >= 2, C))
if len(D) < 2:
	print(0)
else:
	print(D[0][0] ** 2 if D[0][1] >= 4 else D[0][0] * D[1][0])


n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
E = [0, 0]
j = 0
for i in range(n):
	if E[j] == A[i]:
		j += 1
		if j == 1:
			continue
		else:
			break
	E[j] = A[i]
print(E[0] * E[1])


import collections
N = int(input())
L = list(map(int, input().split()))
ANS = [0, 0]
c = collections.Counter(L).most_common()
for (k, v) in c:
	if v <= 1:
		break
	if v >= 4:
		ANS.append(k)
		ANS.append(k)
	else:
		ANS.append(k)
Z = sorted(ANS)
print(Z[-1] * Z[-2])


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)


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)


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)


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


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


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.sort(reverse=True)
c = 0
d = 0
for i in range(N):
	if a[i] == d:
		if c == 0:
			c = a[i]
			d = 0
		else:
			print(c * a[i])
			exit()
	else:
		d = a[i]
print(0)


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])


N = int(input())
A = sorted([int(_) for _ in input().split()], reverse=True)
e = []
pre = 0
for i in range(N):
	if pre == A[i]:
		e.append(A[i])
		if len(e) >= 2:
			break
		pre = 0
	else:
		pre = A[i]
if len(e) < 2:
	print(0)
else:
	print(e[0] * e[1])


n = int(input())
a = list(map(int, input().split()))
l = []
d = dict()
for v in a:
	if v not in d:
		d[v] = 1
	else:
		d[v] += 1
	if d[v] == 2 or d[v] == 4:
		l.append(v)
if len(l) < 2:
	print(0)
else:
	l.sort()
	print(l[-1] * l[-2])


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)
lis.sort(reverse=True)
if len(lis) <= 1:
	ans = 0
else:
	ans = lis[0] * lis[1]
print(ans)


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)


N = int(input())
A = list(map(int, input().split()))
long1 = 0
long2 = 0
A = sorted(A)
pair = 1
for i in range(N - 1):
	if A[i] == A[i + 1] and pair == 1:
		long2 = long1
		long1 = A[i]
		pair = 0
	else:
		pair = 1
if long2 == 0:
	ans = 0
else:
	ans = long1 * long2
print(ans)


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)


N = int(input())
A = list(map(int, input().split()))
A.sort()
l = 0
m = 0
while len(A) >= 2:
	a = A.pop()
	b = A.pop()
	if a == b:
		if l == 0:
			l = a
		elif m == 0:
			m = a
	else:
		A.append(b)
print(l * m)


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())
A = list(map(int, input().split()))
top1 = 0
top2 = 0
c = Counter()
for a in A:
	c[a] += 1
	if c[a] % 2 == 0:
		L = [a, top1, top2]
		L.sort()
		top1 = L[2]
		top2 = L[1]
print(top1 * top2)


N = int(input())
E = list(map(int, input().split()))
E.sort(reverse=True)
pre = 0
nums = []
for e in E:
	if pre == e:
		nums.append(e)
		pre = 0
	else:
		pre = e
	if len(nums) == 2:
		print(nums[0] * nums[1])
		quit()
print(0)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
count = []
i = 0
while i < n - 1:
	if lst[i] == lst[i + 1]:
		count.append(lst[i])
		i += 2
	else:
		i += 1
count.sort(reverse=True)
count.append(0)
count.append(0)
print(count[0] * count[1])


input()
from collections import *
c = Counter(map(int, input().split()))
f = lambda x: sorted((-k for (k, v) in c.items() if v > x))
a = 0
r = f(1)
s = f(3)
if len(r) > 1:
	a = r[0] * r[1]
if s:
	a = max(a, s[0] ** 2)
print(a)


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])


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())
li = list(map(int, input().split()))
li.sort(reverse=True)
vert = {}
even = []
ans = 0
for i in li:
	if i in vert:
		vert.pop(i)
		even.append(i)
		if len(even) == 2:
			ans = even[0] * even[1]
			break
	else:
		vert[i] = 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
(D, L) = ({}, [0, 0])
for a in A:
	if a not in D:
		D[a] = 1
	else:
		L.append(a)
		del D[a]
L.sort(reverse=True)
print(L[0] * L[1])


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 = [int(i) for i in input().split()]
a.sort(reverse=True)
s = 0
t = 0
x = 0
y = 0
for _ in range(N):
	i = a[_]
	if t == 0:
		if s == i:
			t = i
		else:
			s = i
	elif x == i:
		y = i
		break
	else:
		x = i
print(s * x)


d = {}
_ = input()
for x in input().split():
	x = int(x)
	d[x] = d.get(x, 0) + 1
p = []
for (k, v) in d.items():
	if v >= 4:
		p.append(k)
	if v >= 2:
		p.append(k)
if len(p) < 2:
	print(0)
else:
	p.sort(reverse=True)
	print(p[0] * p[1])


N = int(input())
A = [int(i) for i in input().split()]
count = 0
s = 1
i = 0
A.sort()
A.reverse()
while i < N - 1 and count < 2:
	if A[i] == A[i + 1]:
		s = s * A[i]
		count += 1
		i += 2
	else:
		i += 1
if count >= 2:
	print(s)
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l.reverse()
a = b = c = d = 0
for i in l:
	if a == 0:
		a = i
	elif b == 0:
		b = i
		if a != b:
			a = b
			b = 0
	elif c == 0:
		c = i
	elif d == 0:
		d = i
		if c != d:
			c = d
			d = 0
	else:
		break
print(b * d)


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())
A = sorted(list(map(int, input().split())), reverse=True)
(x, y) = (0, 0)
for i in range(N - 1):
	if A[i] == A[i + 1]:
		x = A[i]
		break
for j in range(i + 2, N - 1):
	if A[j] == A[j + 1]:
		y = A[j]
		break
print(x * y)


n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
i = 0
c = 0
m = list()
while i < n - 1:
	if a[i] == a[i + 1]:
		m.append(a[i])
		i += 1
		c += 1
	i += 1
	if c == 2:
		break
if c == 2:
	print(m[0] * m[1])
else:
	print(0)


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
before = 0
c = 0
x = -1
for a in A:
	if before == a:
		c += 1
		if c == 2:
			if x == -1:
				x = a
			else:
				print(x * a)
				break
		if c == 4:
			print(a ** 2)
			break
	else:
		before = a
		c = 1
else:
	print(0)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
x1 = 0
x2 = 0
count = Counter(a)
for i in count:
	if count[i] >= 4:
		if x1 <= i:
			x2 = i
			x1 = i
	if count[i] >= 2:
		if x1 <= i:
			x2 = x1
			x1 = i
		elif x2 <= i < x1:
			x2 = i
print(x1 * x2)


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())
A = [int(x) for x in input().split()]
A.sort()
for i in range(N - 1):
	if A[i] == A[i + 1]:
		A[i + 1] = 0
	else:
		A[i] = 0
A[N - 1] = 0
A.sort()
A.reverse()
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)


from collections import Counter
input()
a = sorted(Counter(map(int, input().split())).most_common())[::-1]
c = b = 0
for i in range(len(set(a))):
	if b and c:
		break
	if a[i][1] > 3 and a[i][0] * c < a[i][0] ** 2:
		b = c = a[i][0]
	elif a[i][1] > 1:
		(b, c) = (c, a[i][0])
print(c * b)


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])


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 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))


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)


n = int(input().strip())
li = list(map(int, input().strip().split()))
d = {}
res = []
for i in li:
	d[i] = d.get(i, 0) + 1
	if d[i] == 2 or d[i] == 4:
		res.append(i)
if len(res) < 2:
	print(0)
else:
	res = sorted(res, reverse=True)
	print(res[0] * res[1])


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()))
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 = list(map(int, input().split()))
A.sort()
tmp = []
i = N - 1
while i > 0:
	if A[i] == A[i - 1]:
		tmp.append(A[i])
		i -= 2
	else:
		i -= 1
if len(tmp) >= 2:
	print(tmp[0] * tmp[1])
else:
	print(0)


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


num = int(input())
hen = sorted(list(map(int, input().split(' '))), reverse=True)
i = 0
a = []
while i < num - 1:
	if hen[i] == hen[i + 1]:
		a.append(hen[i])
		i += 2
	else:
		i += 1
if len(a) < 2:
	print(0)
else:
	print(a[0] * a[1])


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


N = int(input())
A = list(map(int, input().split()))
a = b = c = 0
for i in sorted(A)[::-1]:
	c += 1
	if a == i:
		break
	a = i
B = sorted(A)[:-c]
c = 0
d = len(B)
for i in B[::-1]:
	c += 1
	if b == i:
		break
	b = i
	if c == d:
		b = 0
print(a * b)


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


n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
use = []
flag = -1
for i in range(n):
	if flag == a[i]:
		use.append(a[i])
		flag = -1
	else:
		flag = a[i]
if len(use) < 2:
	print(0)
else:
	use.sort(reverse=True)
	print(use[0] * use[1])


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())
a = list(map(int, input().split()))
d = {}
x = [0, 0]
for i in range(n):
	try:
		d[a[i]] += 1
		if d[a[i]] == 2 or d[a[i]] == 4:
			x.append(a[i])
	except:
		d[a[i]] = 1
x.sort()
x.reverse()
print(x[0] * x[1])


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

def max_pair(Asc):
	m1 = 0
	while Asc:
		m2 = Asc.pop()
		if m1 == m2:
			return m1
		m1 = m2
	return 0
A.sort()
print(max_pair(A) * max_pair(A))


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
	d[i] = d.get(i, 0) + 1
s = [i for i in d if d[i] >= 2] + [0, 0]
s.sort(reverse=True)
if d.get(s[0], 0) >= 4:
	print(s[0] ** 2)
else:
	print(s[0] * s[1])


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)


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)


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)


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
	elif d[i][1] >= 2:
		ans = temp * d[i][0]
		break
print(ans)


import collections
n = int(input())
a = [int(i) for i in input().split()]
l = collections.Counter(a)
l_ = [k for (k, v) in l.items() if v > 1]
if len(l_) > 1:
	l_.sort()
	if l[l_[-1]] > 3:
		print(l_[-1] ** 2)
	else:
		print(l_[-1] * l_[-2])
else:
	print(0)


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()))
temp_set = set()
l = []
for a in A:
	if a in temp_set:
		l.append(a)
		temp_set.remove(a)
	else:
		temp_set.add(a)
l.sort()
if len(l) >= 2:
	print(l[-2] * l[-1])
else:
	print(0)


n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
side = []
i = 0
while i < n - 1:
	if A[i] == A[i + 1]:
		side.append(A[i])
		i += 2
	else:
		i += 1
print(0 if len(side) < 2 else side[0] * side[1])


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)


import os
import sys
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().rstrip().split(' ')))
A.sort()
lis = []
for i in range(len(A) - 1):
	if A[i] == A[i + 1]:
		lis.append(A[i])
		A[i + 1] = 0
if len(lis) < 2:
	print(0)
else:
	print(lis[-1] * lis[-2])


from collections import Counter
N = int(input())
A = [int(n) for n in input().split()]
pairs = sorted([k for (k, v) in Counter(A).items() if v >= 2] + [k for (k, v) in Counter(A).items() if v >= 4], reverse=True)
if len(pairs) < 2:
	print(0)
else:
	print(pairs[0] * pairs[1])


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
a = 0
b = 0
check = -1
for i in range(n - 1):
	if l[i] == l[i + 1]:
		if check != i:
			if a == 0:
				a = l[i]
				check = i + 1
			elif b == 0:
				b = l[i]
print(a * b)


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)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
H = 0
W = 0
i = 0
while i < n - 1:
	if a[i] == a[i + 1]:
		if H == 0:
			H = a[i]
			i += 2
		else:
			W = a[i]
			break
	else:
		i += 1
print(H * W)


from collections import *
(n, *a) = map(int, open(0).read().split())
d = defaultdict(int)
l = []
for i in a:
	if d[i] % 2:
		l.append(i)
	d[i] += 1
if len(l) > 1:
	(*_, a, b) = sorted(l)
	print(a * b)
else:
	print(0)


from collections import Counter
n = int(input())
l = map(int, input().split())
o = sorted(filter(lambda x: x[1] >= 2, Counter(l).items()))
if len(o) < 2:
	print(0)
elif o[-1][1] >= 4:
	print(o[-1][0] * o[-1][0])
else:
	print(o[-1][0] * o[-2][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])


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))


from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
c = []
for (k, v) in a.items():
	if v >= 2:
		c.append(k)
	if v >= 4:
		c.append(k)
c.sort()
c = c[::-1]
if len(c) < 2:
	print(0)
else:
	print(c[0] * c[1])


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)


from itertools import groupby
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
g = groupby(a)
s = [0, 0]
for (k, v) in g:
	l = len(list(v))
	while l > 1:
		s.append(k)
		l -= 2
s = sorted(s)
print(s[-1] * s[-2])


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])


from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split())))
bar = []
for (k, v) in A.items():
	bar += [k] * (v // 2)
bar.sort(reverse=True)
if len(bar) < 2:
	print(0)
else:
	print(bar[0] * bar[1])


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)


n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
l = 0
ans = []
for i in a:
	if l == i:
		ans.append(i)
		l = 0
	else:
		l = i
	if len(ans) == 2:
		print(ans[0] * ans[1])
		exit()
print(0)


n = int(input())
al = list(map(int, input().split()))
al.sort(reverse=True)
cnt = 0
h = 0
w = 0
t = set()
for a in al:
	if a in t:
		if h == 0:
			h = a
		else:
			w = a
			break
		t.remove(a)
	else:
		t.add(a)
print(h * w)


n = int(input().strip())
a = list(map(int, input().split()))
reps = []
a.sort()
tmp = 0
for e in a:
	if e == tmp:
		reps.append(e)
		tmp = 0
	else:
		tmp = e
if len(reps) < 2:
	print(0)
else:
	print(reps[-1] * reps[-2])


n = int(input())
a = sorted(list(map(int, input().split())))
s = t = 0
i = n - 1
while i >= 4 and a[i] != a[i - 1]:
	i -= 1
if a[i] == a[i - 1]:
	s = a[i]
	i -= 2
while i >= 2 and a[i] != a[i - 1]:
	i -= 1
if a[i] == a[i - 1]:
	t = a[i]
print(s * t)


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


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])


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)


from collections import Counter as C
(n, *a) = map(int, open(0).read().split())
b = []
for i in C(a).items():
	if i[1] > 3:
		b += [i[0], i[0]]
	elif i[1] > 1:
		b += [i[0]]
b = sorted(b)
print(b[-1] * b[-2] if len(b) > 1 else 0)


n = int(input())
l = sorted((int(x) for x in input().split()), reverse=True)
a = []
t = None
for x in l:
	if t == x:
		t = None
		a.append(x)
		if len(a) > 1:
			break
	else:
		t = x
print(a[0] * a[1] if len(a) > 1 else 0)


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)


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()


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)


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)


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
N = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
C = []
for (a, c) in B.items():
	C += [a] * (c // 2)
C.sort()
if len(C) >= 2:
	print(C[-1] * C[-2])
else:
	print(0)


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
maxs = []
for i in range(2):
	max_1 = a.pop()
	while True:
		max_2 = a.pop()
		if max_1 == max_2:
			maxs.append(max_1)
			break
		max_1 = max_2
		if len(a) == 0:
			print(0)
			exit()
print(maxs[0] * maxs[1])


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


n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
(h, w, i) = (0, 0, 0)
while i < n - 1:
	if a[i] == a[i + 1]:
		if h == 0:
			h = a[i]
			i += 1
		else:
			w = a[i]
			break
	i += 1
print(h * w)


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]:
		ans.append(A[i])
		i += 1
	if len(ans) == 2:
		break
	i += 1
import numpy as np
if len(ans) < 2:
	print(0)
else:
	print(np.prod(ans))


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)


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
edge = [0, 0]
index = 0
tmp = 0
for i in range(0, N):
	if 2 <= index:
		break
	if tmp == A[i]:
		edge[index] = A[i]
		tmp = 0
		index += 1
	else:
		tmp = A[i]
print(edge[0] * edge[1])


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


(n, a) = (int(input()), sorted(list(map(int, input().split()))))
i = n - 1
ans = 1
c = 0
while i > 0:
	if a[i - 1] == a[i]:
		i -= 1
		c += 1
		ans *= a[i]
		if c == 2:
			print(ans)
			exit()
	i -= 1
print(0)


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])


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
x = 0
y = 0
tmp = 0
for a in A:
	if tmp == a:
		if not x:
			x = a
			tmp = 0
		else:
			y = a
			tmp = 0
	else:
		tmp = a
	if x and y:
		break
print(x * y)


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)


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)


n = int(input())
a = list(map(int, 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]
		break
for j in range(i + 2, n - 1):
	if a[j] == a[j + 1]:
		w = a[j]
		break
print(h * w)


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)


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)


import collections
N = int(input())
A = list(map(int, input().split()))
a = collections.Counter(A)
array = [0, 0]
for i in a:
	if a[i] >= 4:
		array += [i, i]
	elif a[i] >= 2:
		array.append(i)
array.sort()
array.reverse()
print(array[0] * array[1])


N = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
h = []
count = 0
f = 0
for i in a:
	if f == i:
		h.append(i)
		count += 1
		f = 0
	else:
		f = i
		if count == 2:
			break
if count == 2:
	print(h[0] * h[1])
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)


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


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


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)


N = int(input())
A = list(map(int, input().split()))
A.sort(key=lambda x: -x)
l = []
a_old = -1
for a in A:
	if a_old == a:
		l.append(a)
		a_old = -1
	else:
		a_old = a
l.append(0)
l.append(0)
print(l[0] * l[1])


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


from collections import Counter
N = int(input())
A = [int(x) for x in input().split()]
pair = []
c = Counter(A)
for (x, cnt) in c.items():
	pair += [x] * (cnt // 2)
pair.sort()
answer = 0
if len(pair) >= 2:
	answer = pair[-1] * pair[-2]
print(answer)


N = int(input())
A = [int(_) for _ in input().split()]
import collections
c = collections.Counter(A)
xs = [x for (x, n) in c.items() if n >= 2]
xs.sort()
if len(xs) >= 1 and c[xs[-1]] >= 4:
	print(xs[-1] ** 2)
elif len(xs) >= 2:
	print(xs[-1] * xs[-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()


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
(x, y) = (0, 0)
for (k, v) in a.items():
	if v >= 2 and k > y:
		if k >= x:
			if v >= 4:
				y = k
			else:
				y = x
			x = k
		else:
			y = k
print(x * y)


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])


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))


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


n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
for i in range(n - 1):
	if a[i] == a[i + 1]:
		a[i + 1] = 0
	elif a[i] != a[i + 1]:
		a[i] = 0
a = sorted(a, reverse=True)
print(a[0] * a[1])


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)


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


n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
for i in range(n - 3):
	if a[i] == a[i + 1]:
		for j in range(i + 2, n):
			if a[j] == a[j + 1]:
				print(a[i] * a[j])
				exit()
print(0)


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()


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


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


def main():
	N = int(input())
	A = sorted(list(map(int, input().split())))
	i = 0
	d = [0, 0]
	while N - 1 > i:
		if A[i] == A[i + 1]:
			d.append(A[i])
			i += 1
		i += 1
	print(d[-1] * d[-2])
main()