Problem:
 Score : 300 points    Problem Statement We have N sticks with negligible thickness.
The length of the i -th stick is A_i .  Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.      Constraints  4 \leq N \leq 10^5  1 \leq A_i \leq 10^9  A_i is an integer.         Input Input is given from Standard Input in the following format:  N  A_1  A_2 ... A_N       Output Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0 .        Sample Input 1 6
3 1 2 4 2 1      Sample Output 1 2  1 \times 2 rectangle can be formed.       Sample Input 2 4
1 2 3 4      Sample Output 2 0  No rectangle can be formed.       Sample Input 3 10
3 3 3 3 4 4 4 5 5 5      Sample Output 3 20

Solution (Python):




def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    
    
    
    
    n=int(input())
    a = list(map(int,input().split()))
    x={}
    for i in range(n):
        if a[i] not in x:
            x[a[i]]=1
        else:
            x[a[i]]+=1
    y=[]
    for i in x:
        if x[i]>=2:
            y.append(i)
            if x[i]>=4:
                y.append(i)
    y.sort(reverse=True)
    if len(y)>=2:
        print(y[0]*y[1])
    else:
        print(0)

main()

Solution (Python):
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  ans = 0
  a = sorted(a,reverse = True)
  query = []
  flag = False
  for i in range(n-1):
    if flag:
      flag = False
      continue
      
    if a[i] == a[i+1]:
      query.append(a[i])
      flag = True

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

Solution (Python):
from collections import Counter

N = int(input())
A = Counter(list(map(int, input().split())))
A = {k: v for k, v in A.items() if v >= 2}
A = sorted(A.items(), key=lambda x: x[0], reverse=True)
A.extend([(0, 0), (0, 0)])
if A[0][1] >= 4:
    print(A[0][0]**2)
else:
    print(A[0][0]*A[1][0])

Solution (Python):
n = int(input())
A = sorted(list(map(int, input().split())))
up2_max = 0
up2_2nd = 0
up4_max = 0

from bisect import bisect_left, bisect_right
B = sorted(list(set(A)), reverse=True)
for cand in B:
  num = bisect_right(A, cand) - bisect_left(A, cand)
  if num >= 4:
    up4_max = cand
    break
for i, cand in enumerate(B):
  num = bisect_right(A, cand) - bisect_left(A, cand)
  if num >= 2:
    up2_max = cand
    break
for j in range(i+1, n):
  num = bisect_right(A, B[j]) - bisect_left(A, B[j])
  if num >= 2:
    up2_2nd = B[j]
    break
print(max(up4_max**2, up2_max * up2_2nd))

Solution (Python):
n= int(input())
a= list(map(int, input().split()))
from collections import Counter
c= Counter(a).most_common()
c.sort(key=lambda x: x[0],reverse=True)
tate=0
kouho=0
sei=0
chou=0
for i in c:
    if sei==0 and i[1]>=4:
        if tate:
            sei=i[0]*tate
        else:
            sei=i[0]**2
    elif chou==0 and i[1]>=2:
        if tate:
            yoko=i[0]
            chou=yoko*tate
        else:
            tate=i[0]
print(max(chou,sei))

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
w = 0
h = 0
for i in range(n-1):
    if a[i] == a[i+1] and w == 0:
        w = a[i]
        a[i+1] = 0
    if a[i] == a[i+1] and w != 0:
        h = a[i]
        break
if w == 0 or h == 0:
    ans = 0
else:
    ans = int(h*w)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
flag1 = 1
flag2 = 0
w = 0
h = 0
for i in range(n-1):
    flag2 = 1
    if a[i] == a[i+1] and flag1:
        w = a[i]
        a.pop(i+1)
        flag1 = 0
        flag2 = 0
    if a[i] == a[i+1] and flag2:
        h = a[i]
        break
if w == 0 or h == 0:
    ans = 0
else:
    ans = int(h*w)
print(ans)

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


if __name__ == '__main__':
    main()

Solution (Python):
import collections 

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

