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):
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
A = sorted(list(set(A)))[::-1]
flag = False
x = 0
for a in A:
	if flag == False:
		if C[a] >= 4:
			print(a ** 2)
			exit()
		elif C[a] >= 2:
			flag = True
			x = a
	elif flag == True and C[a] >= 2:
		print(a * x)
		exit()
else:
	print(0)

Solution (Python):
from collections import defaultdict

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

hasOne = defaultdict(bool)
E = []

for a in A:
  if not hasOne[a]:
    hasOne[a] = True
  else:
    E.append(a)
    hasOne[a] = False

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(reverse=True)
b = []
g = []
for i in range(1,n):
    if a[i-1] == a[i]:
        b.append(a[i])
if 4 <= n:
    for i in range(3,n):
        if a[i-3] == a[i]:
            g.append(a[i])
c = sorted(list(set(b)),reverse=True)
f = sorted(list(set(g)),reverse=True)
ans = 0
if len(f):
    ans = max(ans,f[0]*f[0])
if 2 <= len(c):
    ans = max(ans,c[0]*c[1])
print(ans)

Solution (Python):
import collections

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

rkey=list(set(a))
list.sort(rkey, reverse=True)
rvalue=[c[i] for i in rkey]

for i in range(len(rvalue)):
  if rvalue[i]>=4:
    print(rkey[i]**2)
    exit()
  elif rvalue[i]>=2:
    width=rkey[i]
    rvalue.pop(i)
    rkey.pop(i)
    break
else:
  print("0")
  exit()
for i in range(len(rvalue)):
  if rvalue[i]>=2:
    height=rkey[i]
    break
else:
  print("0")
  exit()
print(width*height)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=0
w=0
c=0
for i in range(n-1,0,-1):
    if a[i]==a[i-1] and l==0:
        l=a[i]
        a[i]=0
        a[i-1]=0
    elif a[i]==a[i-1] and w==0:
        w=a[i]
        print(l*w)
        break
if w==0:
    print(0)

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

x=0
y=0
i=0

while(i<n):
    if x==0 and a[n-1-i]==a[n-2-i]:
        x=a[n-1-i]
        i+=2
        continue
    if x>0 and y==0 and a[n-1-i]==a[n-2-i]:
        y=a[n-1-i]
        break
    i+=1
print(x*y)

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

a.sort()

side1=0
side2=0
num=0

for num in range(n-1):
    if a[num]==a[num+1]:
        side2=side1
        side1=a[num]
        a[num+1]=0

print(side1*side2)

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

from collections import Counter
c=Counter(a)

ans_1=0
ans_2=0
for key in c:
    if c[key]>=2 and key>=ans_1:
        ans_1,ans_2=key,ans_1
    elif c[key]>=2 and key>=ans_2:
        ans_2=key
    if c[key]>=4 and key>=ans_2:
        ans_2=key

print(ans_1*ans_2)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    dic = defaultdict(int)
    max_1 = 0
    max_2 = 0
    for ai in a:
        dic[ai] += 1
        if dic[ai] >= 2 and ai > max_1:
            max_2 = max_1
            max_1 = ai
        if dic[ai] >= 2 and max_1 > ai > max_2:
            max_2 = ai
    if dic[max_1] >= 4:
        print(max_1 ** 2)
    else:
        print(max_1 * max_2)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
before = 0
ans = 0
for num in a:
    if num == before:
        if ans == 0:
            ans = num
            before = 0
        else:
            print(ans * num)
            exit()
    else:
        before = num
print(0)

Solution (Python):
from collections import Counter

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

s = sorted(Counter(a).items(), reverse = True)


count = 0
ans = 0
for i, j in s:
        if count == 2:
            break
        if count == 1 and j >= 2:
            ans *= i
            count += 1
        if count == 0:
            if j >= 4:
                ans = i**2
                count += 2
            elif j >= 2:
                ans = i
                count += 1
print(ans)

Solution (Python):
from collections import defaultdict

N = int(input())
arr = list(map(int, input().split()))
a_set = sorted(set(arr), reverse=True)
a_dict = defaultdict(int)
for num in arr:
    a_dict[num] += 1
a, b = 0, 0
for num in a_set:
    if a_dict[num] > 3 and a == 0:
        a, b = num, num
        break
    elif a_dict[num] > 1 and a == 0:
        a = num
    elif a_dict[num] > 1:
        b = num
        break

print(a * b)

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *

from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]








