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(map(int, input().split()))

A.sort()
A = A[::-1]
ans = 0
counter = 0
buff = []
flag = False
for i in range(0, N-1):
    if flag:
        flag = False
        continue
    if A[i] == A[i+1]:
        buff.append(A[i])
        flag = True
        counter += 1
        if counter >= 2:
            print(buff[0]*buff[1])
            exit()

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
D,L={},[0,0]
for a in A:
    if a not in D:D[a]=1
    else:
        L.append(a)
        del D[a]
L.sort(reverse=True)
print(L[0]*L[1])

Submission status: Accepted

Solution code:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

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

longest=0
for length, n in d_sorted:
    if n>=2 and longest!=0:
        print(longest*length)
        exit()
    elif n>=4 and longest==0:
        print(length**2)
        exit()
    elif n>=2 and longest==0:
        longest=length
print(0)

Submission status: Accepted

Solution code:
# ABC071C - Make a Rectangle (ARC081C)
from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(
        {k: v for k, v in Counter(lst).items() if v >= 2}.items(), reverse=True
    )
    if cnt == []:
        print(0)
    elif cnt[0][1] >= 4:
        print(cnt[0][0] ** 2)
    else:
        print(cnt[0][0] * cnt[1][0])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    i = 0
    d = [0, 0]
    while N - 1 > i:
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    print(d[-1] * d[-2])


main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    i = 0
    d = []
    while N - 1 > i:
        if len(d) == 2:
            break
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    if (len(d) == 2):
        print(d[0] * d[1])
    else:
        print(0)


main()

Submission status: Accepted

Solution code:
n=int(input())
al=list(map(int,input().split()))
al.sort(reverse=True)
cnt=0
h=0
w=0
t=set()
for a in al:
    if a in t:
        if h==0:
            h=a
        else:
            w=a
            break
        t.remove(a)
    else:
        t.add(a)
print(h*w)

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(int)
for i in range(n):
    d[a[i]]+=1

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

ans = []
for i in range(n):
    if d[i][1]>=4 and len(ans)==0:
        ans.append(d[i][0])
        ans.append(d[i][0])
    if len(ans)==2:
        break

    if d[i][1]>=2:
        ans.append(d[i][0])
        if len(ans)==2:
            break

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
x=0
y=0
tmp=0
for a in A:
    if tmp==a:
        if not(x):
            x=a
            tmp=0
        else:
            y=a
            tmp=0
    else:
        tmp=a
    if x and y:
        break
print(x*y)

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    num = int(input())
    data = Counter(list(map(int, input().split())))
    score_sorted = sorted(data.items(), key=lambda x: -x[0])

    ans = []
    for ele, kosuu in score_sorted:
        if kosuu >= 2:
            if len(ans) == 0 and kosuu >= 4:
                ans = [ele, ele]
                break
            else:
                ans.append(ele)
                if len(ans) == 2:
                    break
    if len(ans) == 2:
        print(ans[0] * ans[1])
    else:
        print(0)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.sort(reverse = True)

A += [0]
count = 1
lst = []
for i in range(1, N+1):
    if A[i] == A[i-1]:
        count += 1
    else:
        lst += [[A[i-1], count]]
        count = 1

ans = 1
flag = 0
for i in range(len(lst)):
    if lst[i][1] >= 2:
        ans *= lst[i][0]
        flag += 1
        if flag == 2:
            print (ans)
            sys.exit()
        if lst[i][1] >= 4:
            ans *= lst[i][0]
            print (ans)
            sys.exit()