A=collections.Counter(A)
A=list(A.items())
A.sort(reverse=True)


x,y=0,0
for a in A:
  if x and a[1]>=2:
    y=a[0]
    break
  if a[1]>=2:
    if a[1]>=4:
      x,y=a[0],a[0]
      break
    else:
      x=a[0]

print(x*y)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=map(int,input().split())
    from collections import Counter
    c=Counter(A)
    ans=0
    first=0
    second=0
    for k,v in c.items():
        if v>=4: ans=max(ans,k*k)
        if v>=2:
            if k>first:
                first,second=k,first
            elif k>second:
                second=k
    print(max(ans,first*second))
resolve()

Solution (Python):
from collections import Counter

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

ans = [0, 0]
for k in sorted(A.keys(), reverse=True):
    if A[k] >= 2:
        ans.append(k)
    if A[k] >= 4:
        ans.append(k)
ans = sorted(ans)
print(ans[-1]*ans[-2])

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

A.sort(reverse=True)

cnt=1
r=[]
for i in range(1,N):
    if A[i-1]==A[i]:
        cnt+=1
    else:
        if len(r)==0 and cnt>=4:
            print(A[i-1]*A[i-1])
            exit()
        elif cnt>=2:
            r.append(A[i-1])
            if len(r)==2:
                print(r[0]*r[1])
                exit()
            cnt=1
        else:
            cnt=1
if cnt>=2:
    r.append(A[i-1])
    if len(r)==2:
        print(r[0]*r[1])
        exit()

print(0)

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

rect = [-1, -1]
for key in sorted(A.keys(), reverse=True):
  if A[key] >= 4:
    print(max(rect[0]*key, key**2))
    exit()
  elif A[key] >= 2:
    if rect == [-1,-1]: rect[0] = key
    else:
      print(rect[0]*key)
      exit()
print(0)

Solution (Python):
from collections import Counter

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

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a = sorted(collections.Counter(a).most_common(), key=lambda x: x[0], reverse=True)
    ans = []
    for k, v in a:
        if v >= 2:
            for i in range(v // 2 * 2):
                ans.append(k)
        if len(ans) >= 4:
            print(ans[0] * ans[2])
            exit()
    print(0)


if __name__ == '__main__':
    slove()

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

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


dic = collections.defaultdict(int)

for x in A:
    dic[x] += 1

dic = list(dic.items())
dic = [x for x in dic if x[1] >= 2]
dic = sorted(dic, reverse=True, key=lambda x: x[0])

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

Solution (Python):
import heapq

N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: -x, A))

heapq.heapify(A)
a = - heapq.heappop(A)
for i in range(N-1):
    b = - heapq.heappop(A)
    if a == b:
        x = a
        break
    else:
        a = b
else:
    x = 0

if len(A) >= 2:
    c = - heapq.heappop(A)
    for j in range(len(A)):
        d = - heapq.heappop(A)
        if c == d:
            y = c
            break
        else:
            c = d
    else:
        y = 0
else:
    y = 0

ans = x*y
print(ans)

Solution (Python):


from collections import Counter,deque


from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

h,w=0,0
l=0
n=int(input().rstrip())
a=sorted(Counter([int(i) for i in input().split()]).most_common(),reverse=1)

for i in range(len(a)):
    if a[i][1]>=4:
        print(a[i][0]**2)
        exit()
    elif a[i][1]>=2:
        h=a[i][0]
        l=i+1
        break

for i in range(l,len(a)):
    if a[i][1]>=2:
        w=a[i][0]
        break
print(h*w)

Solution (Python):
from collections import defaultdict


n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
    d[a[i]] += 1

b = sorted(list(set(a)))[::-1]
newa = []
for i in range(len(b)):
    if d[b[i]] >= 2:
        newa.append((b[i], d[b[i]]))

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    import collections
    a = collections.Counter(a).most_common()
    a = sorted(a, key=lambda x: x[0], reverse=True)
    t = -1
    for k, v in a:
        if v >= 4:
            if t != -1:
                print(t * k)
                exit()
            else:
                print(k ** 2)
                exit()
        elif v >= 2:
            if t != -1:
                print(t * k)
                exit()
            else:
                t = k
    print(0)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)

