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: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import Counter
AA = Counter(A)
B = []
C = []
for k,v in AA.items():
    if v>=2:
        B.append(k)
    if v>=4:
        C.append(k)
B.sort(reverse=True)
C.sort(reverse=True)
if len(B)<=1 and len(C)==0:
    print(0)
else:
    if len(B)<=1:
        print(C[0]*C[0])
    else:
        print(max(B[0]*B[1],C[0]*C[0]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
lis=[]
dic={}
for i in range(N):
  try:
    dic[A[N-i-1]]=dic[A[N-i-1]]+1
    if dic[A[N-i-1]]%2==0:
      lis+=[A[N-i-1]]
  except:
    dict.setdefault(A[N-i-1],1)
    if len(lis)==2:
      break
if len(lis)<2:print(0)
else:print(lis[0]*lis[1])

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
lis=[]
dic={}
for i in range(N):
	try:
      dic[A[N-i-1]]=dic[A[N-i-1]]+1
      if dic[A[N-i-1]]%2==0:
        lis+=[A[N-i-1]]
    except:
      dict.setdefault(A[N-i-1],1)
    if len(lis)==2:
      break
if len(lis)<2:print(0)
else:print(lis[0]*lis[1])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
l = map(int, input().split())
c = collections.Counter(l)
c = sorted(c.items(), key=lambda c:c[0], reverse=True)

ans = 1
cnt = 0

for key,val in c:
  if cnt=0 and val>=4:
    ans=key**2
    break
  if val>=2:
    ans*=key
    cnt+=1
  if cnt == 2:
    break
else:
  ans = 0
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
import collections
c = collections.Counter(l)
ans1=[]
ans2=[]
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))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

    l = Counter(a)
    tw = []
    fo = []
    for i,j in l.items():
        if j >= 2:
            tw.append(i)
        if j >= 4:
            fo.append(i)

    if len(tw) >= 2 or len(fo) >= 1:
        tw.sort()
        fo.sort()
        return max(tw[-1]*tw[-2], fo[-1]**2)
    else:
        return 0
    

print(solve())

Submission status: Runtime Error

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

    l = Counter(a)
    tw = []
    fo = []
    for i,j in l.items():
        if j >= 2:
            tw.append(i)
        if j >= 4:
            fo.append(i)

    if len(tw) >= 2 or fo:
        tw.sort()
        return max(tw[-1]*tw[-2], fo[-1]**2)
    else:
        return 0
    

print(solve())

Submission status: Runtime Error

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
ar = sorted(ar,reverse=True)
A = 0
B = 0
j = 0
while True:
    if A != 0 and B != 0:
        break
    if j == a - 1:
        break
    if ar[j] == ar[j+1] and A == 0:
        A = ar[j]
        j += 1
    elif ar[j] == ar[j+1] and A != 0:
        B = ar[j]
        j += 1
    j += 1
    print(ar[j])
print(A * B)

Submission status: Runtime Error

Solution code:
import collections

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

f = []
t = []
for i in a:
    if a[i] >= 4:
        f.append(i)
    if a[i] >= 2:
        t.append(i)
fa, ta = 0, 0
f.sort()
t.sort()
if len(f) >= 1:
    fa = f[-1]**2
if len(t) >= 2:
    ta = max(t[-1]*t[-2], t[-1]*f[-1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

c = Counter(A)


ans = []
for i, j in c.items():
    if j >= 2:
        ans.append(i)

ans.sort()    

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

    
c = Counter(A)


ans = []
for i, j in c.items():
    if j >= 2:
        ans.append[i]

ans.sort()    
print(ans[-1]*ans[-2])

Submission status: Runtime Error

Solution code:
from collections import Counter

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

    
c = Counter(l)


ans = []
for i, j in c.items():
    if i >= 2:
        ans.append[j]

ans.sort()    
print(ans[-1]*ans[-2])

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
p = list(map(int,input().split()))
cnt = collections.Counter(p)

maxs = []
for k, v in cnt.items():
  if v > 1:
    maxs.append(k)
    
if len(maxs) > 1:
  maxs.sort()
  if len(maxs[-1]) > 3:
    print(maxs[-1] ** 2)
  else:
    print(maxs[-1] * maxs[-2])

else:
  print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter


N = int(input())
c = Counter(map(int, input().split()))
usables = sorted([(k, v) for k, v in c.items() if v >= 2])
if len(usables) <= 1:
    print(0)
else:
    if usables[-1][2] >= 4:
        print(usables[-1][1] ** 2)
    else:
        print(usables[-1][1] * usables[-2][1])

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,(input().split())))
from collections import Counter
c = Counter(a)
L = []
LL = []
for k in c.keys():
    if c[k] >= 2:
        L.append(k)
    if c[k] >= 4:
        LL.append(k)