print (0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    i = 0
    tmp = []
    while i < N- 1:
        if A[i] == A[i + 1]:
            tmp.append(A[i])
            i += 1
        i += 1
    if len(tmp) > 1:
        ret = tmp[0] * tmp[1]
    else:
        ret = 0
    print(ret)
    return


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:
# coding: utf-8
# Your code here!

from collections import defaultdict

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

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

count = 0
sorted_keys = sorted(d.keys(), key=lambda x: -x)
has_choiced = False
h = 0
v = 0
for key in sorted_keys:
    if has_choiced == False and d[key] >= 4:
        h = key
        v = key
        break
    elif has_choiced == True and d[key] >= 4:
        v = key
        break
    elif has_choiced == True and d[key] >= 2:
        v = key
        break
    elif has_choiced == False and d[key] >= 2:
        h = key
        has_choiced = True
        
print(h * v)

Submission status: Accepted

Solution code:
n=int(input())
dic=dict()
l=list(map(int,input().split()))
for i in l:
	if i not in dic.keys():
		dic[i]=1
	else:
		dic[i]+=1
p=[k for k,v in dic.items() if v>=2]
f=0
s=0
for i in p:
	if i>f:
		f,s=i,f
	elif i>s:
		s=i
print(0 if f==0 else f**2 if dic[f]>=4 else f*s)

Submission status: Accepted

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

dic = {}
xy = []
for a in A:
    if a in dic:
        dic[a] += 1
        if dic[a] == 2:
            xy.append(a)
            dic[a] = 0
    else:
        dic[a] = 1
xy.sort(reverse = True)
if len(xy) < 2:
    print(0)
else:
    print(xy[0]*xy[1])

Submission status: Accepted

Solution code:
N = int(input())
tmp = input().split(" ")

als = []


for t in tmp:
    als.append(int(t))

als.sort(reverse = True)

rec_w = 0
prev = 0
for a in als:
    if rec_w:
        #2つ目の辺を探す
        if a == prev:
            print(a*rec_w)
            exit()
        else:
            prev = a
    else:
        if a == prev:
            rec_w = a
            prev = 0
        else:
            prev = a

print(0)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  a=[]
  b=[]
  for x in l:
    if len(a)>0:
      if x==a[-1]:
        a.pop()
        b.append(x)
      else:
        a.pop()
        a.append(x)
    else:
      a.append(x)

  b.sort()

  if len(b)<2:
    return 0

  return b[-1]*b[-2]

print(main())

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
edge = [0, 0]
index = 0
tmp = 0
for i in range(0, N):
	if 2 <= index: break
	if tmp == A[i]:
		edge[index] = A[i]
		tmp = 0
		index += 1
	else:
		tmp = A[i]
print(edge[0]*edge[1])

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
num_list = sorted([ int(v) for v in input().split() ],reverse = True)

a, b = -1, -1
d = 0

for i in range(n-1):
	if num_list[i] != num_list[i+1]:
		d = 0
	else:
		if a != -1 and d == 0:
			b = num_list[i]
			ans = a*b
			break
		else:
			d += 1
			a = num_list[i]
			if d == 3:
				ans = a**2
				break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

length = sorted(length)
length.append(0)

temp = length[0]
c = 1

unique_n = []
square = []

for i in range(n):
    if temp == length[i+1]:
        c += 1
    
    else:
        if c >= 2 :
            unique_n.append(length[i-1])
        
        if c >= 4:
            square.append(length[i-1])
            
        
        c = 1
        temp = length[i+1]

if len(unique_n) <= 1:
    print(0)

else:
    if len(square) >= 1:
        print(max(unique_n[-1]*unique_n[-2],(square[-1])**2))
    
    else:
        print(unique_n[-1]*unique_n[-2])

Submission status: Accepted

Solution code:
from collections import Counter

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

ac = Counter(a)

cur_a = 0
res = 0
# print(ac)
for a,c in ac.items():
	# print(a,c)
	if c < 2:
		continue
	else:
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)
		if c >= 4:
			res = max(res,a*a)
	# print(cur_a,res)
print(res)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())
n = readi()
t = readl()
s = defaultdict(int)
for i in t:
    s[i] += 1

