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



Sample input:
6
3 1 2 4 2 1


Sample output:
2

Submission status: Accepted

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

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

Submission status: Accepted

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

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

L1 = 0
L2 = 0

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

print(L1 * L2)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()

    for i in range(n):
        a = inlis[i]
        if a in indic:
            indic[a] += 1
        else:
            indic[a] = 1
    indic2 = sorted(indic.items(), key = lambda x:x[0], reverse=True)
    ans1 = 0

    for j in range(n):
        kazu = indic2[j][1]
        nagasa = indic2[j][0]
        if kazu >= 4 and ans1 == 0:
            print(nagasa ** 2)
            exit()
        elif kazu >= 2 and ans1 == 0:
            ans1 = nagasa
        elif kazu >= 2 and ans1 > 0:
            print(ans1 * nagasa)
            exit()
    print(0)
        



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
d = {}
for i in a:
  try:d[i] += 1
  except:d[i] = 1

ans = 0
t = 0
for i in d:
  if(d[i] >= 4 and ans == 0):print(i*i);exit()
  if(d[i] >= 2 and ans == 2):print(t*i);exit()
  if(d[i] >= 2 and ans == 0):t=i;ans=2
print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
bou2 = []
bou4 = []
for k, v in c.items():
    if v > 1:
        bou2.append(k)
    if v > 3:
        bou4.append(k)

bou2.sort(reverse=True)
bou4.sort(reverse=True)
ans = 0
if len(bou2) >= 2:
    ans = bou2[0]*bou2[1]
if len(bou4) != 0:
    ans = max(ans, bou4[0]*bou4[0])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

L = []

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

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

Submission status: Accepted

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
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

# map(int, input().split())

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)

Submission status: Accepted

Solution code:
'''
　 ∧_,,∧    究極奥義「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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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