if LL:
    M = max(LL)**2

if len(L) < 2:
    print(0)
else:
    L.sort(reverse=True)
    print(max(L[0]*L[1],M))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = max(a)
check = [0]*m
check2 = [0]*2
s = -1
for i in range(n):
    check[a[i]-1] +=1
for i in range(m-1,-1,-1):
    if check[i] > 1 :
        if check2[0] == 0:
            check2[0] = i+1
        elif check2[1] == 0:
            check2[1] = i+1
    if check[i] >= 4:
        s = i+1

if check2[0] == 0:
    print(0)
    exit(0)
if check2[1] == 0:
    if s:
        print(s*s)
        exit(0)
    else:
        print(0)
        exit(0)
if s:
    print(max(check2[0]*check2[1],s*s))
else:
    print(check2[0] * check2[1])

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
a = list(map(int,input().split()))
m = max(a)
check = [0]*m
check2 = [0]*2
s = -1
for i in range(n):
    check[a[i]-1] +=1
for i in range(m-1,-1,-1):
    if check[i] > 1 :
        if check2[0] == 0:
            check2[0] = i+1
        elif check2[1] == 0:
            check2[1] = i+1
    if check[i] >= 4:
        s = i+1

if check2[0] == 0:
    print(0)
    exit(0)
if check2[1] == 0:
    if s:
        print(s*s)
        exit(0)
    else:
        print(0)
        exit(0)
if s:
    print(max(check2[0]*check2[1],s*s))
else:
    print(check2[0] * check2[1])

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
a = list(map(int,input().split()))
m = max(a)
b = deque([])
check = [0]*m
s = -1
for i in range(n):
    check[a[i]-1] +=1
for i in range(m):
    if check[i] > 1:
        b.append(i+1)
    if check[i] >= 4:
        s = i
B = sorted(b)[::-1]

if len(B) == 0:
    print(0)
    exit(0)
if len(B) == 1:
    if s:
        print((s+1)*(s+1))
        exit(0)
    else:
        print(0)
        exit(0)
if s:
    print(max(B[0]*B[1],(s+1)*(s+1)))
else:
    print(B[0] * B[1])

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
a = list(map(int,input().split()))
m = max(a)
b = deque([])
check = [0]*m
s = -1
for i in range(n):
    check[a[i]-1] +=1
for i in range(m):
    if check[i] > 1:
        b.append(i+1)
    if check[i] >= 4:
        s = i
B = sorted(b)[::-1]
if len(B) ==0:
    print(0)
    exit(0)
if len(B) == 1:
    if s:
        print((s+1)*(s+1))
        exit(0)
    else:
        print(0)
        exit(0)
if s:
    print(max(B[0]*B[1],(s+1)*(s+1)))
else:

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

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
a = list(map(int,input().split()))
m = max(a)
b = deque([])
check = [0]*m
s = -1
for i in range(n):
    check[a[i]-1] +=1
for i in range(m):
    if check[i] > 1:
        b.append(i+1)
    if check[i] >= 4:
        s = i
B = sorted(b)[::-1]
if len(B) ==0:
    print(0)
    exit(0)
if s:
    print(max(B[0]*B[1],(s+1)*(s+1)))
else:
    print(B[0] * B[1])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=-1
ans=[]
for ai in a:
  if len(ans)==2:
    break
  if b==ai:
    ans.append(ai)
    b=-1
  else:
    b=ai
print(ans[0]*ans[1])

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(list(input().split()),np.int64)
u,counters = np.unique(A,return_counts=True)
if counters[-1] >= 4:
    print(u[-1] ** 2)
elif len(u[counters >= 2]) >= 2:
    print(u[counters >= 2][-1] * u[counters >= 2][-2])
