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

Solution (Python):
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)

Solution (Python):
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)
    exit()
  elif v >= 2:
    ans.append(k)
    t += 1
  if t == 2:
    print(ans[0]*ans[1])
    exit()
print(0)

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

cand = []
for k, v in A.items():
    if v >= 2:
        cand.append((k, v))
cand = sorted(cand, reverse=True)

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

Solution (Python):
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=1
cnt=0
i=0
while i<n-1 and cnt<2:
    if a[i]==a[i+1]:
        ans*=a[i]
        i+=2
        cnt+=1
    else:
        i+=1
if cnt==2:
    print(ans)
else:
    print(0)

Solution (Python):
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")
  sys.exit()

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)

Solution (Python):
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A: d[a] += 1
    cand = []
    for key in d:
        for _ in range(d[key] // 2): cand.append(key)
    cand.sort(reverse=True)
    if len(cand) < 2:
        print(0)
        return
    print(cand[0] * cand[1])
    
    


if __name__ == "__main__":
    main()

Solution (Python):
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)

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

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

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

Solution (Python):
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)

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

store = 0
big = 0

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

Solution (Python):
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)
        exit()
    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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
import sys

n,*a=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])
    sys.exit()
print(0)

Solution (Python):
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))

Solution (Python):
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 = 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


if __name__ == '__main__':
    main()

Solution (Python):
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 = map(int, read().split())

    ans = 0
    counter = Counter(A)
    vec1 = [k for k, v in counter.items() if v >= 2]
    vec2 = [k for k, v in 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


if __name__ == '__main__':
    main()

Solution (Python):
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(count.keys(),reverse=True):
  if count[c] >= 4:
    if edge1 == 0:
      print(c*c)
      sys.exit()
    else:
      print(edge1*c)
      sys.exit()
  elif count[c] >= 2:
    if edge1 == 0:
      edge1 = c
    else:
      print(edge1*c)
      sys.exit()
else:
  print(0)

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

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

Solution (Python):
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)

Solution (Python):
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 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])

if __name__ == '__main__':
    main()

Solution (Python):
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))

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

ans = 0
counter = Counter(A)
keys = sorted(counter.keys(), reverse=True)
flag = False
for k in keys:
    if ans == 0 and counter[k] >= 4:
        ans = k*k
        flag = True
        break
    elif ans == 0 and counter[k] >= 2:
        ans = k
    elif ans != k and counter[k] >= 2:
        ans = ans * k
        flag = True
        break
if flag:
    print(ans)
else:
    print(0)

Solution (Python):
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)

Solution (Python):
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])))
    sys.exit()
print(0)

Solution (Python):
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])

Solution (Python):
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])
        quit()
      j += 1
    if count == 4:
      print(now * now)
      quit()
      
  else:
    now = A[i]
    count = 1

print(0)

Solution (Python):
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])

Solution (Python):
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)
            exit(0)
        else:
            print(i[0]*i[0])
            exit(0)
    elif i[1]>1:
        if x:
            print(i[0]*x)
            exit(0)
        else:
            x=i[0]
print(0)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
from collections import Counter as C

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

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

Solution (Python):
from collections import Counter as C

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

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

Solution (Python):
from collections import Counter as C

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

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

Solution (Python):
from collections import Counter as C

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

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

Solution (Python):
from collections import Counter as C

_ = input()

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

Solution (Python):
from collections import Counter as C

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

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

Solution (Python):
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)

Solution (Python):
from collections import Counter as C

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

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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    data = A[i]
    if data in dic:  dic[data] += 1
    else:  dic[data] = 1
temp1, temp2 = 0, 0
for i in sorted(dic.keys())[::-1]:
    if dic[i] >= 2:
        if temp1 == 0:  
            temp1 = i
            if dic[i] >= 4:
                temp2 = i
                break
        else:
            temp2 = i
            break
ans = temp1 * temp2
print(ans)

Solution (Python):
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])
        exit()
    else:
        l = a[i][0]
        count += 1

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

print(0)

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

from collections import Counter

A_=Counter(A)
A_.most_common()

Rectangle = [_ for _ in A_.keys() if A_[_] >1]
sq_list=[_ for _ in A_.keys() if A_[_] >= 4]

Rectangle.sort()
sq_list.sort()

ans=0

if len(Rectangle) >= 2:
    a_1 = Rectangle[-1]
    a_2 = Rectangle[-2]
    ans = a_1*a_2
    
