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:
from collections import Counter

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

c = Counter(A)
ans = []
for k, v in sorted(c.items(), reverse=True):
    if v > 3 and len(ans) == 0:
        ans.append(k)
        ans.append(k)
    elif v > 1:
        ans.append(k)
    if len(ans) == 2:
        break

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

Submission status: Accepted

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

w = 0
while len(a) > 1:
    if a[-1] == a[-2]:
        w = a[-1]
        a.pop()
        a.pop()
        break
    else:
        a.pop()
h = 0
while len(a) > 1:
    if a[-1] == a[-2]:
        h = a[-1]
        a.pop()
        a.pop()
        break
    else:
        a.pop()

print(w*h)
exit(0)

Submission status: Accepted

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

a_sorted = sorted(a, reverse=True)
x = 0
y = 0

while True:
    if len(a_sorted) <= 1:
        break
    max = a_sorted[0]
    if x != 0 and y != 0:
        break
    if a_sorted[1] == max:
        if x == 0:
            x = max
        else:
            y = max
        a_sorted.remove(max)
        a_sorted.remove(max)
    else:
        a_sorted.remove(max)
print(x * y)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = Counter(map(int, input().split()))
h, w = 0, 0
for k, v in sorted(a.items(), key=lambda x: -x[0]):
    if v >= 4 and not h and not w:
        h, w = k, k
        break
    elif v >= 2:
        if not h:
            h = k
        elif not w:
            w = k
            break

print(h * w)

Submission status: Accepted

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

a.sort()
maxs = []
for i in range(2):
	max_1 = a.pop()
	while True:
		max_2 = a.pop()
		if max_1 == max_2:
			maxs.append(max_1)	
			break
		max_1 = max_2
		if len(a) == 0:
			print(0)
			exit()
print(maxs[0]*maxs[1])

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    a_element = list(set(a_list))
    a_element.sort(reverse=True)

    counter = Counter(a_list)

    ans = []
    xy = []
    for i in a_element:
        if counter[i] >= 4:
            ans.append(i * i)
        if counter[i] >= 2:
            xy.append(i)
        if len(xy) == 2:
            ans.append(xy[0] * xy[1])
            break
    if len(ans) == 0:
        print(0)
    else:
        print(max(ans))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
l=map(int,input().split())
o=sorted(filter(lambda x:x[1]>=2,Counter(l).items()))

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

Submission status: Accepted

Solution code:
from collections import Counter

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

cntr = Counter(A)


key_list = list(cntr.keys())

key_list.sort(reverse=True)

ans_cand = []
ans = 0
for key in key_list:
    if cntr[key] >= 4:
        ans_cand.append(key)
    if cntr[key] >= 2:
        ans_cand.append(key)
        
if len(ans_cand) < 2:
    ans = 0
else:
    ans = ans_cand[0] * ans_cand[1]
    
print(ans)

Submission status: Accepted

Solution code:
def inpl():
    return input().split()

n = int(input())
a = list(map(int, inpl()))
a = sorted(a, reverse=True)

ans = 1
cnt = 0
bf = a[0]
i = 1
while (i < n) and (cnt < 2):
    a_i = a[i]
    if bf == a_i:
        ans *= a_i
        bf = -1
        cnt += 1
    else:
        bf = a_i
    i += 1
print(ans if cnt == 2 else 0)

Submission status: Accepted

Solution code:
N = int(input())
d = {}

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

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

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

l1 = -1
l2 = -1

for i in range(N) :
    if s1[i][1] >= 4 and l1 == -1 and l2 == -1:
        l1, l2 = s1[i][0], s1[i][0]
        break
    elif s1[i][1] >= 2 and l1 == -1 :
        l1 = s1[i][0]
    elif s1[i][1] >= 2 and l1 != -1 :
        l2 = s1[i][0]
        break
        
if l1 == -1 or l2 == -1 :
    print("0")
else :
    print(l1 * l2)

Submission status: Accepted

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