n=l()[0]
A=l()
d={}
for i in range(n):
    if(A[i] not in d):
        d[A[i]]=0
    d[A[i]]+=1
s=list(d.keys())
s.sort(reverse=True)
x=-1
y=-1
for ks in s:
    if(x==-1 and d[ks]>=2):
        x=ks
        if(d[ks]>=4):
            y=ks
            break
    elif(x!=-1 and y==-1 and d[ks]>=2):
        y=ks
        break
y=max(0,y)
print(max(x*y,0))

Solution (Python):
from collections import defaultdict

n = int(input())
as_ = map(int, input().strip().split())

d = defaultdict(int)

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

rects = sorted([k for k, v in d.items() if v >= 2], reverse=True)
squares = sorted([k for k, v in d.items() if v >= 4], reverse=True)

max_rect = rects[0] * rects[1] if len(rects) >= 2 else 0
max_square = squares[0] ** 2 if len(squares) > 0 else 0

print(max(max_rect, max_square))

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]>1:x.append(a)
    if A[a]>3:x.append(a)
x.sort()
print(x[-1]*x[-2])

Solution (Python):
from collections import defaultdict


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

lengthNumberDict = defaultdict(int)
for a in A:
    lengthNumberDict[a] += 1

lengthNumberList = [a for a in list(lengthNumberDict.items()) if a[1] >= 2]
lengthNumberList = sorted(lengthNumberList, key=lambda x: x[0], reverse=True)
if len(lengthNumberList) == 0:
    print(0)
    quit()
if len(lengthNumberList) == 1 and lengthNumberList[0][1] <= 3:
    print(0)
    quit()

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

Solution (Python):
from collections import Counter

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

acnt = Counter(a)
num = [0,0]
for i in acnt:
    if acnt[i] >= 4:
        num.append(i)
    if acnt[i] >= 2:
        num.append(i)
num.sort()
print(num[-1] * num[-2])

Solution (Python):
from collections import Counter

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

c = {k: v for k, v in Counter(A).items() if v >= 2}

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

x = max(c)

if c[x] >= 4:
    print(x * x)
else:
    del c[x]
    y = max(c)
    print(x * y)

Solution (Python):
from collections import Counter
N = int(input())
Alist = list(map(int, input().split()))
Ac = Counter(Alist)
length_list = sorted(Ac.keys(), reverse=True)
can_use = []
for l in length_list:
    if Ac[l] >= 4:
        if can_use:
            print(can_use[0]*l)
            exit()
        else:
            print(l**2)
            exit()
    elif Ac[l] >= 2:
        if can_use:
            print(can_use[0]*l)
            exit()
        else:
            can_use.append(l)

print(0)

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

from collections import Counter

c = Counter(a)

c = [(length,cnt) for length,cnt in sorted(c.items(), key=lambda x:(-x[0], -x[1])) if cnt>=2]
if len(c)<2:
    print(0)
else:
    if c[0][1]>=4:
        print(c[0][0]*c[0][0])
    else:
        print(c[0][0]*c[1][0])

Solution (Python):
from collections import defaultdict
N = int(input())

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

edge_dic = defaultdict(int)
for n in range(N):
    edge_dic[al[n]] += 1
dic = sorted(edge_dic.items(), reverse=True)


yoko = 0
tate = 0
for v in dic:
    if yoko == 0:
        if v[1] >= 2:
            yoko = v[0]
            if v[1] >= 4:
                tate = v[0]
                break
    else:
        if v[1] >= 2:
            tate = v[0]
            break
print(yoko * tate)

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A).most_common()
CC = sorted(C,key=lambda x: -x[0])
AA = 0
BB = 0
for cc in CC:
    if AA == 0 and cc[1] >= 4:
        AA = cc[0]
        BB = cc[0]
        break
    if AA == 0 and cc[1] >= 2:
        AA = cc[0]
        continue
    if BB == 0 and cc[1] >= 2:
        BB = cc[0]
        break
print(AA*BB)

Solution (Python):

import numpy as np

N = int(input())
As = list(map(int, input().split()))
dic = {}
for a in As:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

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

first = -1
second = -1

for length, num in dic:
    if num >= 2 and first == -1:
        first = length
        num -= 2
    
    if num >= 2 and second == -1:
        second = length
        break

if first >= 0 and second >= 0:
    print(first * second)
else:
    print(0)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

from collections import Counter

c = Counter(a)

ma1 = 0
ma2 = 0

