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:
#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


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

    Num = [0] * N
    for a in A:
        Num[a-1] += 1

    l1 = l2 = 0
    for i in range(N-1, -1, -1):
        if l1 == 0:
            if Num[i] >= 2:
                l1 = i+1
                if Num[i] >= 4:
                    l2 = i+1
                    break
        else:
            if Num[i] >= 2:
                l2 = i+1
                break

    print(l1*l2)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


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

    Num = [0] * N
    for a in A:
        Num[a-1] += 1

    l1 = l2 = 0
    for i in range(len(Num)-1, -1, -1):
        if l1 == 0:
            if Num[i] >= 2:
                l1 = i+1
            if Num[i] >= 4:
                l2 = i+1
                break
        else:
            if Num[i] >= 2:
                l2 = i+1
                break

    print(l1*l2)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
a=[int(x) for x in input().rstrip().split()]

m=[0]*max(a)
for i in a:
  m[i-1]+=1

ans=1
cnt=0
for i in range(max(a)-1,-1,-1):
  if 2<=m[i]:
    cnt+=1
    ans*=(i+1)
    if cnt==2:
      print(ans)
      sys.exit()
print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ca = Counter(A)
ca = sorted(ca.items(), key=lambda x:-x[0])
cnt = 0
m = []
for k, v in ca:
  if v >= 2:
    cnt += 1
    m += [k]
  if cnt >= 2:
    break

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

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
  if a.count(a[i]) >= 2 and a[i] not in l:
    l.append(a[i])
l.sort()
print(l[-1]*l[-2])

Submission status: Runtime Error

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

Solution code:
import sys

n,*a=map(int,sys.stdin.read())

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==2 and f==1) or (c==3 and f==2):
    print(ans[0]*ans[1])
    sys.exit()
print(0)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
box,box2 = [],[]
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: Runtime Error

Solution code:
import sys
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
box,box2 = [],[]
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)
ans = max(box2)
if len(box) >= 2:
    print(max(ans,(box[0]*box[1])))
    sys.exit()
print(0)

Submission status: Runtime Error

Solution code:
from numba import jit
@jit
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse = True)
    ans = 0
    for i in range(n):
        if a.count(a[i]) >= 4:
            ans = a[i]*a[i]
            break
        elif a.count(a[i]) >=2:
            for j in range(i+a.count(a[i]),n):
                if a.count(a[j]) >=2:
                    ans = a[i]*a[j]
                    break
            break
    print(ans)
main()

Submission status: Runtime Error

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 len(a):
    if count == 1:
        print(l*a[i][0])
        exit()
    else:
        l = a[0]
        count += 1

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

print(0)

Submission status: Runtime Error

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:
        l.append(v)

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

count = [0] * (10**5)

for i in lis:
    count[i] += 1

t1 = 0
t2 = 0
  
for i in range(len(count)):
    if count[i] >= 2 and i+1 > t1:
        t2 = t1
        t1 = i

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

print(t1*t2)

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = list(map(int,input().split())) + [0]
A = list(Counter(A).items())
A  = sorted(A,key=itemgetter(1),reverse = True)
A  = sorted(A,key=itemgetter(0),reverse = True)
#print(A)
ans = 0
for i in range(len(A)):
    if A[i][1] > 1:
        if A[i][1] > 3 :
            ans = max(ans,A[i][0]*2)
        if A[i][1] > 1 and A[i+1][1] > 1:
            ans = max(ans ,A[i][0]*A[i+1][0])
print(ans

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    map<ll,ll, greater<ll>>mp;
    for(ll i=0; i<n; i++ )
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    ll c=0;
    ll ar=1;
    ll f=0;
    for(auto it=mp.begin(); it!=mp.end(); ++it)
    {
        ll s=it->second;
        if(c==0)
        {
            if(s>=4)
            {
                cout<<it->first*it->first<<endl;
                f=1;
                break;
            }
        }
        if(s>=2)
        {
            ar=ar*it->first;
            c++;
            if(c==2)
            {
                break;
            }
        }
    }
    if(c!=2&&f==0)
    {
        cout<<0<<endl;
    }
    else if(c==2&&f==0)
    {
        cout<<ar<<endl;
    }

}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