else:
    print(0)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(list(input().split()),np.int64)
u,counters = np.unique(A,return_counts=True)
if counters[-1] >= 4:
    print(u[-1] * 2)
elif len(u[counters >= 2]) >= 2:
    print(u[counters >= 2][-1] * u[counters >= 2][-2])
else:
    print(0)

Submission status: Runtime Error

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

ans = []
for k in sorted(Ac.keys())[::-1]:
  if len(ans) == 2:
    break
  if Ac[k] >=4:
    if ans:
      ans.append(k)
    else:
      ans.append(k)
      ans.append(k)
  elif Ac[k] >= 2:
    ans.append(k)
print(ans[0]*ans[1])

Submission status: Runtime Error

Solution code:
def resolve():

    N=int(input())
    A=sorted(list(map(int,input().split())),reverse=True)
    temp=-1
    maxans=0
    AA=Counter(A)
    for (i,j) in AA.items():
        if j>=4:
            maxans=max(i**2,maxans)
        if j>=2:
            if temp>=0:
                maxans=max(maxans,temp*i)
            temp=max(i,temp)
    print(maxans)




resolve()

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
b = Counter(a)
c = sorted(list(set(a)), reverse=True)
ans = []
for i in c:
    if b[i] >= 2:
        ans.append(i)
    if b[i] >= 4:
        ans.append(i)
    if len(ans) >= 2:
        break
debug(ans)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
l1 = [0,0]
from collections import Counter
c = Counter(l)
for i in c:
  while l[i]>=2 and len(l1)<4:
    l1.append(l[i])
print(l1[-1]*l1[-2])

Submission status: Runtime Error

Solution code:

def resolve():

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

    AA=Counter(A).most_common()

    ls=[]
    for i in range(len(AA)):
        if AA[i][1]>=2:
            ls.append(AA[i][0])

    ls.sort()
    try:
        print(ls[-1]*ls[-2])
    except:
        print(0)



resolve()

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Aset = list(set(A))
Aset.sort(reverse=True)
a, b = 0, 0
L = []
cnt = 1
for i in range(1, N):
    if A[i] == A[i-1]:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
if A[-1] == A[-2]:
    L.append(cnt)
idx = 0
for i in range(len(Aset)):
    if L[i] >= 4:
        a, b = Aset[i], Aset[i]
        break
    elif L[i] >= 2:
        a = Aset[i]
        idx = i + 1
        break
if b <= 0:
    for i in range(idx, len(Aset)):
        if L[i] >= 2:
            b = Aset[i]
            break
print(a * b)

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
# cnts = Counter(A)
cnts = {}
for i in range(N):
    if A[i] not in cnts.keys():
        cnts[A[i]] = 1
    else:
        cnts[A[i]] += 1
d = {}
for k in cnts.keys():
    if cnts[k] >= 2:
        d[k] = cnts[k] // 2 
ids = list(d.keys())[::-1]
if d[ids[0]] >= 2:
    ans = ids[0] ** 2
elif len(ids) >= 2:
    ans = ids[0] * ids[1]
else:
    ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
A=list(map(int,input().split()))
c=dict(Counter(A))
#print(c)
e=[]
f=[]

for i in c:
  if c[i]>1:
    e.append(i)
  if c[i]>=4:
    f.append(i)

e.sort(reverse=True)
f.sort(reverse=True)
if f[0]>=e[0]:
  print(f[0]**2)
else:
  if len(e)>=2:
    print(e[0]*e[1])
  else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
lens = list(map(int,input().split()))
items = set[lens]
items = list(items).sort(reverse = True)
cnt = 0
for j in items:
  if j >= 4 and cnt == 0:
    print(j**2)
    break
  elif j >= 2 and cnt == 0:
    cnt = j
  elif j >= 2 and cnt != 0:
    print(cnt * j)
    break
else:
  print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
lens = list(map(int,input().split()))

lens.sort(reverse = True)
cnt = 0
for i in lens:
  if l.count(i) >= 4 and cnt != 0:
    print(i*2)
    break
  elif l.count(i) >= 2 and cnt == 0:
    cnt = i
  elif l.count(i) >= 2 and cnt != 0:
    print(cnt * i)
    break
else:
  print(0)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