for k,v in c.items():
    if v < 2:
        continue

    if k > ma1:
        if v >= 4:
            ma2 = k
            ma1 = k
            continue
        else:
            ma2 = ma1
            ma1 = k
    elif k > ma2:
        ma2 = k

print(ma1*ma2)

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

seta = set(a)

counta = {a : 0 for a in seta}

for i in a:
    if i in seta:
        counta[i] += 1

lines = [i for i in counta.keys() if counta[i] >= 2]

if len(lines) >= 1:
    countsameValue = 0
    a = max(lines)
    secondmax = 0
    for l in lines:
       if(l != a):
           secondmax = max(secondmax, l)

    if (counta[a] > 3):
        print(a**2)
    else:
        print(a * secondmax)
else:
    print(0)

Solution (Python):
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

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

a = 0
b = 0
for c in C:
    if c[1] > 1 and a == 0 and b == 0:
        if c[1] > 3:
            a = b = c[0]
            break
        a = c[0]
    elif c[1] > 1 and a != 0 and b == 0:
        b = c[0]
        break

print(a * b)

Solution (Python):
from collections import Counter

N = int(input())
A = Counter(list(map(int,input().split())))
A = sorted(A.items(),reverse=True)
ans = list()
for key,value in A:
    if value >= 4:
        if len(ans) == 0:
            ans.append(key)
            ans.append(key)
            break
        else:
            ans.append(key)
            break
    elif value >= 2:
        if len(ans) == 0:
            ans.append(key)
        else:
            ans.append(key)
            break
if len(ans) <= 1:
    print(0)
else:
    print(ans[0]*ans[1])

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

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)
    ans=[]
    for key,value in c.items():
        if value>=4:
            ans.append(key)
            ans.append(key)
        elif value>=2:
            ans.append(key)
    ans.sort(reverse=True)
    if ans:
        print(ans[0]*ans[1])
    else:
        print(0)
resolve()

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

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)
    cl=list(c.items())
    cl.sort(key=lambda x:x[0],reverse=True)
    ans=[]
    for key,value in cl:
        if value>=4:
            if len(ans)==0:
                ans.append(key)
                ans.append(key)
                break
            elif len(ans)==1:
                ans.append(key)
                break
        elif value>=2:
            ans.append(key)
            if len(ans)==2:
                break
    if ans:
        print(ans[0]*ans[1])
    else:
        print(0)
resolve()

Solution (Python):
def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)
    cl=list(c.items())
    cl.sort(key=lambda x:x[0],reverse=True)
    ans=[]
    for key,value in cl:
        if value>=4:
            ans.append(key)
            ans.append(key)
            break
        elif value>=2:
            ans.append(key)
            if len(ans)==2:
                break
    if ans:
        print(ans[0]*ans[1])
    else:
        print(0)
resolve()

Solution (Python):
from collections import Counter
_, *lst = map(int, open(0).read().split())
c = Counter(lst).items()
stick2 = [i for i, j in c if j > 1]
stick4 = [0] + [i for i, j in c if j > 3]
max4 = max(stick4)
max4 *= max4
if len(stick2) > 1:
  stick2.sort()
  print(max(stick2[-1] * stick2[-2], max4))
else:
  print(max(0, max4))

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

import collections
C=collections.Counter(A).most_common()
D=[0]+[0]+[a for a,b in C if b>=2]+[a for a,b in C if b>=4]
D.sort()
print(D[-1]*D[-2])

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

Solution (Python):
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
m=[]
for key,value in A.items():
    if value>=2:
        m.append(key)
    if value>=4:
        m.append(key)
print(sorted(m)[-1]*sorted(m)[-2] if len(m)>=2 else 0)

Solution (Python):
from collections import deque
n=int(input())
a=list(map(int,input().split()))
b=sorted(a,reverse=True)
d=deque(b)
ans=0
tmp=0
flag1=False
flag2=False
while d:
    if d[0]==tmp and flag1==False:
        flag1=True
        d.popleft()
        h1=tmp
        tmp=0
    elif flag1 and d[0]==tmp:
        h2=tmp
        ans=h1*h2
        break
    elif d[0]!=tmp:
        tmp=d.popleft()
print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
from collections import Counter
A = Counter(A)
B = A.most_common()
B.sort(key = lambda x:x[0], reverse = 1)

fst_len = 0
snd_len = 0

for i,c in B:
  if c >1:
    if fst_len==0:
      fst_len = i
      if c >3:
        snd_len = i
    elif snd_len ==0:
      snd_len = i
    else:
      break


