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_list = list(map(int, input().split()))
counts = {}
for a in a_list:
	if a in counts:
		counts[a] += 1
	else:
		counts[a] = 1
counts = sorted(counts.items(), reverse=True, key=lambda x: x[0])
a = 0
b = 0
for key, value in counts:
	if value > 1:
		if a == 0:
			a = key
			if value > 3:
				b = key
				break
		else:
			b = key
			break
r = a*b
print(r)

Submission status: Accepted

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

for i in range(N):
    if i == 0:
        continue
    elif A[i-1] == A[i]:
        kouho.add(A[i])
        if A.count(A[i]) >= 4 or len(kouho) >= 2:
            break
else:
    ans = 0

kouho = list(kouho)

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

print(ans)

Submission status: Accepted

Solution code:
import collections

n=int(input())
a=list(map(int,input().split()))
a=collections.Counter(a)
a=sorted(a.items(),reverse=True)
#print(a)

tm=0

for i in range(n):
    if a[i][1]>=4 and tm==0:
        print(a[i][0]*a[i][0])
        exit()
    elif a[i][1]>=2:
        if tm==0:
            tm=a[i][0]
        else:
            print(tm*a[i][0])
            exit()

print("0")

Submission status: Accepted

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

c = Counter(A)
sc = sorted(c.items(), key=lambda x: x[0], reverse=True)
sides = []
for side, nums in sc:
    if nums >= 4:
        sides.append(side)
        sides.append(side)
    elif nums >= 2:
        sides.append(side)
if 1 >= len(sides):
    print(0)
    exit()

s = sorted(sides, reverse=True)
ans = s[0]*s[1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter, deque
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
c = deque([])
for k in b.keys():
    if b[k]>=4:
        c.append(k)
        c.append(k)
    elif b[k]>=2:
        c.append(k)
c = sorted(c, reverse = True)
print(c[0]*c[1] if c else 0)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse = True)
l1 = 0
l2 = 0
j = 0
for i in range(n - 1):
    j = i + 1
    if a[i] == a[i + 1]:
        l1 = a[i]
        j = i + 2
        break
for i in range(j, n - 1):
    if a[i] == a[i + 1]:
        l2 = a[i]
        break
print(l1 * l2)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = {}
for ai in a:
  if ai in d:
    d[ai] += 1
  else:
    d[ai] = 1
d = sorted(d.items(),reverse = True)
r = []
for k,v in d:
  if len(r) >= 2:
    break
  if v >= 4:
    r.append(k)
    r.append(k)
  elif v >= 2:
    r.append(k)
if len(r) < 2:
  print(0)