for i,j in d.items():
    if j>=2:
        b.append(i)
    if j>=4:
        c.append(i)
if len(b)<2:
    print(0)
else:
    b.sort(reverse=True)
    rec=b[0]*b[1]
    if len(c)>=1:
        c.sort(reverse=True)
        cube=c[0]**2
    print(max(rec,cube))

Submission status: Runtime Error

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

A = A.sort()
b = set(A)
b = list(b)
a = [i for i in b if A.count(i) >= 2]

if len(a) <= 1:
    print(0)
else:
    a = set(a)
    a = list(a)
    a.reverse()
    print(a[0]*a[1])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(4100000)

n=int(input())
A=list(map(int,input().split()))
k=max(A)+1

count=[0]*k
for i in range(n):
  count[A[i]]+=1

height=0
width=0

for i in range(k-1,0,-1):
  if (height==0 and width==0 and count[i]>=4):
    height=i
    width=i
    break
  elif (height==0 and width==0 and count[i]>=2):
    height=i
    continue
  elif (height!=0 and count[i]>=2):
    width=i
    break
  
if height!=0 and width!=0:
  print(height*width)
else:
  print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
k=max(A)+1

count=[0]*k
for i in range(n):
  count[A[i]]+=1

height=0
width=0

for i in range(k-1,0,-1):
  if (height==0 and width==0 and count[i]>=4):
    height=i
    width=i
    break
  elif (height==0 and width==0 and count[i]>=2):
    height=i
    continue
  elif (height!=0 and count[i]>=2):
    width=i
    break
  
if height!=0 and width!=0:
  print(height*width)
else:
  print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
k=max(A)+1

count=[0]*k
for i in range(n):
  count[A[i]]+=1

height=0
width=0

for i in range(k-1,0,-1):
  if (height==0 and width==0 and count[i]>=4):
    height=i
    width=i
    break
  elif (height==0 and width==0 and count[i]>=2):
    height=i
    continue
  elif (height!=0 and count[i]>=2):
    width=i
    break
    
print(height*width)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
ls = list(map(int,input().split()))
c =collections.Counter(ls)
d = list(c)
p = []
for i in range(len(d)):
    if c[d[i]] >1:
        p.append(d[i])
mx1 = max(p)
p.remove(mx1)
mx2 = max(p)
print(mx1 * mx2)

Submission status: Runtime Error

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

C = Counter(A)
C = [[k, v] for k, v in C.items() if v >= 2]
C.sort(key=lambda x:x[0], reverse=True)

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(input().split())

edge_list =  []
selection = list(set(A)).sort()[::-1]