A = sorted(list(map(int, input().split())))
a = collections.Counter(A)
ans = 0
y = 0
for i in a.keys():
    if a[i] >= 2:
        x = y*i
        y = i
    if a[i] >= 4:
        z = i**2
    ans = max(ans, x, z)
print(ans)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
A=sorted(list(map(int, input().split())))
a = collections.Counter(A)
ans = 0
y = 0
for i in a.keys():
    if a[i] >= 2:
        x = y*i
        y = i
    if a[i] >= 4:
        z = i**2
    ans = max(ans, x, z)
print(ans)

Submission status: Runtime Error

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

x = [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])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a = Counter(a).most_common()
b = []
for i,j in a:
    if j >=4:
        b.append(i)
        b.append(i)
    elif j >= 2:
        b.append(i)
b.sort()
if len(b)>=2:
    print(b[-1]*b[-2])
else:
    print(0)
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a = Counter(a)
b = []
for i,j in a:
    if j >=4:
        b.append(i)
        b.append(i)
    elif j >= 2:
        b.append(i)
b.sort()
if len(b)>=2:
    print(b[-1]*b[-2])
else:
    print(0)
提出情報

Submission status: Runtime Error

Solution code:
import string
char=string.ascii_lowercase
numbering={}
for i in range(26):
    numbering[char[i]]=i
A=input()
n=len(A)
next=[[n+1]*26 for i in range(n+1)]
next[n][numbering[A[n-1]]]=n
for i in range(n-1,-1,-1):
    for j in range(26):
        next[i][j]=next[i+1][j]
    next[i][numbering[A[i]]]=i

dp=["z"*n for i in range(n+1)]
dp[n]="a"
for i in range(n-1,-1,-1):
    m=0
    length=n
    for c in range(26):
        if next[i][c]>n and char[c]<dp[i]:
            dp[i]=char[c]
            break
        else:
            if length>len(dp[next[i][c]+1])+1:
                length=len(dp[next[i][c]+1])+1
                m=c
    try:
        if dp[i]>char[m]+dp[next[i][m]+1] and len(dp[i])>len(dp[next[i][m]+1])+1:
            dp[i]=char[m]+dp[next[i][m]+1]
    except IndexError:
        pass
print(dp[0])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
import collections
c =collections.Counter(a)
ln = [i[0] for i in c.items() if i[1] >= 2]
ln.sort(reverse = True)

if c[ln[0]] >= 4:
    print(ln[0] ** 2)
elif len(ln) <= 1:
    print(0)
else:
    print(ln[0] * ln[1])

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

from collections import defaultdict

def main():
	d=defaultdict(int)
	
	n=int(input())
	A=list(map(int,input().split()))
	for x in A:
		d[x]+=1
	
	li=[]
	li2=[]
	for k,v in d.items():
		if v>=2:
			li.append(k)
		if v>=4:
			li2.append(k)

	li.sort(reverse=True)
	li2.sort(reverse=True)
	
	if len(li)<=1 and len(li2)==0:
		print(0)
	elif len(li)==1:
		print(li2[0]**2)
	else:
		print(max(li[0]*li[1],li2[0]**2))
	

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = OrderedDict()

    for aa in a:
        if a.count(aa) >= 2:
            if aa not in sidelist:
                sidelist[aa] = 1
            else:
                sidelist[aa] += 1

    side_a = 0
    side_b = 0

    for s in sidelist:
        if sidelist[s] >= 4 and s > side_a:
            side_a = s
            side_b = s
        elif sidelist[s] >= 2:
            if side_a == 0:
                side_a = s
            elif side_b == 0:
                side_b = s
            elif s > side_a:
                side_b = side_a
                side_a = s
            elif s > side_b:
                side_b = s

    print(side_a*side_b)

Submission status: Runtime Error

Solution code:
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


n = ni()
a = na()

a.sort(reverse=True)
l = list()
for key, gr in groupby(a):
    if len(l) == 2:
        print(l[0] * l[1])
        quit()
    num = len(list(gr))
    if num >= 2:
        l.append(key)
    if num >= 4:
        l.apend(key)
print(0)

Submission status: Runtime Error

Solution code:
import sys