if len(sq_list) >= 1:
    s_1 = sq_list[-1]
    if ans < s_1**2:
        ans=s_1**2

print(ans)

Solution (Python):
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])

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
def main():
    n = int(input())
    As = sorted(list(map(int, input().split())))
    edeges = []
    i = 0
    while i < n-1:
        if As[i] == As[i+1]:
            edeges.append(As[i])
            i += 1
        i += 1
    if len(edeges) < 2:
        ans = 0
    else:
        ans = edeges[-1] * edeges[-2]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
b = 0
bi = 0
c = 0
for i in range(n - 1):
    if a[i] == a[i + 1]:
        b = a[i]
        bi = i + 1
        break
if bi != 0:
    for i in range(bi + 1, n - 1):
        if a[i] == a[i + 1]:
            c = a[i]
            break
print(b * c)

Solution (Python):
N = int(input())
A = sorted(map(int, input().split()))[::-1]
for i in range(N-3):
  if A[i]==A[i+1]==A[i+2]==A[i+3]:
    print(A[i]**2)
    exit()
  elif A[i]==A[i+1]:
    for j in range(i+2, N):
      if A[j]==A[j+1]:
        print(A[i]*A[j])
        exit()
    else:
      print(0)
      exit()
else:
  print(0)

Solution (Python):
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])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
S = sorted(A, reverse=True)
w, h = 0, 0

cnt = 0
tmp = S[0]
for i in range(N):
  if S[i] == tmp:
    cnt += 1
    if cnt == 2:
      if w == 0:
        w = tmp
        cnt = 0
      else:
        h = tmp
        break
  else:
    cnt = 1
    tmp = S[i]
        
ans = w * h
print(ans)

Solution (Python):
n = int(input())
a_list = sorted([int(x) for x in input().split()], reverse=True)
ans = 0
temp = 0
count = 0
e = None
for i in range(n):
    if a_list[i] == temp:
        count += 1
        if count == 2:
            if e is None:
                e = temp
                count -= 2
            else:
                ans = e * temp
                break
    else:
        temp = a_list[i]
        count = 1
print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    d[a] += 1
temp_list = sorted([(k, v) for k, v in d.items() if v >= 2], reverse=True)
if len(temp_list) >= 2:
    print(temp_list[0][0] ** 2 if temp_list[0][1] >= 4 else temp_list[0][0] * temp_list[1][0])
else:
    print(0)

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

A.sort()

edge = [0] * 2
for i in range(2):
    while True:
        l = len(A)
        if len(A) < 2:
            print(0)
            exit(0)

        if A[l-2] == A[l-1]:
            edge[i] = A.pop()
            A.pop()
            break

        A.pop()

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

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

count = Counter(a)
ans = [0]*2
t = 0
for i in sorted(count.items(), reverse=True):
  if i[1] >= 4:
    if t == 0:
      ans[0],ans[1] = i[0],i[0]
      t = 2
    elif t == 1:
      ans[t] = i[0]
      t += 1
  elif i[1] >= 2:
    ans[t] = i[0]
    t += 1
  if t == 2: break
print(ans[0]*ans[1])

Solution (Python):
import sys
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
C = sorted(C.items(), reverse=True)
a, b = 0, 0
for k, v in C:
    if a == 0 and v >= 4:
        print(k * k)
        sys.exit()
    if v >= 2:
        if a == 0:
            a = k
        elif b == 0:
            print(a * k)
            sys.exit()
print(0)

Solution (Python):
from collections import Counter

n = int(input())

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

a = Counter(lis)

slis = sorted(set(lis))

t1 = 0
t2 = 0

for k, v in a.items():
    if v >=2 and k > t1:
        t2 = t1
        t1 = k

if a[t1] >= 4:
    print(t1*t1)
    exit()

print(t1*t2)

Solution (Python):
n=int(input())
lst=sorted(map(int,input().split()),reverse=True)
memory=-1
ans1=-1
for i in range(n):
    if lst[i]==memory:
        if ans1==-1:
            ans1=memory
            memory=-1
        else:
            ans2=memory
            print(ans1*ans2)
            exit()
    else:
        memory=lst[i]

print(0)

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

Solution (Python):
import sys
sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    A = list(mi())
    dic = {}
    l = []
    for a in A:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1

    for k, v in dic.items():
        if v >= 2:
            l.append(k)
        if v >= 4:
            l.append(k)
        
    l.sort(reverse=True)

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


if __name__ == '__main__':
    main()

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

c = Counter(a)