for a in A:
    d[a] += 1

E = [(k, v) for k, v in d.items() if v >= 2]
E.sort(key=lambda x: -x[0])

if len(E) == 0:
    print(0)
    exit()
if len(E) == 1 and E[0][1] < 4:
    print(0)
    exit()

if E[0][1] >= 4:
    print(E[0][0] ** 2)
else:
    print(E[0][0] * E[1][0])

Solution (Python):
import collections
n = int(input())
a = collections.Counter(list(map(int, input().split()))).most_common()
a = sorted(a, reverse=True)
t = 0
for i, v in a:
    if v >= 4:
        if t == 0:
            print(i * i)
            exit()
        else:
            print(t * i)
            exit()
    elif v >= 2:
        if t == 0:
            t = i
        else:
            print(t * i)
            exit()
print(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
cnt=0
x=0
d=[]
for i in range(n):
	if x==a[i]:
		cnt+=1
	else:
		x=a[i]
		cnt=0
	if cnt==1:
		d.append(a[i])
	if cnt==3:
		d.append(a[i])
	if len(d)==2:
		break
if len(d)<=1:
	print(0)
	exit()
print(d[0]*d[1])

Solution (Python):
import collections

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

c = list(collections.Counter(A).items())
c.sort(reverse=True)

a = 0
b = 0
e = -1

for i in range(N):
    if c[i][1] >= 4:
        a = c[i][0]
        b = c[i][0]
        break
    elif c[i][1] >= 2:
        a = c[i][0]
        e = i
        break

if a == 0:
    print(0)
elif e !=-1:
    for i in range(e+1, N):
        if c[i][1] >= 2:
            b = c[i][0]
            break
    if b == 0:
        print(0)
    else:
        print(a*b)
else:
    print(a*b)

Solution (Python):
import collections
import heapq
n=int(input())
a=[-int(item) for item in input().split()]
c = [item for item in list(collections.Counter(a).items()) if item[1]>1]
heapq.heapify(c)


if len(c)==0:
  print(0)
  exit()
if sum([item[1] for item in c])<4:
  print(0)
  exit()

x=heapq.heappop(c)
if c!=[]:
  y=heapq.heappop(c)
else:
  y=(0,0)
if x[1]>=4:
  print(x[0]*x[0])
else:
  print(x[0]*y[0])

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

A.sort()

first_edge = -1
second_edge = -1

used = [False for i in range(N)]
for i in range(N - 1, 0, -1):
    if first_edge < 0 and A[i] == A[i - 1] and (not used[i]) and (not used[i - 1]):
        first_edge = A[i]
        used[i] = True
        used[i - 1] = True
    if first_edge > 0 and A[i] == A[i - 1] and (not used[i]) and (not used[i - 1]):
        second_edge = A[i]
        break
        
if first_edge < 0 or second_edge < 0:
    print(0)
else:
    print(first_edge * second_edge)

Solution (Python):


import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()

count=0
h=0
w=0
i=0
while(1):

	if(i<n-1):
		if(hoge[n-1-i]==hoge[n-2-i]):
			if(count==0):
				h=hoge[n-1-i]
				count+=1
				i+=1
			else:
				w=hoge[n-1-i]
				break
		i+=1
	else:
		break
print(w*h)

Solution (Python):


import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()

count=0
h=0
w=0
i=0
while(1):

	if(i<n-1):
		if(hoge[n-1-i]==hoge[n-2-i]):
			if(count==0):
				h=hoge[n-1-i]
				count+=1
				i+=1
			else:
				w=hoge[n-1-i]
				break
		i+=1
	else:
		break
print(w*h)

Solution (Python):


from collections import Counter

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

x=sorted(list(a.items()),reverse=True)



ans=0
for k,v in x:
    if v<2:continue
    if v>3:
        if ans==0:
            ans=k**2
        else:
            ans*=k
        break
    else:
        if ans==0:
            ans=k
        else:
            ans*=k
            break

print(ans)

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

max_1 = 0
len_a = len(A)
for i, a in enumerate(A):
    if len_a - i >= 4:
        if A[i] == A[i+1] and A[i+1] == A[i+2] and A[i+2] == A[i+3]:
            if max_1 == 0:
                print(A[i] ** 2)
                exit()
            else:
                print(A[i] * max_1)
                exit()
    if len_a - i >= 2:
        if A[i] == A[i+1]:
            if max_1 == 0:
                max_1 = A[i]
            else:
                if max_1 != A[i]:
                    print(A[i] * max_1)
                    exit()
print(0)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in b:
    if i not in c:
        c[i] = 1
    else:
        c[i] += 1
c = sorted(c.items(), key=lambda x: x[0], reverse=True)
d = 0
for k, v in c:
    if v // 2 == 1:
        if d != 0:
            print(d * k)
            exit()
        else:
            d = k
    elif v // 2 >= 2:
        if d != 0:
            print(d * k)
            exit()
        else:
            print(k ** 2)
            exit()
print(0)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in b:
    if i not in c:
        c[i] = 1
    else:
        c[i] += 1
c = sorted(c.items(), key=lambda x: x[0], reverse=True)
d = 0
for k, v in c:
    if v // 2 == 1:
        if d != 0:
            print(d * k)
            exit()
        else:
            d = k
    elif v // 2 >= 2:
        if d != 0:
            print(d * k)
            exit()
        else:
            print(k ** 2)
            exit()
print(0)

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


num = []
cnt = 1
for i in range(N):
    if i == 0:
        cnt = 1
    else:
        if A[i-1] == A[i]:
            cnt += 1
            if i == N-1:
                num.append([A[i-1],cnt])
        else:
            if cnt > 1:
                num.append([A[i-1],cnt])
                cnt = 1

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

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
b = sorted(b, reverse=True)
c = []
d = []
for i in range(1, len(b)):
    if i-1 not in d:
        if b[i] == b[i-1]:
            c.append(b[i])
            d.append(i)
        if len(c) == 2:
            print(c[0] * c[1])
            exit()
print(0)

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

Solution (Python):
from collections import Counter
n = int(input())
a = list(int(_) for _ in input().split())
t1,t2 = [0,0],[0]
for k,v in Counter(a).items():
    if v >= 2: t1.append(k)
    if v >= 4: t2.append(k)

t1.sort()
t2.sort()
print(max(t1[-1]*t1[-2],t2[-1]**2))

Solution (Python):
from collections import Counter
n=int(input())
a=Counter(list(map(int,input().split())))
b=[i for i,j in a.items() if j>=2]+[0,0]
c=[i for i,j in a.items() if j>=4]+[0]
b.sort(reverse=True)
c.sort(reverse=True)
print(max(b[0]*b[1],c[0]**2))

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

Solution (Python):
import collections

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

A_count = collections.Counter(A)
A_most = A_count.most_common()

ans = []
for a in A_most:
    if a[1] > 1:
        ans.append(a[0])
        if a[1] > 3:
            ans.append(a[0])

ans.sort()

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

Solution (Python):
from collections import Counter

n=int(input())
a=list(map(int, input().split()))
A=Counter(a)
A_most = A.most_common()
d=[]
for i in A_most:
    if i[1]>=4:
        d.append(i[0])
        d.append(i[0])
    elif i[1]>=2:
        d.append(i[0])
d=sorted(d)
print(d[-1]*d[-2] if len(d)>0 else 0)

Solution (Python):
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
d=[]
L=Counter(l)
a=L.most_common()
for i in range(len(a)):
  if a[i][1]>=4:
    d.append(a[i][0])
    d.append(a[i][0])
  elif a[i][1]>=2:
    d.append(a[i][0])
d.sort(reverse=True)
print(d[0]*d[1] if len(d)>=2 else 0)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
i = 0
flag = False
ans = 0
while i < n-1:
    if not flag and a[i+1] == a[i]:
        flag = True
        h = a[i]
        i += 2
    elif flag and a[i+1] == a[i]:
        ans = h * a[i]
        break
    else:
        i += 1

print(ans)

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

l = [0,0]
cnt = {}

for a in A:
    if a in cnt:
        cnt[a] += 1
    else:
        cnt[a] = 1
    
    if cnt[a] >= 2:
        if a > l[0]:
            l[1] = l[0]
            l[0] = a
        elif cnt[a] >= 4 and a == l[0]:
            l[1] = a
        elif a < l[0] and a > l[1]:
            l[1] = a

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

Solution (Python):

from collections import Counter


def main():
    n = int(input())
    cnt = sorted(
        {
            k: v
            for k, v in Counter(map(int, input().rstrip().split())).items()
            if v >= 2
        }.items(),
        reverse=True,
    )
    if cnt == []:
        print(0)
    elif cnt[0][1] >= 4:
        print(cnt[0][0] ** 2)
    else:
        print(cnt[0][0] * cnt[1][0])


if __name__ == "__main__":
    main()

Solution (Python):

from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(
        {k: v for k, v in Counter(lst).items() if v >= 2}.items(), reverse=True
    )
    if cnt == []:
        print(0)
    elif cnt[0][1] >= 4:
        print(cnt[0][0] ** 2)
    else:
        print(cnt[0][0] * cnt[1][0])


if __name__ == "__main__":
    main()

Solution (Python):

from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(Counter(lst).most_common(), reverse=True)
    ans = []
    for i, j in cnt:
        if len(ans) >= 2:
            break
        if j >= 4:
            ans += [i] + [i]
        elif j >= 2:
            ans += [i]
    print(0 if ans == [] else ans[0] * ans[1])


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    if a in d.keys():
        d[a] += 1
    else:
        d[a] = 1

d = sorted(d.items(), reverse=True)
ans = []
for dd in d:
    if dd[1] > 1:
        if len(ans) == 0 and dd[1] > 3:
            print(dd[0] ** 2)
            exit()
        ans.append(dd[0])
    if len(ans) >= 2:
        break

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
x, y = 0, 0
flag = True
for i in A:
    if flag:
        if x == i:
            flag = False
        else:
            x = i
    else:
        if y == i:
            break
        else:
            y = i

print(x * y)

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

A.sort()

wh = [0,0]

tmp = 0
for i in A:
    if i == tmp:
        wh.append(i)
        tmp = 0
    else:
        tmp = i

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

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

C = {}

count = 0
H = 0
W = 0

res1=res2=res3=0

for i in A:
    C[i] = 0

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

for i in A:
    if C[i] >= 2:
        res1 = max(res1, i)

for i in A:
    if C[i] >= 2 and i != res1:
        res2 = max(res2, i)

for i in A:
    if C[i] >= 4:
        res3 = max(res3, i)


print(max(res1 * res2, res3 * res3))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    return


def B():
    return


def C():
    return


def D():
    n = I()
    a = LI()
    f = defaultdict(int)
    for i in a:
        f[i-1] += 1
        f[i] += 1
        f[i+1] += 1
    print(max(f.values()))
    return


def E():
    n = I()
    a = LI()
    f = defaultdict(int)
    f[0] = 4
    for i in a:
        f[i] += 1
    f = list(map(list, f.items()))
    f.sort(key = lambda x:-x[0])
    ans = 1
    k = 0
    for i,j in f:
        if j >= 4 and k == 0:
            print(i*i)
            quit()
        if j >= 2:
            k += 1
            ans *= i
        if k == 2:
            print(ans)
            quit()
    return


def F():
    return


def G():
    return


def H():
    return


def I_():
    return


def J():
    return


if __name__ == "__main__":
    E()

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

ans = 1
cnt = 2
w = 0
for Ai in sorted(map(int, input().split()), reverse=True):
  if w != Ai:
    w = Ai
  else:
    ans *= w
    cnt -= 1
    if cnt <= 0:
      break
    w = 0

print(ans if cnt <= 0 else 0)

Solution (Python):
from collections import Counter

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

c = Counter(a)

ans = 0
items = sorted([item for item in c.most_common() if item[1] >= 2], key=lambda x: x[0], reverse=True)
if len(items):
    x, count = items[0]
    y = 0
    if count >= 4:
        y = x
    else:
        if len(items) > 1:
            y, _ = items[1]
    ans = x * y

print(ans)

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

a_map = {}
for _a in a:
    if _a not in a_map:
        a_map[_a] = 1
    else:
        a_map[_a] += 1
keys =list(a_map.keys())[::]
for k in keys:
    if a_map[k] < 2:
        a_map.pop(k)

candidates = []
for k in a_map.keys():
    num = a_map[k]
    for n in range(num//2):
        candidates.append([k, 2])

if len(candidates) < 2:
    print(0)
else:
    candidates.sort(key=lambda x: x[0], reverse=True)
    print(candidates[0][0] * candidates[1][0])

Solution (Python):
from collections import Counter

input()
arr = Counter(list(map(int,input().split())))
ans = [0,0]
for a in arr:  
  if arr[a] > 1:
    ans.append(a)
  if arr[a] > 3:
    ans.append(a)
ans.sort()
print(ans[-1] * ans[-2])

Solution (Python):
from collections import Counter

n = int(input())

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

c = Counter(a)

can_use = [0, 0]
for i, x in c.items():
    if x >= 2:
        can_use.append(i)
    if x >= 4:
        can_use.append(i)

can_use.sort(reverse=True)

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

Solution (Python):
import collections

N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
c = collections.Counter(A)
b = sorted(c,reverse = True)
tmp  = []
for i in b:
    if c[i] >= 4:
        tmp += [i]
        break
    elif c[i] >= 2:
        tmp += [i]
    if len(tmp) == 2:
        break
    
if len(tmp) == 2:
    print(tmp[0]*tmp[1])
elif len(tmp) == 1:
    print(tmp[0]*tmp[0])
else:
    print(0)

Solution (Python):
import collections
n=int(input())
a_list=[int(i) for i in input().split()]
 
node1,node2=0,0
square=0
 
cnt = collections.Counter(a_list)
for k, v in sorted(cnt.items(), key=lambda x: -x[0]):
    if v>=4:
        square=max(square,k**2)
    
    if v>=2:
        if node1==0:
            node1=k
        else:
            node2=k
            break
print(max(node1*node2,square))

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

nums = {}
for a in As:
    if a in nums.keys():
        nums[a] += 1
    else:
        nums[a] = 1

hens = []
for n in nums.items():
    if n[1] >= 4:
        hens.append(n[0])
    if n[1] >= 2:
        hens.append(n[0])

if len(hens) < 2:
    print(0)
    exit()

hens.sort(reverse=True)
print(hens[0] * hens[1])

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

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

L.sort(reverse = True)
prev = -1
dic = {}
for n in L:
    if prev != n:
        cnt = 0
        prev = n
    elif prev == n:
        cnt += 1
        dic.setdefault(n, cnt)
        dic[n] += 1
if len(dic.keys()) < 1:
    print(0)
else:
    for k, v in sorted(dic.items(), reverse = True):
        if v >= 4:
            print(k * k)
            exit()
        else:
            break
    cand = list(dic.keys())
    cand.sort(reverse=True)
    print(cand[0] * cand[1])

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
li = [0]*2
cnt = 0
i = 0
prev = 0
A.sort(reverse=True)
while(i<N):
    if(prev == A[i]):
        if(li[0] != 0):
            li[1] = A[i]
            break
        else:
            li[0] = A[i]
            if(i+1>=N):
                break
            prev = A[i+1]
            i += 2
    else:
        prev = A[i]
        i += 1
print(li[0]*li[1])

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

node1,node2=0,0
square=0

cnt = collections.Counter(a_list)
for k, v in sorted(cnt.items(), key=lambda x: -x[0]):
    if v>=4:
        square=max(square,k**2)
    
    if v>=2:
        if node1==0:
            node1=k
        else:
            node2=k
            break
print(max(node1*node2,square))

Solution (Python):
import itertools
N = input()
l = list(map(int,input().split(" ")))
l.sort(reverse=True)
N = int(N)
i = 0
hen =[]

while True:
    if i >= N-1 or len(hen) == 2:
        break
    if l[i] == l[i+1]:
        hen.append(l[i])
        i+=1
    i+= 1

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

Solution (Python):
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for a in input().split():
    d[a] += 1
ls = [(k, d[k]) for k in d if d[k] >= 2]
if ls == []:
    print(0)
elif len(ls) == 1:
    print(0 if ls[0][1] < 4 else int(ls[0][0])**2)
else:
    ls.sort(key= lambda x: int(x[0]), reverse=True)
    m,n = ls[0],ls[1]
    print(int(m[0])*int(n[0]) if m[1] < 4 else int(m[0])**2)

Solution (Python):


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    """戦略
    長方形の条件は、縦の2辺の長さが等しくて、横の2辺の長さが等しい。
    自分と同じ数字のものを複数持つ数字を、大きいものから2つ取ってくれば、その2つの数字が長方形の2辺になる。   
    """

    A.sort(reverse=True)
    a = A[0]
    for i in range(1, len(A)):
        if a == A[i]:
            break
        a = A[i]

    if i >= len(A)-1:
        print(0)
        return

    b = A[i+1]
    for j in range(i+2, len(A)):
        if b == A[j]:
            break
        b = A[j]

    if j == len(A):
        print(0)
        return
    
    print(a*b)

if __name__ == "__main__":
    solve()

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter

def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)


"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n = ip()                                     

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








a.sort()
c = 1
cnum = a[0]
s = []
for i in range(1,n):
    if a[i] != cnum:
        if c > 1:
            s.append(cnum)
        if c > 3:
            s.append(cnum)
        c = 1
        cnum = a[i]
    else:
        c+=1
if c > 1:
    s.append(cnum)
if c > 3:
    s.append(cnum)
s.sort(reverse=True)
if len(s) < 2:
    print(0)
else:
    print(s[0]*s[1])

Solution (Python):
import collections as col

N = int(input())
A = list(map(int,input().split()))
L = col.Counter(A).most_common()

ans = [0] * 2
square = 0

for _, item in enumerate(L):
    if item[1] >= 4:
        square = max(square, item[0])
    if item[1] >= 2:
        if ans[0] < item[0]:
            ans[1] = ans[0]
            ans[0] = item[0]
        elif ans[1] < item[0]:
            ans[1] = item[0]

print(max(ans[0]*ans[1],square**2))

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l1={}
l2=[]
for i in l:
  if i in l1:
    if l1[i]%2==0:
      l1[i]+=1
    else:
      l2.append(i)
      l1[i]+=1
  else:
    l1[i]=1
if len(l2)<2:
  print(0)
else:
  m1=max(l2)
  del l2[l2.index(m1)]
  m2=max(l2)
  print(m1*m2)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l1={}
l2=[]
for i in l:
  if i in l1:
    if l1[i]%2==0:
      l1[i]+=1
    else:
      l2.append(i)
      l1[i]+=1
  else:
    l1[i]=1
if len(l2)<2:
  print(0)
else:
  l2=sorted(l2)
  print(l2[-1]*l2[-2])

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

A.sort(reverse=True)

cur = 0
E = []
while cur < N:
    a = A[cur]
    count = 0
    while cur < N and A[cur] == a:
        count += 1
        cur += 1

    if 2 <= count:
        E.append(a)
    if 4 <= count:
        E.append(a)

    if len(E) >= 2:
        print(E[0] * E[1])
        quit()

print(0)