print(fst_len * snd_len)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
A = Counter(A)
A2 = [i for i,j in A.items() if j >= 2]
A2.sort(reverse = True)
A4 = [i for i,j in A.items() if j >= 4]
A4.sort(reverse = True)

H,W = 0,0

for i in range(len(A2)):
  if H == 0:
    H = A2[i]
  else:
    W = A2[i]
    break

for j in range(len(A4)):
  if A4[j] >= H:
    H,W = A4[j],A4[j]
  elif A4[j] >= W:
    W = A4[j]
  break

print(H*W)

Solution (Python):
n = int(input())
L = list(map(int, input().split()))
count = {}
for a in L:
    if a not in count:
        count[a] = 1
    else:
        count[a] += 1
leng = sorted(set(count), reverse=True)
flag = 0
for i in leng:
    if count[i] >= 4:
        if flag == 0:
            print(i * i)
            break
        else:
            print(l * i)
            break
    elif count[i] >= 2:
        if flag == 0:
            l = i
            flag = 1
        else:
            print(l * i)
            break
else:
    print(0)

Solution (Python):
from collections import defaultdict
import numpy as np

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

d = defaultdict(int)

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

values = np.array(list(d.values()))

if np.where(values >= 2)[0].shape[0] < 2:
    print(0)
else:
    over_4 = []
    over_2 = []

    for n, v in d.items():
        if v >= 4:
            over_4.append(n)
        if v >= 2:
            over_2.append(n)

    over_2 = sorted(over_2, reverse=True)

    ans_4 = 0
    if len(over_4) > 0:
        ans_4 = max(over_4)
    ans_2 = over_2[0] * over_2[1]

    print(max(ans_4**2, ans_2))

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

M = 0
N = 0
for x in c.items():
    if x[1] >= 4 and x[0] > M:
        M = x[0]
        N = x[0]
    elif x[1] >= 2 and x[0] > M:
        N = M
        M = x[0]
    elif x[1] >= 2 and x[0] > N:
        N = x[0]
 
print(M*N)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
import collections
c=collections.Counter(a)
values,counts=zip(*c.most_common())
lv=list(values)
lc=list(counts)
temp=[]
for i in range(0,len(lc)):
  if lc[i]>=4:
    temp.append(lv[i])
    temp.append(lv[i])    
  elif lc[i]>=2:
    temp.append(lv[i])
temp.sort(reverse=True)
if len(temp)>=2:
  ans=temp[0]*temp[1]
print(ans)

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

d = dict()
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

M = 0
N = 0
for x in d.items():
    if x[1] >= 4 and x[0] > M:
        M = x[0]
        N = x[0]
    elif x[1] >= 2 and x[0] > M:
        N = M
        M = x[0]
    elif x[1] >= 2 and x[0] > N:
        N = x[0]

print(M*N)

Solution (Python):
from collections import Counter
N = int(input())
Ac = Counter(list(map(int, input().split())))
sticks = sorted({k:v for k, v in Ac.items() if v >= 2}.items())[::-1]
if len(sticks) == 0:
    print(0)
else:
    if sticks[0][1] >= 4:
        print(sticks[0][0]**2)
    else:
        print(sticks[0][0]*sticks[1][0])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
tate, yoko = 0, 0
i = 0
while i < n:
    if i < n - 3 and a[i] == a[i + 1] == a[i + 2] == a[i + 3]:
        tate = max(tate, a[i])
        yoko = max(yoko, a[i])
        i += 3
    elif i < n - 2 and a[i] == a[i + 1] == a[i + 2]:
        if tate > yoko:
            yoko = max(yoko, a[i])
        else:
            tate = max(tate, a[i])
        i += 2
    elif i < n - 1 and a[i] == a[i + 1]:
        if tate > yoko:
            yoko = max(yoko, a[i])
        else:
            tate = max(tate, a[i])
        i += 1
    i += 1
print(tate * yoko)

Solution (Python):

import collections
import itertools as it
import math

 

n  = int(input())

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


c = collections.Counter(l)

cmc = c.most_common()

if cmc[0][1] == 1 or len(cmc) == 1:
    print(0)
else:
    cmc = sorted(cmc)[::-1]
    cmc = [(k, v) for k, v in cmc if v >= 2]
    print(cmc[0][0] * (cmc[0][0] if cmc[0][1] >= 4 else cmc[1][0]))