for i in selection:
    edge_list += i * (A.count(i) // 2)
    if len(edge_list) >= 2:
        break
edge_list.sort()

if len(edge_list) < 2:
    print(0)
else:
    print(int(edge_list[-1]) * int(edge_list[-2]))

Submission status: Runtime Error

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

now = A[0]
tateyoko = [0, 0]
count = 0
nowflag = False
for i in range(1, N):
  if (A[i] == now) and !nowflag:
    tateyoko[count] = now
    count += 1
    nowflag = True
  else:
    nowflag = False
  if count == 2:
    break
  now = A[i]
  
print(tateyoko[0] * tateyoko[1])

Submission status: Runtime Error

Solution code:
M = int(input())
A = list(map(int,input().split()))
B = [0]*(M+1)
C = [0]*2
D = [0]*2

for i in range(len(A)):
	B[ A[i] ] += 1 # カウント

for i in range(len(B)):
	# 一個しかなかったら条件を満たさないのでするー
	if B[i] < 2: 
        continue

	# 2個以上あれば長方形にスタック
	C.append(i)

	# 4個以上あれば正方形にスタック
	if B[i] >= 4: 
        D.append(i)
# C を降順でソート
C = sorted(C, reverse=True)

rect = C[0] * C[1]
s = max(D)
square = s * s

print(max(rect,square))

Submission status: Runtime Error

Solution code:
M = int(input())
A = list(map(int,input().split()))
B = [0]*(M+1)
C = [0]*2
D = [0]*2
 
for i in range(len(A)):
		B[ A[i] ] += 1 # カウント
 
		# Ai = 1, 1, 2, 3, 2, 4
		# B[1] = 2
		# B[2] = 2
		# B[3] = 1
		# B[4] = 1
		# B[100000] = ***

Submission status: Runtime Error

Solution code:
M = int(input())
A = list(map(int,input().split()))
B = [0]*(M+1)
C = [0]*2
D = [0]*2

for i in range(len(A)):
	B[ A[i] ] += 1 # カウント

for i in range(len(B)):
	# 一個しかなかったら条件を満たさないのでするー
	if B[i] < 2: continue

	# 2個以上あれば長方形にスタック
	C.append(i)

	# 4個以上あれば正方形にスタック
	if B[i] >= 4: D.append(i)
# C を降順でソート
C = sorted(C, reverse=True)

rect = C[0] * C[1]
s = max(D)
square = s * s

print(max(rect,square))

Submission status: Runtime Error

Solution code:
M = int(input())
A = list(map(int,input().split()))
B = [0]*(M+1)
C = [0]*2
D = [0]*2

for i in range(len(A)):
		B[ A[i] ] += 1 # カウント

		# Ai = 1, 1, 2, 3, 2, 4
		# B[1] = 2
		# B[2] = 2
		# B[3] = 1
		# B[4] = 1
		# B[100000] = ***

for i in range(len(B)):
	# 一個しかなかったら条件を満たさないのでするー
	if B[i] < 2: continue

	# 2個以上あれば長方形にスタック
	C.append(i)

	# 4個以上あれば正方形にスタック
	if B[i] >= 4: D.append(i)
# C を降順でソート
C = sorted(C, reverse=True)

rect = C[0] * C[1]
s = max(D)
square = s * s

print(max(rect,square))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

N = I()
A = IL()
d = DD(int)
for a in A:
  d[a] += 1
  
d = [(k,d[k])for k in d]
d.sort(reverse=True)
ans = []
ans_b = []
for a,b in d:
  if b>=4:
    ans_b.append(a)
  if b>=2:
    ans.append(a)
  if len(ans)==2:
    break
    
if len(ans)==2:
  if ans_b:
    P(max(ans[0]*ans[1],ans_b[0]**2))
  else:
    P(max(ans[0]*ans[1])
else:
  if ans_b:
    P(ans_b[0]**2)
  else:
    P(0)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

N = I()
A = IL()
d = DD(int)
for a in A:
  d[a] += 1
  
d = [(k,d[k])for k in d]
d.sort(reverse=True)
ans = []
ans_b = []
for a,b in d:
  if b>=4:
    ans_b.append(a)
  if b>=2:
    ans.append(a)
  if len(ans)==2:
    break
    
if len(ans)==2:
  P(max(ans[0]*ans[1],ans_b[0]**2))
else:
  if ans_b:
    P(ans_b[0]**2)
  else:
    P(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

a.sort(reverse = True)
c = []
for i in range(n):
    if a.count(a[i]) ==2 or a.count(a[i]) ==3:
        c.append(i+1)
    elif a.count(a[i]) >= 4:
        c.append(i+1)
        c.append(i+1)
    if len(c) >= 2:
        break

if len(c) >= 2:
    e = max(c)
    c.pop(e)
    f = max(c)
    print(e*f)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

b = [0]*10**5

for i in range(n):
    b[a[i]] += 1

c = []
for i in range(n):
    if b[i] == 2 or b[i] == 3:
        c.append(i+1)
    elif b[i] >= 4:
        c.append(i+1)
        c.append(i+1)

if len(c) >= 3:
    
    e = max(c)
    c.pop(e)
    f = max(c)
    print(e*f)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

b = [0]*10**9

for i in range(n):
    b[a[i]] += 1

c = []
for i in range(n):
    if b[i] == 2 or b[i] == 3:
        c.append(i+1)
    elif b[i] >= 4:
        c.append(i+1)
        c.append(i+1)

if len(c) >= 3:
    
    e = max(c)
    c.pop(e)
    f = max(c)
    print(e*f)
else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
List = list(map(int,input().split()))
List_ans = []
List.sort()
for x in range(N-1):
  if List[x]==List[x+1]:
    List_ans.append(List[x])
M = max(List_ans)
m = min(List_ans)
print(M*m)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=sorted(lmp(),reverse=True)
i=0
l=[]
while i<n:
    if a[i]==a[i+1]:
        l.append(a[i])
        i+=1
    i+=1
if len(l)>=2:
    print(l[0]*l[1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
from colletions import Counter

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

sticks_len = []
for k, v in d:
  if v >= 2:
    sticks.append(k)
  if v >= 4:
    sticks.append(k)
    
sticks.sort()

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

Submission status: Runtime Error

Solution code:
from colletions import Counter

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

sticks_len = []
for k, v in d:
  if v >= 2:
    sticks.append(k)
  if v >= 4:
    sticks.append(k)
    
sticks.sort()

if len(sticks) >= 2:
  print(sticks[-1] * sticks[-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)
pair = []
print(c)
for x, cnt in c.items():
    pair += [x] * (cnt//2)

# print(pair)
pair.sort()

ans = 0
if len(pair) >= 2:
    ans = pair[-1] * pair[-2]
print ans

Submission status: Runtime Error

Solution code:
from collections import Counter
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    ac = Counter(a)
    acl = [i for i in ac if ac[i] >= 2]

    if ac[acl[0]] >= 4:
        print(int(acl[0] ** 2))
    else:
        print(int(acl[0]*acl[1]))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
cnts = [0]*(a[-1]+1)
cnt2 = []
cnt4 = []
for i in range(len(a)):
    cnts[a[i]] += 1
    if cnts[a[i]] == 2:
        cnt2.append(a[i])
    if cnts[a[i]] == 4:
        cnt2.remove(a[i])
        cnt4.append(a[i])
ans = 0
if len(cnt2) <= 1 and not(cnt4):
    print(0)
else:
    if len(cnt2) >= 2:
        ans = max(ans, cnt2[-1]*cnt2[-2])
    if cnt4:
        ans = max(ans, cnt4[-1]**2)
    
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 0
x = 0
y = 0
while i < n:
    if x == 0:
        if a[i] == a[i+1]:
            x = a[i]
            i += 1
    elif y == 0:
        if a[i] == a[i+1]:
            y = a[i]
            i += 1
    i += 1
print(x*y)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = unique(a)
side = []
ans = 0
for key, value in d:
    if value >= 4:
        ans = max(ans, key ** 2)
    elif value >= 2:
        side.append(key)
m = len(side)
if m >= 2:
    for i in range(m-1):
        for j in range(i+1, m):
            ans = max(ans, side[i] * side[j])
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    d=defaultdict(int)
    t=[0]
    f=[]
    for x in A:
        d[x]+=1
        if d[x]==2:
            t.append(x)
        elif d[x]==4:
            f.append(x)
    t.sort()
    f.sort()
    if not f:
        if len(t)<2:
            print(0)
        else:
            print(t[-1]*t[-2])
    else:
        if f[-1]>=t[-1]:
            print(f**2)
        else:
            print(t[-1]*t[-2])

if __name__ == '__main__':
    main()