else:
  print(r[0]*r[1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a.reverse()
count = 1
x = 0
y = 0
for i in range(1,n):
    if a[i] == a[i-1]:
        count+=1
    else:
        count = 1
    if count == 2 and x == 0:
        x = a[i]
        count = 0       
    elif count == 2 and y == 0:
        y = a[i]
print(x*y)

Submission status: Accepted

Solution code:
from collections import Counter
n, *A = map(int, open(0).read().split())
B = sorted([(k, v) for k, v in Counter(A).items() if v >= 2], reverse=1)
if len(B) == 0:
  print(0)
elif len(B) == 1:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
    print(0)
else:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
  	print(B[0][0]*B[1][0])

Submission status: Accepted

Solution code:
import collections 

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

d = collections.Counter(A)

x = sorted([i for i in d.items() if i[1]>1])
if len(x)==0 :
  print(0)
elif x[-1][1] >3 :
  print(x[-1][0]**2)
elif len(x) == 1 :
  print(0)
else:
  print(x[-1][0]*x[-2][0])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
l = sorted(filter(lambda x:x[1] > 1,c.items()),reverse=True)

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
l = list(map(int,input().split()))
c = collections.Counter(l)
dic = sorted(c.items(), reverse=True)
r = []
for j in dic:
    k = j[0]
    v = j[1]
    if v >= 4:
    	r.append(k)
    	r.append(k)
    elif v >= 2:
    	r.append(k)
    if len(r) >= 2:
      print(r[0]*r[1])
      exit()
print(0)

Submission status: Accepted

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

S=[]
for i,j in A.items():
  if j>=2:
    S.append(i)
S=list(set(S))
S.sort()
if len(S)>=2:
  ans=S[-1]*S[-2]
else:
  print(0)
  exit()

Q=[]

for i,j in A.items():
  if j>=4:
    Q.append(i)
if Q==[]:
  print(ans)
  exit()
print(max(ans, (max(Q))**2))

Submission status: Accepted

Solution code:
import sys

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

def main():
    a.sort()
    y = x = 0
    i = n - 1
    while i > 0:
        if a[i] == a[i-1]:
            if not y:
                y = a[i]
                i -= 1
            else:
                x = a[i]
                break
        i -= 1
    print(y * x)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
ls = []
pre = A[0]
cnt = 1
for i in range(n):
    if A[i] == pre:
        cnt+=1
    else:
        ls.append((pre,cnt))
        cnt = 1
    pre = A[i]
ls.append((pre,cnt))
ans = 0
pre = 0
for num,cnt in ls:
    if cnt>=2:
        if cnt>=4:
            ans = num**2
        else:
            ans = num*pre
        pre = num
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(map(int, input().split()), reverse = True)

x = 0; y = 0
count = 0
i = 0
while i < n - 1:
    if A[i] == A[i + 1]:
        if count == 0:
            x = A[i]
        else:
            y = A[i]
        count += 1
        i += 2
    else:
        i += 1
    if count == 2:
        break

print(x * y)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
D = Counter(A)
res = []
for k, v in D.items():
    if v >= 2:
        for _ in range(v // 2):
            res.append(k)

if len(res) < 2:
    print(0)
else:
    res = sorted(res, reverse=True)
    print(res[0] * res[1])

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""
# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n = int(input())
  dic = {}
  for nya in map(int,input().split()):
    if nya in dic:
      dic[nya] += 1
    else:
      dic[nya] = 1
  
  LIST = []
  
  for k,v in dic.items():
    if v // 2 >= 1 and v > 1: # 最低限2個以上は必要
      LIST.append([k,v])
  LIST = sorted(LIST,reverse = True)
  #print(LIST) # [[5, 3], [4, 3], [3, 4]]
  cnt = 0
  pr_ = 0
  for k,v in LIST:
    #print(k,v)
    if v // 2 >= 2 and cnt == 0:
      print(k * k)
      exit()
    elif v // 2 == 1 and cnt == 0:
      cnt += 2
      pr_ = k
    elif v // 2 >= 1 and cnt == 2:
      print(pr_ * k)
      exit()
  print(0)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
d = {}

for i in range(n):
    tmp = a[i]
    if tmp not in d:
        d[tmp] = 0
    d[tmp] += 1

flag1 = False
flag2 = False

for kk in sorted(d.keys(),reverse = True):
    if d[kk] >= 2 and flag1 == False:
        mx_v = kk
        flag1 = True
        d[kk] -= 2
    if flag1 == True and flag2 == False and d[kk] >= 2:
        mn_v = kk
        flag2 = True

if flag1 and flag2:
    print(mx_v * mn_v)
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ns = list(map(int, input().split()))
dic = Counter(ns)
dic = {key:value for key, value in dic.items() if value>=2}
if len(dic) < 2:
    print(0)
else:
    sorted_dic = sorted(dic.items(), key=lambda x: x[0])
    if sorted_dic[-1][1] >= 4:
        print(sorted_dic[-1][0]**2)
    else:
        print(sorted_dic[-1][0] * sorted_dic[-2][0])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
list_A = list(map(int, input().split()))
list_C = Counter(list_A)
list_D = sorted(list_C.items(), key=lambda x:x[0],reverse=True)
q = []
for i in range(len(list_D)):
    if len(q) == 2:
        break
    l = list_D[i]
    if l[1] > 1:
        q.append(l[0])
        if len(q) == 1 and l[1] > 3:
            q.append(l[0])
if len(q) == 2:
    print(q[0]*q[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter as C
n,*a=map(int,open(0).read().split())
b=[]
for i in C(a).items():
  if i[1]>3:
    b+=[i[0],i[0]]
  elif i[1]>1:
    b+=[i[0]]
b=sorted(b)
print(b[-1]*b[-2] if len(b)>1 else 0)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
c_ls = []
cnt = 0
for i in range(n-1):
  if a[i] == a[i+1]:
    cnt += 1
  else:
    cnt = 0
  if cnt == 3:
    c_ls.append(a[i])
  if (a[i] == a[i+1]) and(a[i] not in c_ls):
    c_ls.append(a[i])
  if len(c_ls) == 2:
    print(c_ls[0]*c_ls[1])
    exit()
print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = list(reversed(sorted(a)))
x = 0
y = 0
for i in range(len(a)-1):
         if a[i] == a[i+1]:
                  x = a[i]
                  break
for j in range(i+2,len(a)-1):
         if a[j] == a[j+1]:
                  y = a[j]
                  break
print(x*y)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
ans = []
for i, j in a.items():
    if j >= 2:
        for _ in range(j):
            ans.append(i)
ans.sort(reverse=True)
if len(ans) <= 3:
    print(0)
else:
    print(ans[0]*ans[3])

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
ans = []
for i, j in a.items():
    if j >= 2:
        for _ in range(j):
            ans.append(i)
ans.sort(reverse=True)
if len(ans) == 0:
    print(0)
else:
    print(ans[0]*ans[3])

Submission status: Accepted

Solution code:
import collections 
n=input()
a=tuple(map(int,input().split()))
c=collections.Counter(a)
b=sorted(list(set(a)))[::-1]
ans,count=0,0
for i in b:
  if c[i]>3 and ans==0:
    print(i**2)
    exit()
  if c[i]>1:
    ans=ans*i if ans>0 else i
    count+=1
    if count==2:
      print(ans)
      exit()
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
work = []
temp = []
for k, v in sorted(counter.items(), key=lambda x:x[0], reverse=True):
    if v >= 4:
        temp.append(k)
    if v >= 2:
        work.append(k)
        if len(work)==2:
            break   
if len(work) < 2:
    if len(temp)==0:
        result = 0
    else:
        result = temp[0]**2
else:
    if len(temp)==0:
        result = work[0]*work[1]
    else:
        result = work[0]*work[1] if work[0]*work[1]>temp[0]**2 else temp[0]**2
print(result)

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ans = []
for i in range(0,n-1):
    if(a[i]==a[i+1]):
        ans.append(a[i])
if len(ans) <2:
    print(0)
    sys.exit()
        
if (ans[0]==ans[1] and ans[1]!=ans[2]):
    print(ans[0]*ans[2])
    sys.exit()

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

Submission status: Accepted

Solution code:
# N = 10
# ARR = [3, 3, 3, 3, 4, 4, 4, 5, 5, 5]
#
# # N = 6
# # ARR = [3, 1, 2, 4, 2, 1]
#
# # N = 4
# # ARR = [1, 2, 3, 4]

N = int(input())
ARR = [int(s) for s in input().split(" ")]


def calculate(n, arr):

    dict = {}

    for ar in arr:
        if dict.get(ar) == None:
            dict.__setitem__(ar, 1)
        else:
            dict.__setitem__(ar, dict.get(ar) + 1)

    dict2 = {changedu: geshu for changedu, geshu in dict.items() if geshu >= 2}

    dict3 = sorted(dict2.items(), key=lambda x: -x[0])


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


calculate(N, ARR)

Submission status: Accepted

Solution code:
from collections import Counter


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

cand = [a for a in edge.keys() if edge[a] >= 2]
cand.sort(reverse=True)

e1 = e2 = 0
if len(cand) >= 1:
    if edge[cand[0]] >= 4:
        e1 = e2 = cand[0]
    elif len(cand) > 1:
        e1 = cand[0]
        e2 = cand[1]

print(e1 * e2)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
count = []

i = 0
while i<n-1:
    if lst[i]==lst[i+1]:
        count.append(lst[i])
        i+=2
    else:
        i+=1

count.sort(reverse=True)
count.append(0)
count.append(0)

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

Submission status: Accepted

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

a.sort(reverse=True)

i1=-1
lena1=0
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        lena1=a[i+1]
        i1=i
        break
if i1==-1:        
    print(0)
elif i1+2<len(a)-1:        
    lena2=0
    for i in range(i1+2,len(a)-1):
#        if a[i]==a[i+1] and a[i]!=lena1:
        if a[i]==a[i+1] :
            lena2=a[i+1]
            break
    print(lena1*lena2)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
b = True
wh = 0
for i in range(n - 1):
  if b == False:
    b = True
    continue
  if a[i] == a[i + 1]:
    b = False
    if wh == 0:
      wh = a[i]
    else:
      print(wh * a[i])
      exit()
print(0)

Submission status: Accepted

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

a_cnt = {}
for ai in A:
    if ai in a_cnt:
        a_cnt[ai] += 1
    else:
        a_cnt[ai] = 1
from operator import itemgetter
a_cnt = sorted(a_cnt.items(), key=itemgetter(0), reverse=True)
tate = 0
yoko = 0
for i in range(len(a_cnt)):
    if a_cnt[i][1] >= 2:
        tate = a_cnt[i][0]
        #a_cnt[i][1] -= 1
        a_cnt[i] = (a_cnt[i][0], a_cnt[i][1] - 2)
        break
for i in range(len(a_cnt)):
    if a_cnt[i][1] >= 2:
        yoko = a_cnt[i][0]
        #a_cnt[i][1] -= 1
        a_cnt[i] = (a_cnt[i][0], a_cnt[i][1] - 2)
        break
#if tate == 0 or yoko == 0:
#    print(0)
print(tate * yoko)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
cnt=1
li=[]
x=[0]
for i in range(n-1):
    if a[i+1]==a[i]:
        cnt+=1
    else:
        cnt=1
    if cnt==2:
        li.append(a[i+1])
    if cnt==4:
        x.append(a[i+1])

if len(li)>=2:
    print(max(li[0]*li[1],max(x)**2))
else:
    print(0)

Submission status: Accepted

Solution code:
import collections

n, *a = map(int, open(0).read().split())
c = collections.Counter(a)
length_l = list(c.keys())
length_l.sort(reverse = True)
side1 = 0
ans = 0
for l in length_l:
    cnt = c[l]
    if cnt >= 4:
        if side1 != 0:
            ans = side1*l
            break
        else:
            ans = l**2
            break
    elif cnt >= 2:
        if side1 != 0:
            ans = side1*l
            break
        else:
            side1 = l
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


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

    count = Counter(A)
    count = sorted(count.items(), key=lambda x: (-x[0], x[1]))
    count = [(k, v) for k, v in count if v >= 2]
    if len(count) < 2:
        print(0)
    elif count[0][1] >= 4:
        print(count[0][0] ** 2)
    else:
        print(count[0][0] * count[1][0])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import collections
lst=collections.Counter(A).most_common()
lst_larger=[el for el in lst if el[1]>=2]
#print(lst)
#print(lst_larger)
if len(lst_larger) >= 2:
    lst_larger=sorted(lst_larger, key=lambda x:x[0], reverse=True)
    if lst_larger[0][1]>=4:
        print(lst_larger[0][0]**2)
    else:
        print(lst_larger[0][0]*lst_larger[1][0])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
cnt=defaultdict(int)
for i in range(n):
  cnt[a[i]]+=1
tmp=[]
for key in cnt.keys():
  if cnt[key]>=2:
    tmp.append(key)
    if cnt[key]>=4:
      tmp.append(key)
tmp=sorted(tmp,reverse=True)
if len(tmp)<=1:
  print(0)
else:
  print(tmp[0]*tmp[1])

Submission status: Accepted

Solution code:
def main2():
    r = int(input())

    stick = [int(v) for v in input().split()]
    stick = sorted(stick, reverse=True)

    line = []
    tmp = -1
    for i in range(0, len(stick), 1):
        if tmp == stick[i]:
            line.append(stick[i])
            tmp = -1
        else:
            tmp = stick[i]
        if len(line) == 2:
            print(line[0] * line[1])
            exit()
    print(0)

main2()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

import collections

C = collections.Counter(A)

D = sorted(list(set(A)))[::-1]

t = 0
s = 0
for i in D:
    if C[i] >= 4 and t == 0:
        print(i ** 2)
        s = 1
        break
    elif C[i] >= 2 and t == 0:
        t = i
    elif C[i] >= 2 and t != 0:
        print(i * t)
        s = 1
        break

if s == 0:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
from collections import Counter
a=Counter(list(map(int,input().split())))
l=[]
ll=[]
ans=0
for i in a:
    if a[i]>=2:
        l.append(i)
    if a[i]>=4:
        ans=max(ans,i*i)
l.sort(reverse=True)
if len(l)<2:
    print(0)
else:
    print(max(l[0]*l[1],ans))

Submission status: Accepted

Solution code:
from collections import Counter

a = input()
a_list = list(map(int, input().split()))
 
# 要素数の数え上げと取り出し
num_counter = Counter(a_list)
num_keys = sorted(num_counter.keys(), reverse=True)

big = 0
small = 0

for i in num_keys:
  x = num_counter[i]
  if x >= 4:
    if big == 0:
      big = small = i
    elif big != 0 and small == 0:
      small = i
  elif x == 3 or x == 2:
    if big == 0:
      big = i
    elif big != 0 and small == 0:
      small = i
  if big != 0 and small != 0:
    break
print(big * small)

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=map(int,input().split())
b=list(collections.Counter(a).items())
lst=[]
Lst=[]
for i in range(len(b)):
  if b[i][1]>1:
    lst.append(int(b[i][0]))  
    if b[i][1]>3:
      Lst.append(int(b[i][0]))
if len(lst)<2 and len(Lst)==0:
  print(0)
else:
  if len(lst)==1:
    Lst.sort(reverse=True)
    print(Lst[0]**2)
  else:
    if len(Lst)>0:
      lst.sort(reverse=True)
      Lst.sort(reverse=True)
      print(max(lst[0]*lst[1],Lst[0]**2))     
    else:
      lst.sort(reverse=True)
      print(lst[0]*lst[1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
dict = {}
b = [0,0]
c = [0,0]
for i in a:
	if i in dict:
		dict[i] += 1
	else:
		dict[i] = 1
	if dict[i] == 2:
		b.append(i)
	if dict[i] == 4:
		c.append(i)
b.sort(reverse=True)
c.sort(reverse=True)
print (max(b[0] * b[1],c[0]**2))

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    cnter = Counter(A)
    cnter_list = list(cnter.items())
    cnter_list.sort(key=lambda x:x[0], reverse=True)

    double_cnt = 0
    ans = 1
    for elem in cnter_list:
        if elem[1] >= 4:
            if double_cnt == 0:
                ans = elem[0] * elem[0]
                break

        if elem[1] >= 2:
            double_cnt += 1
            ans *= elem[0]
        if double_cnt >= 2:
            break
    else:
        print(0)
        return
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

#print(*ans, sep='\n')

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Tue Mar 24 00:01:43 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter

n = ni()
a = na()
c = Counter(a)
m = list(c.items())
m.sort(reverse=True)
xy = [0] * 2
i = 0
flag = False
for k, v in m:
    if v >= 4:
        if i != 0:
            print(xy[0] * k)
        else:
            print(k * k)
        flag = True
        break
    elif v >= 2:
        xy[i] = k
        i += 1
        if i == 2:
            print(xy[0] * xy[1])
            flag = True
            break
if not flag:
    print(0)

Submission status: Accepted

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

c = Counter(a).most_common()
edges = []
for l, cnt in c:
    if cnt < 2:
        break
    else:
        edges.append(l)
        if cnt > 3:
            edges.append(l)
edges.sort(reverse= True)
if len(edges) < 2:
    print(0)
else:
    print(edges[0] * edges[1])

Submission status: Accepted

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

dict1 = {}
for i in a:
    if i in dict1:
        dict1[i] += 1
    else:
        dict1[i] = 1

dict1_sorted = sorted(dict1.items(), key=lambda x:x[0], reverse = True)

ans = []

for a,b in dict1_sorted:
    if b >= 4:
        if len(ans) == 0:
            ans = [a] * 2
            break
        else:
            ans.append(a)
            break
    elif b >= 2:
        ans.append(a)
        if len(ans) == 2:
            break

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

Submission status: Accepted

Solution code:
input()
from collections import *
c=Counter(map(int,input().split()))
f=lambda x:sorted(-k for k,v in c.items() if v>x)
a=0;r=f(1);s=f(3)
if len(r)>1: a=r[0]*r[1]
if s: a=max(a,s[0]**2)
print(a)

Submission status: Accepted

Solution code:
input()
from collections import *
c=Counter(map(int,input().split()))
a=0
r=sorted(-k for k,v in c.items() if v>1)
if len(r)>1: a=r[0]*r[1]
s=sorted(-k for k,v in c.items() if v>3)
if s: a=max(a,s[0]**2)
print(a)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a).most_common()
s=[0,0]
for v in c:
  if v[1]>=2:
    for _ in range(v[1]//2):
      s.append(int(v[0]))
s.sort()
print(s[-1]*s[-2])

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)
s = [(k, v) for k, v in c.items() if v >= 2]

s1 = s2 = 0  # s1 >= s2
for k, v in s:
    if k > s1:
        if v >= 4:
            s1 = s2 = k
        else:
            s1, s2 = k, s1
    elif k > s2:
        s2 = k

print(s1 * s2)

Submission status: Accepted

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

from collections import Counter
c = Counter(l)
c = sorted(c.items(), reverse=1)

temp = 0
for i in range(len(c)):
    if c[i][1] >= 2:
        if temp != 0:
            print(temp * c[i][0])
            exit()
        else:
            temp = c[i][0]
    if c[i][1] >= 4:
            print(c[i][0] ** 2)
            exit()
else:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())

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

t.sort()

memo = []
check = 1
for i in range(n-1):
    if t[i] == t[i+1] and i == n-2:
        check += 1
        memo.extend([t[i]]*(check//2))
    elif t[i] == t[i+1]:
        check += 1
    elif t[i] != t[i+1] and check>1:
        memo.extend([t[i]]*(check//2))
        check = 1

memo.sort(reverse=True)

if len(memo)>1:
    print(memo[0]*memo[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict


def solve():
    _ = int(input())
    A = list(map(int, input().split()))
    
    counter = defaultdict(int)
    for ai in A:
        counter[ai] += 1
    
    first, second = 0, 0
    for key, val in counter.items():
        if 4 <= val:
            if first < key:
                first, second = key, key
            elif second < key:
                second = key
        elif 2 <= val:
            if first < key:
                first, second = key, first
            elif second < key:
                second = key
    ans = first * second
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())
seq = sorted((int(x) for x in input().split()), reverse=True)
val1 = None
val2 = None
cur_val = seq[0]
for val in seq[1:]:
    if val == cur_val:
        if val1 is None:
            val1 = val
            cur_val = None
        elif val2 is None:
            val2 = val
            break
    else:
        cur_val = val
if val1 is None or val2 is None:
    print(0)
else:
    print(val1 * val2)

Submission status: Accepted

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

A.sort(key=lambda x: -x)

l = []

a_old = -1
for a in A:
    if a_old == a:
        l.append(a)
        a_old = -1
    else:
        a_old = a

l.append(0)
l.append(0)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, A: "List[int]"):
    def g():
        ctr = Counter(A)
        for key in sorted(ctr.keys(), reverse=True):
            for _ in range(ctr[key] // 2):
                yield key
    gg = g()
    try:
        print(next(gg) * next(gg))
    except StopIteration:
        print(0)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input().strip())
a = list(map(int, input().split()))
reps = []

a.sort()
tmp = 0
for e in a:
    if e == tmp:
        reps.append(e)
        tmp = 0
    else:
        tmp = e
if len(reps) < 2:
    print(0)
else:
    print(reps[-1] * reps[-2])

Submission status: Accepted

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

import collections

L = collections.Counter(a_L)

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

flag = 0
#print(L)
ans = 0
for k,v in L:
    #print(k,v)
    if v>=4:
        ans = max(ans,k**2)

    if v >= 2:
        if flag== 0:
            tmp = k
            flag += 1
        elif flag == 1:
            ans = max(tmp*k,ans)
            #print(tmp*k)
            #print("ans",tmp,k)
            print(ans)
            exit()

print(0)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)  # リストの要素をカウント
cnt = [k for k, v in c.items() if v >= 2]

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

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

W = H = 0
L = sorted(list(Counter(A).items()),key=lambda x:(-x[0]))
for k,v in L:
    if W == 0:
        if v >= 4:
            W = H = k
            break
        elif v >= 2:
            W = k
    elif H == 0:
        if v >= 2:
            H = k
            break

print(H*W)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]

A = Counter(a)
a_sorted = sorted(A.keys(), reverse=True)

ans = 0
tmp = 0
for i in a_sorted:
    if A[i] >= 4 and tmp == 0:
        ans = i**2
        break
    elif A[i] >= 2 and tmp == 0:
        tmp = i
    elif A[i] >= 2 and tmp != 0:
        ans = tmp * i
        break
print(ans)

Submission status: Accepted

Solution code:
import collections

n=int(input())
arr=list(map(int,input().split()))
cnt=collections.Counter(arr)
keys=cnt.keys()
keys=sorted(keys,reverse=True)
a=0
b=0
for key in keys:
  if b!=0:
    break
  if a==0:
    if cnt[key]>=2:
      a=key
      if cnt[key]>=4:
        b=key
  else:
    if cnt[key]>=2:
      b=key
print(a*b)