Solution (Python):

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

T = collections.Counter(A)
hen1 = 0 
hen2 = 0 
for h, c in sorted(T.items(), key=lambda x:x[0]):
    if c >= 4:
        hen1 = h
        hen2 = h
    elif c >= 2:
        if hen1 >= hen2:
            hen2 = h
        else:
            hen1 = h
print(hen1*hen2)

Solution (Python):
import collections
n=int(input())
A=list(map(int,input().split()))
a=collections.Counter(A)
firstnum=0
secondnum=0
firstl=0
secondl=0
values,counts=zip(*a.most_common())
for i,j in a.items():
  if i>=firstl and j>=2:
    secondnum=firstnum
    firstnum=j
    secondl=firstl
    firstl=i
  elif secondl<=i<firstl and j>=2:
    secondnum=j
    secondl=i
if firstnum>=4:
  print(firstl**2)
else:
  print(firstl*secondl)

Solution (Python):
from collections import defaultdict
n = int(input())
bars = list(map(int, input().split()))
bars.sort(reverse=True)
sides = defaultdict(int)
decided = []
ans = 0

for b in bars:
    sides[b] += 1
    if sides[b] == 2:
        decided.append(b)
        sides[b] -= 2
    if len(decided) == 2:
        ans = decided[0] * decided[1]
        break

print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
import collections
c = collections.Counter(l)
ans1=[]
ans2=[0]
for x in c.keys():
  if c[x]>1:
    ans1.append(x)
  if c[x]>3:
    ans2.append(x)
ans1.sort()
if len(ans1)<2:
  print(0)
else:
  print(max(ans1[-1]*ans1[-2],max(ans2)**2))

Solution (Python):



from collections import Counter

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

C = sorted(list(Counter(A).items()), key=lambda x: -x[0])

ans = 0
for k, v in C:
  if v >= 4:
    if ans == 0:
      print(k ** 2)
    else:
      print(ans * k)
    exit()
  else:
    if v >= 2:
      if ans == 0:
        ans = k
      else:
        print(ans * k)
        exit()