def solve():
    N = int(input())
    A = [int(a) for a in input().split()]
    lengthD = dict()
    for a in A:
        if a in lengthD: lengthD[a] += 1
        else: lengthD[a] = 1
    moreThanTwo = []
    count = 0
    for key in lengthD:
        if lengthD[key] > 1: 
            moreThanTwo.append(key)
            count += 1
    ans = 0
    moreThanTwo.sort()
    if lengthD[moreThanTwo[-1]] > 3: ans = moreThanTwo[-1] ** 2
    if count < 2: print(ans)
    else:
        ans = max(ans, moreThanTwo[-1] * moreThanTwo[-2])
        print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


n = ni()
a = na()

a.sort(reverse=True)
l = list()
for key, gr in groupby(a):
    if len(l) == 2:
        break
    num = len(list(gr))
    if num >= 2:
        l.append(key)
    if num >= 4:
        l.apend(key)
print(l[0] * l[1])

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) \
            and c.most_common()[0][1] < 4:
        return print(0)
    d = [i[0] for i in c.items() if i[1] >= 2]
    d.sort()
    e = [i[0] for i in c.items() if i[1] >= 4]
    e.sort()
    print(max(d[-1] * d[-2], e[-1]*e[-1]))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

table=collections.defaultdict(int)
for x in A:
  table[x]+=1
table=list(table.items())
table=[table[i][0] for  i in range(N) if table[i][1]>1]
table.append(0)
table.append(0)
table.sort(reverse=True)
print(table[0]*table[1])

Submission status: Runtime Error

Solution code:
from collections import Counter

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

c = Counter(A)
hen = [(key, val) for key, val in c.items() if val > 1]

l = max(hen) if hen else 0
if l != 0:
    if c[l] > 3:
        s = l
    else:
        hen.remove(l)
        s = max(hen) if hen else 0
else:
    s = 0

print(l * s)

Submission status: Runtime Error

Solution code:
import heapq
n=int(input())
s=set()
q=[0,0]
for a in map(int,input().split()):
  if a>q[0]:
    heapq.heapreplace(q,a)
print(q[0]*a[1])

Submission status: Runtime Error

Solution code:
N = int(input())
A = tuple(map(int, input().split()))

#%%
keys = set(A)
keys = sorted(keys, reverse=True)

if len(keys) == len(A) - 2:
    ans = 0
else:
    lengths = []
    for k in keys:
        num = A.count(k)
        if num >= 4 and len(lengths) == 0:
            lengths.append(k)
            lengths.append(k)
        elif num >= 2:
            lengths.append(k)

        if len(lengths) == 2:
            break

    ans = lengths[0] * lengths[1]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
Ac = Counter(list(map(int, input().split())))
over2 = [ele for ele in Ac.items() if ele[1]>=2]
if len(over2) == 0:
  print(0)
elif len(over2) == 1:
  if over2[0][1] >= 4:
    print(over2[0][0]**2)
else:
  over2.sort()[::-1]
  if over2[0][1] >= 4:
    print(over2[0][0]**2)
  else:
    print(over2[0][0]*over2[1][0])

Submission status: Runtime Error

Solution code:
import collections

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

c = collections.Counter(ls)

ls_s = c.most_common()
ls_s.sort(reverse=True)

mul = []

for i in range(len(ls_s)):
    if ls_s[i][1] >= 4:
        if len(mul) == 0:
            print(ls_s[i][0] ** 2)
            break
        elif len(mul) == 1:
            print(ls_s[i][0] * mu;[0])
            break
    elif ls_s[i][1] >= 2:
        mul.append(ls_s[i][0])
    
    if len(mul) >= 2:
        print(mul[0] * mul[1])
        break
    elif i == len(ls_s) - 1:
        print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
m=map(int,input().split())
a=[0 for i in range(1000000)]
x=0
y=0
for i in m:
    a[i]+=1
for i in range(len(a)):
    if a[i]>=2:
        x=y
        y=i

ans=x*y
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
m=map(int,input().split())
a=[0 for i in range(100001)]
x=0
y=0
for i in m:
    a[i]+=1
for i in range(len(a)):
    if a[i]>=2:
        x=y
        y=i

ans=x*y
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
m=map(int,input().split())
a=[0 for i in range(100000)]
x=0
y=0
for i in m:
    a[i]+=1