a, b = 0, 0
idx = 0
while idx < len(A) - 1:
    if A[idx] == A[idx + 1]:
        if a == 0:
            a = A[idx]
            idx += 1
        else:
            b = A[idx]
            break

    idx += 1

print(a * b)

Submission status: Accepted

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

from collections import Counter 

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

# 各数値ごとに数を集計
AN_dict = Counter(AN)
AN_list = sorted(AN_dict.items())

hen1 = 0
hen2 = 0
# 低い値から見ていって順次最大に更新していく
for AN in AN_list:
    # 正方形
    if AN[1] >= 4:
        hen1 = AN[0]
        hen2 = AN[0]
    # 長方形
    elif AN[1] >= 2:
        hen2 = hen1
        hen1 = AN[0]      

print(hen1 * hen2)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
d={}
chk=0
for i in a[::-1]:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    if d[i]==4:
        print(i*i)
        exit()
    if d[i]==2 and chk==1:
        for j in d:
           if i!=j and d[j]>=2:
                print(i*j)
                exit()
    elif d[i]==2:
           chk=1
   
print(0)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=1
count=2
i=1
while i<N:
    if count==0:
        break
    if a[i]==a[i-1]:
        ans*=a[i]
        count-=1
        i+=2
    else:
        i+=1    
if count==0:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:

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

a.sort()
a.reverse()

count=1
ans=[]