print(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x={}
edge=[0]*2
for i in a:
  if i in x:
    x[i]+=1
    if x[i]==2:
      edge.append(i)
      x[i]=0
  else:
    x[i]=1
edge.sort(reverse=True)
print(edge[0]*edge[1])

Solution (Python):
import sys
import os

def file_input():
    f = open('ARC081/input.txt', 'r')
    sys.stdin = f

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

    n=0
    m=0
    a=dict()

    for i in A:
        if not i in a:
            a[i]=True
        elif not a[i]:
            a[i]=True
        elif n<i or m<i:
            if n<m:
                n=i
            else:
                m=i
            a[i]=False

    if n==0 and m==0:
        print(0)
    else:
        print(str(n*m))


if __name__ == '__main__':
    main()

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
import collections
n = ii()
A = iil()
d = collections.Counter(A)
fst = 0
sec = 0
for k,v in d.items():
    if v == 1:
        continue
    elif v < 4:
        if k > fst:
            sec = fst
            fst = k
        elif k > sec:
            sec = k
    else:
        if k > fst:
            fst = k
            sec = k
        elif k > sec:
            sec = k
print(fst*sec)

Solution (Python):
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
cnt = sorted(cnt.items(), key = lambda x: x[0], reverse = True)


c = []
for i in range(len(cnt)):
    if cnt[i][1] == 2 or cnt[i][1] == 3:
        c.append(cnt[i][0])
    elif cnt[i][1] >= 4:
        c.append(cnt[i][0])
        c.append(cnt[i][0])

c = sorted(c, reverse = True)

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

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

L=[]
for num, v in D.items():
    if v>=4:
        L.append((num,4))
    elif v>=2:
        L.append((num, 2))

L=sorted(L, reverse=True)
if len(L)==0:
    print(0)
    exit()
elif len(L)==1 and L[0][1]==2:
    print(0)
    exit()
ans=1
for i,t in enumerate(L):
    num,v=t
    if i==0:
        if v==4:
            ans=num*num
            break
        else:
            ans*=num
    elif i==1:
        ans*=num
        break
print(ans)

Solution (Python):
from collections import Counter, deque, OrderedDict













import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


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

    ans=[0,0]
    for k,v in A.items():
        if v>=2:
            ans.append(k)
        if v>=4:
            ans.append(k)
    ans.sort()
    print(ans[-1]*ans[-2])


resolve()

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

a_set = list(set(a_list))
c = Counter(a_list)

if len(a_set) > n-2:
    print(0)
    exit()
else:
    a_list.sort(reverse=True)
    a_set.sort(reverse=True)
    candidate = []
    for i in a_set:
        cnt = c[i]
        
        if 2 <= cnt <= 3:
            candidate.append(i)
        elif cnt >= 4:
            candidate.append(i)
            candidate.append(i)
        if len(candidate) >= 2:
            print(candidate[0] * candidate[1])
            exit()

Solution (Python):
from collections import Counter

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

c = Counter(A)

hen = []

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


hen.sort(reverse=True)


ans = 0
finished = False
choosen = False

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

print(ans if finished else 0)

Solution (Python):
from collections import Counter

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

c = Counter(A)

hen = []

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


hen.sort(reverse=True)


ans = 0
finished = False
choosen = False

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

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

print(ans if finished else 0)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
b = ""
ans = []
for i in range(n):
  if b == "": b = a[i]
  elif b != a[i]: b = a[i]
  elif a[i] == b:
    ans.append(a[i])
    b = ""
    if len(ans) == 2: break
print(0 if len(ans) != 2 else ans[0] * ans[1])

Solution (Python):
from collections import Counter

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

a_c = sorted(Counter(a_input).items(),key=lambda x:x[0],reverse=True)

max_len=0
next_len=0
ans=0
for a in a_c:
    if a[1]<2:
        continue
    max_len = max(max_len,a[0])
    if a[1]>=4:
        ans = max(ans,a[0]**2)
    if max_len>a[0]:
        next_len = max(next_len,a[0])
print(max(ans,max_len*next_len))

Solution (Python):
from collections import Counter

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

Ac = sorted([i for i in c.keys() if c[i] >= 2], reverse=True)

if len(Ac) >= 2 and c[Ac[0]] >= 4:
    print(max(Ac[0] * Ac[1], Ac[0] * Ac[0]))
elif len(Ac) >= 2:
    print(Ac[0] * Ac[1])
elif len(Ac) == 1 and c[Ac[0]] >= 4:
    print(Ac[0] * Ac[0])
else:
    print(0)

Solution (Python):
import collections

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

c = collections.Counter(A)
max_1 = 0
max_2 = 0
for k, v in c.items():
    if v >= 2:
        if k > max_1:
            if v >= 4:
                max_1, max_2 = k, k
            else:
                max_1, max_2 = k, max_1
        elif k > max_2:
            max_2 = k

print(max_1*max_2)

Solution (Python):
n = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
    dic[A[i]] += 1
rec = False
ans = 0
nya = []
for k,v in dic.items():
    nya.append([k,v])
nya = sorted(nya,key = lambda x:x[0],reverse = True)

for k,v in nya:
    if v // 2 >= 1 and not rec:
        if v//4 >= 1:
            ans = k**2
            break
        else:
            po = k
            rec = True
    elif rec:
        if v // 2 >=1:
            ans = po * k
            break
print(ans)

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

N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
l = []

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

l.sort(reverse=True)

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

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

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

c = Counter(a)

temp = sorted(c.items())

h = 0
w = 0

while(len(temp)>0):
  k,v = temp.pop()
  if v>=4:
    print(k**2)
    exit()
  elif v>=2:
    h = k
    break
    
while(len(temp)>0):
  k,v = temp.pop()
  if v>=2:
    w = k
    break
    
print(h*w)

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

max1 = 0
max2 = 0
dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1
    
for key, value in dic.items():
    if value >= 4:
        max1 = max(max1, key)
        max2 = max(max2, key)
    elif value >= 2:
        if key > max1:
            max2 = max1
            max1 = key
        elif key > max2:
            max2 = key

print(max1*max2)

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

A.sort(reverse=True)

from collections import defaultdict
d = defaultdict(int)
ans = 0
t = 0
for i in A:
    d[i] +=1
    if d[i] == 4:
        print(i**2)
        exit()
    elif d[i]==2 and ans ==0:
        ans +=2
        t = i  
    elif d[i] == 2:
        ans +=2 
    if ans ==4:
        print(t*i)
        exit()

print(0)

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

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

from collections import Counter
c = Counter(a)

ans = 0

possible_e = []

for i in c.keys():
    if c[i] >= 4:
        ans = max(ans, i ** 2)
    if c[i] >= 2:
        possible_e.append(i)

possible_e.sort()

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

print(ans)

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