e = []
for k, v in c.items():
    if v > 3:
        e.append(k)
        e.append(k)
    elif v > 1:
        e.append(k)
e.sort(reverse=True)

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

Solution (Python):




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

a.sort()

h_long = 0
h_short = 0
i = n - 1


while i > 0:
    if a[i-1] == a[i]:
        if h_long == 0:
            h_long = a[i]
            i = i - 1
        else:
            h_short = a[i]
            break
    i = i - 1

ans = h_short * h_long


print(ans)

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

A_collection = collections.Counter(A)
bars = []
for key in A_collection.keys():
    if A_collection[key] > 1:
        bars.append(key)

ans = 0
bars.sort(reverse = 1)
if len(bars) > 1:
    ans = bars[0] * bars[1]
    if A_collection[bars[0]] > 3:
        ans = bars[0] ** 2
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
lst = list(map(int, input().split()))
mclst = Counter(lst).most_common()
sqlst = []
rclst = []
for tpl in mclst:
  if tpl[1] >= 2:
    rclst.append(tpl[0])
  if tpl[1] >= 4:
    sqlst.append(tpl[0])
sqmax, rcmax = 0, 0
if len(sqlst) >= 1:
  sqmax = max(sqlst) ** 2
if len(rclst) >= 2:
  rclst.sort(reverse=True)
  rcmax = rclst[0] * rclst[1]
print(max(sqmax, rcmax))

Solution (Python):
from collections import Counter

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

c = Counter(a)
d = dict(sorted(c.items(), key=lambda x:x[0], reverse=True))

x = 0
y = 0
for k, v in d.items():
   if v >= 4:
      if x == 0:
         x = k
         y = k
         break
      elif y == 0:
         y = k
         break
   if v >= 2:
      if x == 0:
         x = k
      elif y == 0:
         y = k
         break

ans = x * y
print(ans)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
A.sort(reverse=True)
list = []
start = 0
while start < N-1: 
    if A[start] == A[start+1]:
        list.append(A[start])
        start += 2
    else:
        if start == N-2:
            break
        start += 1
if len(list) >= 2:
    print(list[0]*list[1])
else:
    print(0)

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

count = Counter(a)
t = 4
s = []
for i in sorted(count.items(), key=lambda x: x[0], reverse=True):
  if i[1] >= 4 and t == 4:
    print(i[0]**2)
    exit()
  if i[1] >= 2 and t != 0:
    t -= 2
    s.append(i[0])
  elif t == 0: break
    
if len(s) != 0: print(s[0]*s[1])
else: print(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split(' ')))
x=0
y=0
a.sort()
a.reverse()
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        x=a[i]
        p=i+1
        break
if x!=0:
    for i in range((p+1),len(a)-1):
        if a[i]==a[i+1]:
            y=a[i]
            break
print(x*y)

Solution (Python):
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
d=defaultdict(int)
for i in range(n):
    d[a[i]]+=1

for i,j in d.items():
    if j>=2:
        b.append(i)
    if j>=4:
        c.append(i)

if len(b)<2 and len(c)<1:
    print(0)
elif len(c)==1 and len(b)<2:
    print(c[0]**2)
else:
    b.sort(reverse=True)
    rec=b[0]*b[1]
    if len(c)>=1:
        c.sort(reverse=True)
        cube=c[0]**2
    else:
        cube=0
    print(max(rec,cube))

Solution (Python):
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)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
A.append(0)
i=0
ans=1
d=0
while i<N:
  b=A[i]
  c=0
  while i<N and b==A[i]:
    i+=1
    c+=1
  if 2<=c<=3:
    d+=1
    ans*=b
    if d==2:
      break
  elif 4<=c:
    if d==0:
      ans*=b*b
      d=2
      break
    else:
      ans*=b
      d+=1
      break
if d!=2:
  print(0)
else:
  print(ans)

Solution (Python):
from collections import Counter
N = int(input())
*A, = map(int, input().split())
c = Counter(A)
ac = [(k, v) for k, v in c.items()]
ac.sort()
ac.reverse()

rest = 4
ans = 0
for k, v in ac:
    if v >= 4 and rest == 4:
        ans = k*k
        break
    elif v >= 2:
        rest -= 2
        if ans == 0:
            ans = -k
        else:
            ans *= -k
            break
print(max(ans, 0))

Solution (Python):
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)

Solution (Python):
from collections import Counter
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

c = Counter(l)
sides = sorted([[x, y] for x, y in c.items() if y >= 2])
ans = 0

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

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

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

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