t1 = 0
t2 = 0
for i in sorted(s.items(),reverse=True,key=lambda x:x[0]):
    if t1 == 0:
        if i[1] >= 4:
            t1 = i[0]
            t2 = i[0]
            break
        elif i[1] >= 2:
            t1 = i[0]
    elif t2 == 0:
        if i[1] >= 2:
            t2 = i[0]
            break
print(t1 * t2)

Submission status: Accepted

Solution code:
from collections import *

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

filtered_a = sorted([i for i in Counter(a).most_common() if i[1] >= 2], reverse=True)

print(  0 if len(filtered_a) < 2
        else filtered_a[0][0] ** 2 if filtered_a[0][1] >= 4
        else filtered_a[0][0] * filtered_a[1][0])

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A).most_common()
B.sort(key= lambda x : -x[0])
L=[]
for i in B:
    if i[1]>=4:
        L.append(i[0])
        L.append(i[0])
    elif i[1]>=2:
        L.append(i[0])
    if len(L)==2:
        break
print(L[0]*L[1] if len(L)>=2 else 0)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
from collections import defaultdict
d=defaultdict(int)
for i in a:
    d[i]+=1
a=sorted(list(d.items()),key=lambda x:x[0])
p=0
ans=0
#print(a)
while a:
    c=a.pop()
    if c[1]<2:
        continue
    if c[1]>=4:
        ans=max(c[0]**2,ans)
        p=max(p,c[0])
    if c[1]>=2:
        if p==0:
            p=max(c[0],p)
        else:
            ans=max(p*c[0],ans)
            
print(ans)

Submission status: Accepted

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

def main():
    e = {}
    for n in A:
        if not n in e.keys():
            e[n] = 0
        e[n] += 1

    fe = {k:v for k, v in e.items() if v >= 2}
    se = sorted(fe.items(), key=lambda o: o[0], reverse=True)
    if len(se) == 0:
        ans = 0
    elif se[0][1] >= 4:
        ans = se[0][0] ** 2
    elif len(se) == 1:
        ans = 0
    else:
        ans = se[0][0] * se[1][0]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

from bisect import bisect_left, bisect_right


def count(seq, element):
    "Return number of occurrences of item"
    i = bisect_left(seq, element)
    j = bisect_right(seq, element)
    return seq[i:j].count(element)


def solve(N: int, A: "List[int]"):
    flag = 0
    ans = 1
    seta = sorted(list(set(A)))
    sa = sorted(A)
    for a in reversed(seta):
        if count(sa, a) >= 4:
            if flag == 1:
                ans *= a
                print(ans)
                return
            ans = a * a
            print(ans)
            return
        elif count(sa, a) >= 2:
            flag += 1
            ans *= a
            if flag == 2:
                print(ans)
                return
    print(0)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
from collections import Counter
N, *a = map(int, open(0).read().split())