for i in range(len(a)):
    if a[i]>=2:
        x=y
        y=i

ans=x*y
print(ans)

Submission status: Runtime Error

Solution code:
#第二問　make a rectangle
import collections
n=int(input())
lists=list(map(int,input().split()))
A=dict(collections.Counter(lists))
dictdict=[]


for j in A.keys():
    for _ in range(A[j]//2):
        dictdict.append(j)

dictdict=sorted(dictdict,reverse=True)
print(dictdict[0]*dictdict[1])

Submission status: Runtime Error

Solution code:
def main(n: int, a: list):
    c = sorted(Counter(a).items(), reverse=True)

    x_y = []

    for l, m in c:
        if m >= 4:
            print(m ** 2)
            return

        if m >= 2:
            x_y.append(l)

        if len(x_y) == 2:
            print(x_y[0] * x_y[1])
            return

    if len(x_y) != 2:
        print(0)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    main(n, a)

Submission status: Runtime Error

Solution code:
def main(n: int, a: list):
    c = sorted(Counter(a).items(), reverse=True)

    x_y = []

    for l, m in c:
        if len(x_y) == 0 and m >= 4:
            print(m ** m)
            return

        if m >= 2:
            x_y.append(l)

        if len(x_y) == 2:
            print(x_y[0] * x_y[1])
            return

    if len(x_y) != 2:
        print(0)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    main(n, a)

Submission status: Runtime Error

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

f = 0
x = 0
for i in range(len(a)):
    if a[i] == a[i+1] != x:
        f += 1
    if f == 1:
        x = a[i]
        f += 1
        if a.count(x) >= 4:
          f = 3
    if f >= 3:
        print(x*a[i])
        exit()
print(0)

Submission status: Runtime Error

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

l = [0] * (a[0]+10)
f = 0
for i in a:
    l[i-1] += 1
    if l[i-1] == 2 or l[i-1] == 4:
        f += 1
    if f == 1:
        x = i
        f += 1
    if f == 3:
        print(x*i)
        exit()
print(0)

Submission status: Runtime Error

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

l = [0] * (a[0])
f = 0
for i in a:
    l[i-1] += 1
    if l[i-1] == 2:
        f += 1
    if f == 1:
        x = i
        f += 1
    if f == 3:
        print(x*i)
        exit()
print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input()
B = input()

def f(horizontal_flag):
    if horizontal_flag[0]:
        if horizontal_flag[1]:
            return 3
        else:
            return 1
    else:
        return 2

if N == 1:
    print(3)    
else:
    if A[0] == A[1]:
        counter = 6
        initial_num = 2
        horizontal_flag = [0,1]
    else:
        counter = 3
        initial_num = 1
        horizontal_flag = [0,1]


    for i in range(initial_num,N):
        if i == N-1:
            if horizontal_flag[1] == 2:
                horizontal_flag[1] = 1
                counter *= f(horizontal_flag)
            else:
                horizontal_flag[1] = 0
                counter *= f(horizontal_flag)
        elif A[i] == A[i+1]:
            horizontal_flag[1] = 2
        else:
            if horizontal_flag[1] == 2:
                horizontal_flag[1] = 1
                counter *= f(horizontal_flag)
            else:
                horizontal_flag[1] = 0
                counter *= f(horizontal_flag)
            horizontal_flag[0] = horizontal_flag[1]
    print(counter % 1000000007)

Submission status: Runtime Error

Solution code:
import collections

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

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

a = 0

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

b = 0

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

Submission status: Runtime Error

Solution code:
import collections
import heapq
n=int(input())
a=[-int(item) for item in input().split()]
c = [item for item in list(collections.Counter(a).items()) if item[1]>1]
if c==[]:
  print(0)
  exit()
#print(c)
x=heapq.heappop(c)
y=heapq.heappop(c)
kouho=[]
if x[1]>=4:
  print(x*x)
else:
  print(x*y)

Submission status: Runtime Error

Solution code:
import collections
import heapq
n=int(input())
a=[-int(item) for item in input().split()]
c = [item for item in list(collections.Counter(a).items()) if item[1]>1]
#print(c)
x=heapq.heappop(c)[0]
y=heapq.heappop(c)[0]
print(x*y)