for i in range(N-1):
    if a[i]==a[i+1]:
        count+=1
    else:
        if count//2>0:
            tmp=[a[i], count//2]
            ans.append(tmp)
        count=1
else:
    if count//2>0:
        tmp=[a[i], count//2]
        ans.append(tmp)
        
ans.sort()
ans.reverse()

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
max1=0;max2=0
count=0
for i in range(n-3):
  if a[i]==a[i+1]:
    max1=a[i]
    a[i+1]=0
    count=i+1
    break
if count==0:
  print(0)
  exit()
for j in range(count,n-1):
  if a[j]==a[j+1]:
    max2=a[j]
    break
print(max1*max2)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

first = 0
second = 0
square = 0

for i in l:
    k, v = i[0], i[1]
    if v >= 4:
        if square == 0:
            square = k
        if first == 0:
            first = k
        elif second == 0:
            second = k
    elif v >= 2:
        if first == 0:
            first = k
        elif second == 0:
            second = k
print(max(first * second, square * square))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
dic={}
mx=[0,0]
for x in a:
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
    if dic[x]==2:
        dic[x]=0
        for i in range(2):
            mx.sort()
            if mx[i]<x:
                mx[i]=x
                break
print(mx[0]*mx[1])

Submission status: Accepted

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

l = None
for k,v in sorted(ctr.items(),reverse=True):
    if l:
        if v >= 2:
            print(l*k)
            exit()
    else:
        if v >= 4:
            print(k*k)
            exit()
        elif v >= 2:
            l = k
print(0)

Submission status: Accepted

Solution code:
# coding: utf-8
n=int(input())
a=list(map(int,input().split()))
dic={}
mx=[0,0]
for x in a:
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
    if dic[x]==2:
        dic[x]=0
        for i in range(2):
            mx.sort()
            if mx[i]<x:
                mx[i]=x
                break
print(mx[0]*mx[1])

Submission status: Accepted

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

A = sorted(A, reverse = True)
pair = 0
ans = []

i = 0
while i < N - 1:
    if A[i] == A[i + 1]:
        ans.append(A[i])
        pair += 1
        i += 2
    else:
        i += 1
    if pair == 2:
        print(ans[0] * ans[1])
        break

if pair < 2:
    print(0)

Submission status: Accepted

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

import collections

c = collections.Counter(A)
xs = [x for x, n in c.items() if n >= 2]
xs.sort()

if len(xs) >= 1 and c[xs[-1]] >= 4:
    print(xs[-1] ** 2)
elif len(xs) >= 2:
    print(xs[-1] * xs[-2])
else:
    print(0)

Submission status: Accepted

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

for a in A:
    c[a] += 1
    if c[a] % 2 == 0:
        L = [a, top1, top2]
        L.sort()
        top1 = L[2]
        top2 = L[1]
print(top1 * top2)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
import collections
k=list(collections.Counter(a).items())
x=[k[i][0] for i in range(len(k)) if k[i][1]>=2]
y=[k[i][0] for i in range(len(k)) if k[i][1]>=4]
x.sort()
y.sort()
if len(x)>1 and len(y)>1:
    print(max(x[-1]*x[-2], y[-1]**2))
elif len(x)>1:
    print(x[-1]*x[-2])
else:
    print(0)

Submission status: Accepted

Solution code:
N=int(input())

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

a.sort(reverse=True)
TATE=0
count=0

for i in range(N):
  if i!=N-1 and a[i]==a[i+1] and count!=1:
    if TATE==0:
      TATE=a[i]
      i+=1
      count=1
    else:
      YOKO=a[i]
      print(TATE*YOKO)
      exit()
  else:
    count=0

print(0)

Submission status: Accepted

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

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

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

C = []
for b in B.keys():
    if B[b] >= 4:
        C.append(b)
        C.append(b)
    elif B[b] >= 2:
        C.append(b)

C.sort(reverse=True)

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
input_list = sorted([int(i) for i in input().split()])
inupt_dict = Counter(input_list)
sorted_input_dict = sorted(dict(filter(lambda x:x[1]>1, inupt_dict.items())).items(), key=lambda x: x[0], reverse=True)
result = 1

if sorted_input_dict == []:
    result = 0
else:
    result *= sorted_input_dict[0][0]
    if sorted_input_dict[0][1] > 3:
        result *= sorted_input_dict[0][0]
    else:
        result *= sorted_input_dict[1][0]

print(result)

Submission status: Accepted

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

t = sorted(set(a), reverse=True)
rec = []
flag = False
for k in t:
    if dic[k] >= 4 and len(rec) == 1:
        print(k * rec[0])
        flag = True
        break
    elif dic[k] >= 4:
        print(k * k)
        flag = True
        break
    elif dic[k] >= 2 and len(rec) == 1:
        print(k * rec[0])
        flag = True
        break
    elif dic[k] >= 2:
        rec.append(k)

if not flag:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter

a = input()
a = map(int,input().split())
a = Counter(a)
li = []
for i,v in sorted(a.items(),key = lambda x: x[0],reverse = True):
    if(v >= 2 and v < 4):
        li.append(i)
    elif(v >= 4):
        li.extend([i,i])
    if(len(li) >= 2):
        print(li[0]*li[1])
        exit()
print(0)

Submission status: Accepted

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

# A.sort()
# print(B)

A = list(map(int, input().split()))
A.sort()
A.reverse()
# print(A)

tapu = 0
tapi = 0

i = 0
while i + 1 < N:
    if A[i] == A[i + 1]:
        if tapu == 0:
            tapu = A[i]
            i += 1
        elif tapi == 0:
            tapi = A[i]
            i += 1
            break
    i += 1

ans = tapu * tapi
print(ans)

Submission status: Accepted

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

A.sort(reverse = True)

T = []
for i in range(N-1):
    if i > 1 and  A[i] == A[i-1] and not(A[i] == A[i-2]): continue
    if i == 1 and A[i] == A[i-1]: continue

    if A[i] == A[i+1]:
        T.append(A[i])
    if len(T) >= 2: break

if len(T) < 2: print(0)
else: print(T[0]*T[1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
dict = {}
for i in a:
    if(i in dict):
        dict[i] += 1
    else:
        dict[i] = 1
dict = sorted(dict.items(), reverse = True)
for i in dict:
    if(i[1] >= 2):
        if(ans):
            print(ans*i[0])
            exit()
        else:
            ans = i[0]
        if(i[1] >= 4):
            print(ans*i[0])
            exit()
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
input();a=sorted(Counter(map(int,input().split())).most_common())[::-1];c=b=0
for i in range(len(set(a))):
    if b and c:break
    if a[i][1]>3 and a[i][0]*c<a[i][0]**2:b=c=a[i][0]
    elif a[i][1]>1:b,c=c,a[i][0]
print(c*b)

Submission status: Accepted

Solution code:
def m():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    edge = []
    tmp = 0
    for i in range(N):
        if A[i] == tmp:
            edge.append(tmp)
            tmp = 0
        else:
            tmp = A[i]
    if len(edge) < 2:
        return 0
    else:
        return edge[-1] * edge[-2]

print(m())

Submission status: Accepted

Solution code:
def c_make_a_rectangle(N, A):
    from collections import Counter
    count = Counter(A)  # リストの要素が何回現れたか
    cond = []  # 同じ長さのものが2個ある棒の長さ
    for k, v in count.items():
        cond.extend([k] * (v // 2))  # 2本の組を何個作れるか
    if len(cond) <= 1:
        return 0  # 長方形を作れない
    cond = sorted(cond, reverse=True)
    ans = cond[0] * cond[1]  # 長いもの2組を使う
    return ans

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

Submission status: Accepted

Solution code:
def judge(lst):
	x = 0
	y = 0
	memo = 0
	for i in range(0, len(lst)-1):
		if lst[i] == lst[i+1]:
			x = lst[i]
			memo = i
			break
	for i in range(memo+2, len(lst)-1):
		if lst[i] == lst[i+1]:
			y = lst[i]
			break
	return x*y

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

print judge(A)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
Adict = {}
for i in A:
    if i in Adict:
        Adict[i]=Adict[i]+1
    else:
        Adict.update({i:1})
B = [0, 0]
for i in Adict.keys():
    if Adict[i] >= 2:
        B.append(i)
    if Adict[i] >= 4:
        B.append(i)
B.sort()
print(B[-1]*B[-2])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
B = [0, 0]
for i in A.keys():
    if A[i] >= 2:
        B.append(i)
    if A[i] >= 4:
        B.append(i)
B.sort()
print(B[-1]*B[-2])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
rod = {}
for i in A:
    if i in rod:
        rod[i] += 1
    else:
        rod[i] = 1
if len([i for i in rod.values() if i >= 2]) < 2:
    print(0)
else:
    length4 = [k for k, v in rod.items() if v >= 4]
    length4.sort()
    length2 = [k for k, v in rod.items() if v >= 2]
    length2.sort()
    if len(length4) > 0 and length4[-1] == length2[-1]:
        print(length4[-1]**2)
    else:
        print(length2[-2] * length2[-1])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
data=Counter(a)
two=[0]*n
four=[0]*n
for i,j in data.items():
    if 2<=j<=3:
        two.append(i)
    elif 4<=j:
        four.append(i)
two.sort()
two.reverse()
four.sort()
four.reverse()
print(max(four[0]*four[0],four[0]*four[1],two[0]*two[1],two[0]*four[0]))

Submission status: Accepted

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

C = list(dict(Counter(A)).items())
C.sort(reverse=True)
use = []
ans = 0
for length, num in C:
    if num >= 4:
        ans = max(length**2, ans)
        use.append(length)
    elif num >= 2:
        use.append(length)

    if len(use) >= 2:
        ans = max(ans, use[-1]*use[-2])

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = sorted(Counter(A).most_common(),reverse=True)
D = list(filter(lambda x: x[1]>=2,C))
if len(D)<2:
    print(0)
else:
    print(D[0][0]**2 if D[0][1]>=4 else D[0][0]*D[1][0])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)
a = b = 0
for k,v in sorted(ctr.items(),reverse=True):
    if v == 1: continue
    if not a:
        a = k
        if v >= 4:
            print(a*a)
            exit()
    elif not b:
        b = k
        print(a*b)
        exit()
print(0)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    n = int(input())
    a = Counter(list(map(int, input().split())))
    sorted_a = sorted(a.items(), key=lambda x: (x[0], x[1]), reverse=True)
    squares = [key for key, value in sorted_a if value >= 4]
    rectangles = [key for key, value in sorted_a if value >= 2]

    if (len(squares) >= 1) and (len(rectangles) >= 2):
        print(max(squares[0] ** 2, rectangles[0] * rectangles[1]))
    elif (len(squares) >= 1) and (len(rectangles) < 2):
        print(squares[0] ** 2)
    elif len(rectangles) >= 2:
        print(rectangles[0] * rectangles[1])
    else:
        print(0)

Submission status: Accepted

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

a.sort(reverse=True)
for i in a:
    a_dic[i] = a_dic.get(i, 0) + 1

h = [0, 0]
for i in range(2):
    for j in a:
        if a_dic[j] >= 2:
            h[i] = j
            a_dic[j] -= 2
            break

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

Submission status: Accepted

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

c = 0
t = 0

for k in B:
    if k*k > c*t and B[k] >= 4:
        c = k
        t = k
    elif c >= k > t and B[k] >= 2:
        t = k
    elif k > c and B[k] >= 2:
        t = c
        c = k

print(t*c)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split()))).most_common()
fA = filter(lambda x: x[1] >= 2, A)
sA = sorted(fA,reverse=True)
if len(sA) < 2:
    print(0)
else:
    print(sA[0][0]**2 if sA[0][1]>=4 else sA[0][0]*sA[1][0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N=int(input())
A=[int(x) for x in input().split()]
dict=defaultdict(int)

for i in range(N):
  dict[A[i]]+=1

ans=[]
for x,y in dict.items():
  if 2 <= y < 4:
    ans.append(x)
  elif y>=4:
    ans.append(x)
    ans.append(x)
  else:
    continue
if len(ans) < 2:
  print(0)
else:
  ans.sort(reverse=True)
  print(ans[0]*ans[1])

Submission status: Accepted

Solution code:
N=int(input())
d,t={},[]
for i in list(map(int,input().split())):
    d[i]=d.get(i,0)+1
d=sorted(list(d.items()))
for j in range(len(d)):
    k=len(d)-j-1
    if d[k][1]>3:
        if len(t)==0:
            print((d[k][0])**2)
            exit()
    if d[k][1]>1:
        t.append(d[k][0])
        if len(t)==2:
            print(t[0]*t[1])
            exit()
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

def max_rectangle(sticks):
    # sticks ordered by length, only if there's at least two of a kind
    valid_lengths = list(filter(lambda x: sticks[x] >= 2, sorted(sticks, reverse=True)))
    if valid_lengths and sticks[valid_lengths[0]] >= 4:
        return valid_lengths[0] ** 2
    if len(valid_lengths) >= 2:
        return valid_lengths[0] * valid_lengths[1]
    return 0


if __name__ == '__main__':
    _ = input()
    sticks = Counter(map(int, input().split()))
    print(max_rectangle(sticks))

Submission status: Accepted

Solution code:
def c_make_a_rectangle(N, A):
    from collections import Counter
    count = Counter(A)  # リストの要素が何回現れたか

    cond = []  # 同じ長さのものが2個ある棒の長さ
    for k, v in count.items():
        if v == 1:  # 1個しかない棒では長方形を作れない
            continue
        else:
            cond.extend([k] * (v // 2))
    if len(cond) <= 1:
        return 0  # 長方形を作れない
    cond = sorted(cond, reverse=True)
    ans = cond[0] * cond[1]  # 長いもの2組を使う
    return ans

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

Submission status: Accepted

Solution code:
d = {}
_ = input()
for x in input().split():
    x = int(x)
    d[x] = d.get(x, 0) + 1
p = []
for k, v in d.items():
    if v >= 4: p.append(k)
    if v >= 2: p.append(k)
if len(p) < 2: print(0)
else:
    p.sort(reverse=True)
    print(p[0] * p[1])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A,reverse=True)
first = 0
bef = 0
count = 0
for i in A:
    if count == 0 or i == bef:
        count += 1
    if count >= 2:
        if first != 0:
            print(first*i)
            exit()
        else:
            first = i
            count = 0
    if bef != i:
        count = 1
    bef = i
print(0)

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
arr01=arr_data[1]

hash01={}

for v in arr01:
    
    cnt=hash01.setdefault(int(v),0)+1
    
    hash01[int(v)]=cnt
    
#print(hash01)  

menseki01=None
menseki02=None

a=None
b=None

for k, v in sorted(hash01.items(), reverse=True):
    
#    print(k,v)
    
    if(v>=2 and a is None):
    
    
#        print("--chk01")
        a=k
        
    elif(v>=2 and a is not None and b is None):
    
#        print("--chk02")
        b=k
        menseki02=a*b
    
    if(v>=4 and menseki01 is None):
        
        menseki01=k*k
        
#print(menseki01,menseki02,a,b)        
if menseki01 is None and menseki02 is None:
     
     print(0)


elif menseki01 is None and menseki02 is not None:

     print(menseki02)

elif menseki01 is not None and menseki02 is None:
     
    
     print(menseki01)

elif menseki01 is not None and menseki02 is not None:
     
    
    if menseki01 <= menseki02:

        print(menseki02)
        
    else:
        print(menseki01)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
x,y,z = collections.Counter(a),[0],[0,0]
for i in x.keys():
	if x[i]>=4:
		y.append(i)
	if x[i]>=2:
		z.append(i)
y,z = sorted(y),sorted(z)
print(max(y[-1]**2,z[-1]*z[-2]))

Submission status: Accepted

Solution code:
N = int(input())
num = list(map(int,input().split()))
dict = {}
dist = []
for i in range(N):
  if num[i] not in dict:
    dict[num[i]] = 1
    dist.append(num[i])
  else:
    dict[num[i]] += 1
dist.sort(reverse=True)
rec = []    
for j in range(len(dist)):
  if 4 <= dict[dist[j]]:
    rec.append(dist[j])
    rec.append(dist[j])
    break
  elif 2<= dict[dist[j]]:
    rec.append(dist[j])
  if 2 <= len(rec):
    break
if len(rec) < 2:
  print(0)
else:
  print(rec[0]*rec[1])

Submission status: Accepted

Solution code:

N=int(input())
Set=set()
List=[]
Data=list(map(int,input().split()))

for i in range(N):
    if Data[i] not in Set:
        Set.add(Data[i])
    else:
        Set.remove(Data[i])
        List.append(Data[i])
if len(List)<2:print("0")
else:
    List=sorted(List)
    print(List[-1]*List[-2])

Submission status: Accepted

Solution code:
n = int(input())
li = set()
lis = []
l = list(map(int,input().split()))
for i in range(n):
    if l[i] not in li:
        li.add(l[i])
    else:
        lis.append(l[i])
        li.remove(l[i])
if len(lis) < 2:
    print("0")

else:
    lis = sorted(lis)
    print(lis[-1] * lis[-2])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
cnt = {}
tmp = None
for a in A:
    cnt[a] = cnt.get(a, 0) + 1 
    if cnt[a]>=4:
        print(a*a)
        break
    if cnt[a]==2:
        if tmp:
            print(tmp*a)
            break
        tmp=a
else:
    print(0)

Submission status: Accepted

Solution code:
import collections

n = int(input())

array = [int(x) for x in input().split()]

count = collections.Counter(array)
count_values = list(count.values())
if count_values.count(1) >= len(count_values) - 1:
    print(0)
else:
    count = list(sorted(count.items(), key=lambda x: x[0], reverse=True))
    res_count = []
    for i in count:
        if i[1] != 1:
            res_count.append(i)
    if res_count[0][1] >= 4:
        print(res_count[0][0] ** 2)
    else:
        print(res_count[0][0] * res_count[1][0])

Submission status: Accepted

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

a.sort()
a.reverse()

flag=False
for i in range(n-1):
	if flag:
		flag=False
		continue
	if a[i]==a[i+1]:
		ans.append(a[i])
		flag=True
		if len(ans)==2:
			break
if len(ans)<2:
	print(0)
else:
	print(ans[0]*ans[1])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
j = Counter(list(map(int, input().split())))
l = r = 0
for m, b in sorted(list(j.items()), key=lambda x: -x[0]):
    if b > 3 and (not l and not r):
        print(m * m)
        exit()
    if b > 1 and (not l or not r):
        if not l:
            l = m
        elif not r:
            r = m
print(l * r)

Submission status: Accepted

Solution code:
from collections import *
n=int(input())
a=list(map(int,input().split()))
b=sorted(set(a))[::-1]
d=defaultdict(int)
wid=0
hei=0
for i in a:
  d[i]+=1
for i in b:
  if(d[i]>3):
    if(wid==0):wid,hei=i,i
    else:hei=i
    break
  elif(d[i]>1):
    if(wid==0):wid=i
    else:
      hei=i
      break
print(wid*hei)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
data=collections.Counter(a)
a=[]
a_4=[]
for i,j in data.items():
    if 4<=j:
        a_4.append(i)
    elif 2<=j:
        a.append(i)
x=y=z=0
a.sort()
a.reverse()
a_4.sort()
a_4.reverse()

if len(a_4)==0 and len(a)<=1:
    print(0)
    exit()
if 1<=len(a_4) and 1<=len(a):
    x=a[0]*a_4[0]
if 2<=len(a):
    y=a[0]*a[1]
if 1<=len(a_4):
    z=a_4[0]*a_4[0]
print(max(x,y,z))

Submission status: Accepted

Solution code:
import sys
line = sys.stdin.readline
n = int(line())
a = list(map(int, line().split()))
h = 0
from collections import Counter
counter = Counter(a)
for key in sorted(counter.keys(), reverse = True):
    if h and counter[key] >= 2:
        print(h * key)
        sys.exit()
    if counter[key] >= 4:
        print(key * key)
        sys.exit()
    if counter[key] >= 2:
        h = key
print(0)

Submission status: Accepted

Solution code:
import sys
line = sys.stdin.readline

n = int(line())
a = list(map(int, line().split()))
a.sort(reverse=True)
summ = 0
h = 0
for i in range(len(a)):
    summ += 1
    if i and a[i] != a[i-1]:
        summ = 1
    if summ == 2:
        if h:
            print(a[i] * h)
            sys.exit()
        else:
            h = a[i]
    if summ == 4:
        print(a[i] * a[i])
        sys.exit()
print(0)

Submission status: Accepted

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


x1=0
x2=0
i0=0
for i in a:
  if i==i0 and x1==0 and x2==0:
    x1=i
    i0=0
  elif i==i0 and x2==0:
    x2=i
    i0=0
  else:
    i0=i
print(x1*x2)

Submission status: Accepted

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

for k,v in c.items():
    if v >= 2:
        num.append([k,v])

if len(num) ==0:
    print(0)
else:
    k = sorted(num,reverse=True)
    l = k[0][0]
    s = k[1][0]
    if k[0][1] >= 4:
        print(l*l)
    else:
        print(l*s)

Submission status: Accepted

Solution code:
import collections
import sys
N = int(input())
A = map(int,input().split(" "))
count_input = collections.Counter(A)
del count_input[" "]
judge = True
m1 = 0
m2 = 0
count = 0
temp_max=0
for k,v in sorted(count_input.items(),reverse = True):#,reverse = True
    # print(k)
    if temp_max<=k:
        temp_max=k
    # if m1 < int(k) and int(v) >= 2:
        # m2 = m1
        # m1 = int(k)
    if int(v) >= 4 and temp_max<=k:
        print(k**2)
        sys.exit()
    elif int(v) >= 2:
        m2 = m1
        m1 = int(k)
        count += 1
        if count ==2:
            print(m1*m2)
            sys.exit()
print("0")