c = Counter(a).most_common()
c = sorted([[i, j // 2] for i, j in c], reverse=True)
ans = 1
cnt = 0
for i in range(len(c)):
    a, v = c[i]
    while v > 0:
        ans *= a
        cnt += 1
        v -= 1
        if cnt == 2:
            break
    if cnt == 2:
      break
            
print(ans if cnt == 2 else 0)

Submission status: Accepted

Solution code:
from collections import Counter

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

A_cnt = list(Counter(A).items())
A_cnt.sort(key=lambda x:x[0], reverse=True)

sides = []
for i in range(len(A_cnt)):
  if A_cnt[i][1] >= 4:
    sides.extend([A_cnt[i][0]]*2)
  elif A_cnt[i][1] >= 2:
    sides.append(A_cnt[i][0])
  if len(sides) >= 2:
    break

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
edge = []
for key, value in a.items():
    if value > 1:
        edge.append(key)
    if value > 3:
        edge.append(key)
edge.sort()
print(edge[-1] * edge[-2] if len(edge) > 1 else 0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = {}
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
first = 0
for i, c in sorted(count.items(), key = lambda x: x[0], reverse = True):
    if c >= 4 and not first:
        print(i * i)
        exit()
    elif c >= 2:
        if first:
            print(first * i)
            exit()
        else:
            first = i
print(0)

Submission status: Accepted

Solution code:
N = int(input())
lst_A = list(map(int, input().split()))
lst_A.sort(reverse=True)
cur_a = -1
lst_ans = []


for a in lst_A:
    # 同じ長さの棒が二本あったとき
    if cur_a == a:
        lst_ans.append(a)
        cur_a = -1
        if len(lst_ans) == 2:
            break
    # 長さが変わり、その長さの一本目の処理
    else:
        cur_a = a


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

Submission status: Accepted

Solution code:
N = int(input())
lst_A = list(map(int, input().split()))
lst_A.sort(reverse=True)
cur_a = -1
lst_ans = []


for a in lst_A:
    if cur_a == a:
        lst_ans.append(a)
        cur_a = -1
        if len(lst_ans) == 2:
            break
    else:
        cur_a = a


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

Submission status: Accepted

Solution code:
N = int(input())
lst_A = list(map(int, input().split()))
lst_A.sort(reverse=True)
cur_a = -1
lst_ans = []


for i, a in enumerate(lst_A):
    if cur_a == a:
        lst_ans.append(a)
        cur_a = -1
        if len(lst_ans) == 2:
            break
    else:
        cur_a = a


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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
prev = -1
ans = []
for i, a in enumerate(A):
    if prev == a:
        ans.append(a)
        prev = -1
        if len(ans) == 2:
            break
    else:
        prev = a
if len(ans) == 2:
    print(ans[0] * ans[1])
else:
    print(0)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import math
from collections import defaultdict


int(input())
Ln = [0, 0]
mydict = defaultdict(lambda:0)
for a in list(map(int, input().split())):
  mydict[a] += 1
  if mydict[a] == 2:
    Ln.append(a)
    mydict[a] = 0
Ln = sorted(Ln,reverse=True)
print(Ln[0]*Ln[1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N=int(input())
a=collections.Counter(map(int, input().split())).items()
b=sorted([n for n in a if n[1] > 3], reverse=True)
c=sorted([n for n in a if n[1] > 1], reverse=True)
print(max([b[0][0] ** 2 if len(b) > 0 else 0, c[0][0] * c[1][0] if len(c) > 1 else 0]))

Submission status: Accepted

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

asum = {}
for a in A:
	if a not in asum:
		asum[a] = 1
	else:
		asum[a] += 1

#print(asum)

kouho = 0
for a in sorted(asum)[::-1]:
	if 4 <= asum[a]:
		if kouho:
			print(kouho * a)
		else:
			print(a * a)
		break
	elif 2 <= asum[a]:
		if kouho:
			print(kouho * a)
			break
		else:
			kouho = a
else:
	print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
A = A + [0,0,0,0]
for i,a in enumerate(A):
    if a == A[i+1]:
        ans = a
        i = i+2
        break
for j,a in enumerate(A[i:],i):
    if a == A[j+1]:
        ans *= a
        break
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def read_input():
    n = int(input())
    alist = map(int, input().split())

    return n, alist


def submit():
    n, alist = read_input()

    sides = defaultdict(int)
    for a in alist:
        sides[a] += 1

    sides = list(sides.items())
    sides.sort(key=lambda x: x[0], reverse=True)

    sides_four = [s for s in sides if s[1] >= 4]
    square = 0
    if sides_four:
        square = sides_four[0][0] * sides_four[0][0]

    sides_two = [s for s in sides if s[1] >= 2]
    rectangle = 0
    if len(sides_two) >= 2:
        rectangle = sides_two[0][0] * sides_two[1][0]

    print(max(square, rectangle))


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
from functools import reduce
import collections
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = list(int(_) for _ in input().split())
    d = collections.defaultdict(int)
    for i in range(N):
        d[a[i]]+=1

    e_1 = 0
    e_2 = 0
    for d_i in sorted(d.items(),key=lambda x:-x[0]):
        if d_i[1] >= 4 and e_1 == 0:
            e_1 = d_i[0]
            e_2 = d_i[0]
            break
        elif d_i[1] >= 2 and e_1 == 0:
            e_1 = d_i[0]
        elif d_i[1] >= 2 and e_2 == 0:
            e_2 = d_i[0]
            break
    print(e_1 * e_2)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

E.sort(reverse=True)
pre = 0
nums = []
for e in E:
    if pre == e:
        nums.append(e)
        pre = 0
    else:
        pre = e
    if len(nums) == 2:
        print(nums[0]*nums[1])
        quit()
print(0)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
c=list(Counter(A).most_common())
c.sort(key=lambda x:x[0],reverse=True)
w=0
h=0
for a,b in c:
    if(b>=4):
        if(w==0):
            w=a
            h=a
            break
        else:
            h=a
            break
    if(b>1):
        if(w==0):
            w=a
        else:
            h=a
            break
print(w*h)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import collections

n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
l = c.most_common()
L = [ l[i] for i in range(len(l)) if l[i][1] >= 2 ]
b = sorted(L,reverse = True)
if len(b) == 0:
    ans = 0
elif len(b) == 1 and b[0][1] < 4:
    ans = 0
else:
    if b[0][1] >= 4:
        ans = b[0][0]**2
    else:
        ans = b[0][0]*b[1][0]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from math import gcd
except Exception:
    from fractions import gcd
from collections import Counter

def solve(N: int, A: "List[int]"):
    tmp = [(i,c) for i, c in Counter(A).items() if 2 <= c]
    tmp = sorted(tmp, reverse=True)
    if 2 <= len(tmp):
        return (tmp[0][0] ** 2) if 4 <= tmp[0][1] else (tmp[0][0] * tmp[1][0])
    else:
        return 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]"
    result = solve(N, A)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

d = dict()

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

d2 = sorted(d.items(), reverse=1)

first = 0
for i,j in d2:
    if d[i] >= 2:
        if first == 0 and d[i] >= 4:
            print(i**2)
            exit()
        elif first != 0:
            print(first*i)
            exit()
        else:
            first = i
print(0)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
ct = list(Counter(A).items())
flg = 0
ct. sort(key=lambda x: x[0], reverse=True)
for i in ct:
    if i[1] >= 4 and flg == 0:
        flg = 2
        ans = i[0]**2
        break
    if i[1] >= 2 and flg == 0:
        flg = 1
        ans = i[0]
    elif i[1] >= 2 and flg == 1:
        flg = 2
        ans *= i[0]
        break

if flg != 2:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


N = int(input())
A = [int(i) for i in input().split()]

A.sort()
len_dic = {}
for a in A:
    if a in len_dic.keys():
        len_dic[a] += 1

    else:
        len_dic[a] = 1

ans = [0,0]
for k, v in sorted(len_dic.items(),key=lambda x:-x[0]):
    if v >= 4 and ans[0] == 0:
        ans = [k,k]
    elif v >= 2:
        if ans[0]==0:
            ans[0] = k
        elif ans[1] == 0:
            ans[1] = k

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

Submission status: Accepted

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

A.sort(reverse=True)

check = int(2e9)
bar = []
for i in A:
    if check == i:
        bar.append(i)
        check = int(2e9)
    else:
        check = i
    if len(bar) == 2:
        break

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

Submission status: Accepted

Solution code:
import itertools
import heapq
import functools
import operator

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

desc_lengths = list(
  itertools.chain(
    *(
      [length, length] if count >= 4 else [length] if count >= 2 else []
      for (length, count)
      in [
        (length, sum(1 for _ in iter))
        for (length, iter)
        in itertools.groupby(sorted(a))
      ]
    )
  )
)
print(functools.reduce(operator.mul, heapq.nlargest(2, desc_lengths)) if len(desc_lengths) >= 2 else 0)

Submission status: Accepted

Solution code:
n  = int(input())

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

nums = {}
for i in a:
  if i in nums:
    nums[i] += 1
  else:
    nums[i] = 1
    
nums_list_sorted = sorted(nums.items(), reverse=True)

a = 0
b = 0
# 最大のが4つ以上とかを考慮するのが抜けてた
for i in range(len(nums_list_sorted)):
  if nums_list_sorted[i][1] >= 2:
    if a == 0:
      a = nums_list_sorted[i][0]
      if nums_list_sorted[i][1] >= 4:
        b = a
        break
      #del nums_list_sorted[i]
    else:
      b = nums_list_sorted[i][0]
      break

print(a*b)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
side=[]
i=0
while i<n-1:
  if A[i]==A[i+1]:
    side.append(A[i])
    i+=2
  else:
    i+=1
print(0 if len(side)<2 else side[0]*side[1])

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))+[0]
arr=sorted(arr, reverse=True)
ans1=0
ans2=0
ans3=0
count=1
for i in range(n):
  if arr[i]!=arr[i+1]:
    if count>=2:
      if ans1==0:
        ans1=arr[i]
      elif ans2==0:
        ans2=arr[i]      
      if count>=4:
        if ans3==0:
          ans3=arr[i]
    count=1
  else:
    count+=1
print(max(ans1*ans2,ans3**2))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

sides = list(bars.keys())
sides.sort(reverse=True)
ans = 0
rect = []
for side in sides:
    if bars[side] >= 4:
        if rect == []:
            ans = side * side
        else:
            ans = rect[0] * side
        break
    elif bars[side] >= 2:
        rect.append(side)
        if len(rect) == 2:
            ans = rect[0] * rect[1]
            break
print(ans)

Submission status: Accepted

Solution code:
import collections

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

l = collections.Counter(a)
bars = filter(lambda x: l[x] >= 2 , l)
bars_ = sorted(bars, reverse=True)



if len(list(bars_)) <= 1:
    s = 0
else:
    if l[bars_[0]] >= 4:
        s = bars_[0] ** 2
    else:
        s = bars_[0] * bars_[1]

print(s)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.items():
    if count[1] >= 2:
        B.append(count)
B.sort(reverse=True)
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:
n = int(input())

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

d = dict()

for x in data:
    if d.__contains__(x):
        d[x]+=1
    else:
        d[x]=1
data = [list(item) for item in d.items()]
data.sort(reverse=True,key= lambda x:x[0])
a = 0
b = 0
i = 0
for i in range(len(data)):
    if data[i][1]>=2:
        data[i][1]-=2
        a=data[i][0]
        break
for j in range(i,len(data)):
    if data[j][1]>=2:
        data[j][1]-=2
        b=data[j][0]
        break
print(a*b)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(item) for item in input().split()], reverse=True)

l = 0
edge = []
while l < n-1:
    if a[l] == a[l+1]:
        edge.append(a[l])
        l += 2
    else:
        l += 1
    if len(edge) >= 2:
        break
if len(edge) >= 2:
    print(edge[0] * edge[1])
else:
    print(0)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc071/tasks/arc081_a

import itertools
import collections
import bisect

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

    c = collections.Counter(A)
    a = 0
    b = 0
    c = sorted(c.items(), key=lambda i: i[0], reverse=True)
    # print(c)
    for item in c:
        # print(item)
        if a == 0:
            if item[1] >= 4:
                a = item[0]
                b = item[0]
                break
            elif item[1] >= 2:
                a = item[0]
        else:
            if item[1] >= 2:
                b = item[0]
                break
    print(a * b)


if __name__ == '__main__':
    main()