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:
# C - Make a Rectangle

import collections

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

# 2ペア以上ある棒のうち長い方から4本取ればよい

A_count = collections.Counter(A)
A_count = A_count.most_common()
pairs = [A_count[idx] for idx in range(len(list(A_count))) if A_count[idx][1] >= 2]
pairs = sorted(pairs, key = lambda x: x[0], reverse = True)

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

Submission status: Accepted

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

for i in nums:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

dic_sort = sorted(dic.items(),reverse=True)

side1 = 0

for side,num in dic_sort:
    if num>=4:
        if side1==0:
            print(side**2)
            exit()
        else:
            print(side1*side)
            exit()
    elif num >=2:
        if side1 ==0:
            side1=side
        else:
            print(side1*side)
            exit()
print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
B = []
cur = 0
for i in range(1,N):
    if A[i]!=A[i-1]:
        n = i-cur
        if n>=2:
            B.append((A[i-1],n))
        cur = i
if N-cur>=2:
    B.append((A[-1],N-cur))
if len(B)<2:
    print(0)
else:
    if B[0][1]>=4:
        s = B[0][0]**2
    else:
        s = B[0][0]*B[1][0]
    print(s)

Submission status: Accepted

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    counter_as_ = collections.Counter(as_)
    available_edge = [item for item in counter_as_.items() if item[1] >= 2]
    available_edge.sort()
    
    if len(available_edge) == 0:
        print(0)
        exit()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.sort(reverse=True)

l = 0
w = 0

while len(A)>=2:
    temp = A.pop(0)
    if temp==A[0]:
        if l==0:
            l = A.pop(0)
        else:
            w = A.pop(0)
            break

print(l*w)

Submission status: Accepted

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

A.sort(reverse=True)
E = [0,0]

j = 0
for i in range(n):
    if E[j] == A[i]:
        j += 1
        if j == 1:
            continue
        else:
            break
    E[j] = A[i]
    
print(E[0]*E[1])

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
swi = 0
s = [0, 0]
i = 0
while i < len(a) - 1:
    if a[i] == a[i + 1]:
        s[swi] = a[i]
        i += 1
        swi += 1
        if swi == 2:
            break
    i += 1

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

Submission status: Accepted

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

D = dd(int)
for a in A:
  D[a] += 1
a = 0
b = 0

for k, v in D.items():
  if v != 1:
    if k > b:
      b = k
    if b > a:
      b, a = a, b
    if v >= 4:
      if k > b:
        b = k
      if b > a:
        b, a = a, b
print (a*b)

Submission status: Accepted

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

b, c, d = 0, 0, 0
for i, v in a.items():
    if v >= 2:
        if b < i:
            b, c = i, b
        elif c < i:
            c = i

    if v >= 4:
        d = max(d, i)
print(max(b*c, d*d))

Submission status: Accepted

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

A.sort(reverse=True)
#print(A)

setbar=[]
known=set()

for a in A:
    if a in known:
        setbar.append(a)
        known.remove(a)
    else:
        known.add(a)
    if len(setbar) >= 2:
        break

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

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
counter=Counter(a)
c_k=sorted(counter.keys(),reverse=True)
ans=0
l=[0]
for i in c_k:
    if counter[i]>=2:
        ans=max(ans,i*l[-1])
        l.append(i)
    if counter[i]>=4:
        ans=max(ans,i*i)
    if ans!=0:
        print(ans)
        exit()
print(0)

Submission status: Accepted

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

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

A.sort(reverse=True)
print(A[0]*A[1])

Submission status: Accepted

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

arr=[]
for k,v in A.items():
    if v>1:
        arr.append(k)
    if v>3:
        arr.append(k)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
X = []
for i in range(N):
  if i == 0:
    cnt = A[i]
  else:
    if A[i] == cnt:
      X.append(A[i])
      cnt = 0
    else:
      cnt = A[i]
if len(X) >= 2:
    print(X[0]*X[1])
else:
  print(0)

Submission status: Accepted

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

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

cnt=0
ans=1
for t in sorted(d.items(),reverse=True):
	if t[1]>=2:
		ans*=t[0]
		cnt+=1
	if cnt==1 and t[1]>=4:
		ans*=t[0]
		cnt+=1
	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 = Counter(a)
ary = [0,0]
for i in a:
    if a[i] >= 4:
        ary.append(i)
        ary.append(i)
    elif a[i] >= 2:
        ary.append(i)
ary.sort()
print(ary.pop()*ary.pop())

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
a += [0]
b = -1
ans = [0,0]
count = 0
for i in range(n+1):
    count += 1
    if b != a[i]:
        if count >= 4:
            if ans[0]:
                ans[1] = b
                break
            else:
                ans[0] = b
                ans[1] = b
                break
        elif count >= 2:
            if ans[0]:
                ans[1] = b
                break
            else:ans[0] = b
        b = a[i]
        count = 0
print(ans[0]*ans[1])

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
li = collections.Counter(a)
square = 0
rectangle = []
for i in li:
    if li[i] >= 2:
        rectangle.append(i)
    if li[i] >= 4:
        square = max(square, i)

rectangle.sort()

if len(rectangle) < 2 and square == 0:
    print(0)
elif len(rectangle) < 2:
    print(square**2)
else:
    print(max(square**2, rectangle[-1] * rectangle[-2]))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

for i in a:
    d[i] += 1

tmp = sorted(d.items(), reverse=True)
cnt = 0
ans = 0
for i, j in tmp:
    if cnt == 0 and j >= 4:
        ans = i * i
        break
    if j >= 2 and cnt == 0:
        ans += i
        cnt += 2
    elif j >= 2 and cnt == 2:
        ans = ans * i
        break

print(ans)

Submission status: Accepted

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

A.sort(reverse = True)
max_num = []
before_num = 0

for j in A:
        if before_num == j:
                max_num.append(j)
                if len(max_num) == 2:
                        break
                else:
                        before_num = 0
        else:
                before_num = j

if len(max_num) >= 2:
        print(max_num[0]*max_num[1])
else:
        print("0")

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
sides = [0, 0]

for i in a.keys():
    if a[i] >= 4:
        sides.append(i)
        sides.append(i)
    elif a[i] >= 2:
        sides.append(i)

sides.sort(reverse=True)
print(sides[0] * sides[1])

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
sides = [0, 0]

for i in a.keys():
    if a[i] >= 4:
        sides.append(i)
        sides.append(i)
    elif a[i] >= 2:
        sides.append(i)

sides.sort()
print(sides.pop() * sides.pop())

Submission status: Accepted

Solution code:
c={}
input()
for i in list(map(int,input().split())):
    if i in c:
        c[i]+=1
    else:
        c[i]=1
d=[i for i in c.items() if i[1]>1]
c=sorted(d)
if len(d)==0 or (len(d)==1 and c[-1][1]<4):
    print(0)
else:
    if c[-1][1]>3:
        print(c[-1][0]**2)
    else:
        print(c[-1][0]*c[-2][0])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
li = list(map(int, input().split()))
counter = Counter(li)
dic = {}
for key, val in counter.items():
    if val >= 2:
        dic[key] = val

if len(dic) == 0:
    print(0)
elif len(dic) == 1:
    key, val = dic.popitem()
    if val >= 4:
        print(key*key)
    if val <= 3:
        print(0)
elif len(dic) >= 2:
    sort = sorted(dic.items(), key=lambda x:x[0], reverse=True)
    k1, v1 = sort[0]
    k2, v2 = sort[1]
    if v1 >= 4:
        print(k1*k1)
    elif v1 <= 3:
        print(k1*k2)

Submission status: Accepted

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

x, y = 0, 0

i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        x = a[i]
        i += 2
        break
    i += 1

while i < n - 1:
    if a[i] == a[i + 1]:
        y = a[i]
        i += 2
        break
    i += 1
print(x * y)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=sorted([int(i) for i in input().split()])
cnt=Counter(a)
key=sorted(list(cnt.keys()))[::-1]
one=two=0
for i in key:
    if cnt[i]>=4 and one==0:
        one=two=i
        break
    elif cnt[i]>=2:
        if one==0:
            one=i
        else:
            two=i
            break
print(one*two)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort(reverse=True)
cout = 0
for i in range(1, len(A)):
    if A[i] == A[i - 1]:
        cout = i
        break
for i in range(cout + 2, len(A)):
    if A[i] == A[i - 1]:
        print(A[cout] * A[i])
        break
if cout == 0:
    print(0)

Submission status: Accepted

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

a,b = 0,0
i = 0
while i<=len(li)-2:
    if li[i] == li[i+1] and a == 0:
        a = li[i]
        i += 2
    elif li[i] == li[i+1]  and a != 0:
        b = li[i]
        break
    elif li[i] != li[i+1]:
        i += 1
print(a*b)

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
from collections import Counter
# from itertools import accumulate
# from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))
Ls = sorted(list(set(L[:])),reverse=True)
Lc = Counter(L)

A = 0

for l in Ls:
    if A == 0:
        if Lc[l] >= 4:
            print(l * l)
            exit()
        if Lc[l] >= 2:
            A = l
    else:
        if Lc[l] >= 2:
            print(A * l)
            exit()

print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
N = int(input())
dict = defaultdict(int)
for a in [int(x) for x in input().split()]:
  dict[a] += 1

ab = deque([])
for a, cnt in dict.items():
  if cnt > 1:
    ab.append((a, cnt))

ab = sorted(list(ab), reverse=True)
i = 4
ret = 1
for abc in ab:
  if i == 2:
    ret *= abc[0]
    i = 0
    break
  elif abc[1] >= 4:
    ret = abc[0] ** 2
    i = 0
    break
  else:
    ret *= abc[0]
    i -= 2
if i:
  ret = 0
print(ret)

Submission status: Accepted

Solution code:
import collections

n = int(input())
ls = list(map(int, input().split()))
counter = collections.Counter()
for a in ls:
    counter[a] += 1
ls = [(k, v) for k, v in counter.items() if v > 1]
ls.sort(reverse=True)
m = len(ls)
if m >= 1 and ls[0][1] >= 4:
    print(ls[0][0]**2)
elif m >= 2:
    print(ls[0][0] * ls[1][0])
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
A = III()

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1

A = list(set(A))
A.sort(reverse=True)

l1 = 0
l2 = 0
for a in A:
    if d[a]>=2:
        if l1==0:
            l1 = a
        else:
            l2 = a
            break
        d[a] -= 2
        if d[a]>=2:
            l2 = a
            break
    else:
        continue

print(l1*l2)

Submission status: Accepted

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

from collections import Counter

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

pair = [0, 0]
c = Counter(a)
for num, cnt in c.items():
    pair += [num] * (cnt // 2)

pair.sort(reverse=True)

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

Submission status: Accepted

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

from collections import Counter

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

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

cands = []
for num, cnt in li:
    if cnt >= 4:
        cands += [num, num]
    elif cnt >= 2:
        cands += [num]

cands += [0, 0]
ans = cands[0] * cands[1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
input()
a = list(map(int, input().split()))
ca = Counter(a)
sca = sorted(ca.items(), key=lambda x:-x[0])
# print(sca)
h, w = 0, 0
for k, v in sca:
  if v >= 4:
    h = max(h, k)
    w = max(w, k)
  elif v >= 2:
    if h == 0:
      h = max(h, k)
    else:
      w = max(w, k)
  if h != 0 and w != 0:
    print(h*w)
    exit()
print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]
L = []
flag = 0
for i in range(N-1):
    if A[i] == A[i+1] and flag == 0:
        L.append(A[i])
        flag = 1
    else:
        flag = 0

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

Submission status: Accepted

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        d[ai] += 1
    f = sorted([k for k, v in d.items() if v >= 2], reverse=True)
    if len(f) < 2:
        ans = 0
    else:
        if d[f[0]] >= 4:
            ans = max(f[0] ** 2, f[0] * f[1])
        else:
            ans = f[0] * f[1]
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

e=[]
a.sort(reverse=True)
for i in range(len(a)-1):
  if a[i] == a[i+1] and a[i] not in e:
    e.append(a[i])
    if len(e) == 2:
      break
e.sort(reverse=True)

c4 = 0
for i in e:
  if a.count(i)>=4:
    c4=i
    break

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

Submission status: Accepted

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = collections.defaultdict(int)
    for a in A:
        d[a] += 1
    for k,v in list(d.items()):
        if v < 2:
            d.pop(k)
    d = sorted(d.items(), key=lambda x: x[0], reverse=True)
    if len(d) >= 1 and d[0][1] >= 4:
        print(d[0][0]**2)
    elif len(d) >= 2:
        print(d[0][0]*d[1][0])
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

dic = {}
for i in A:
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
two = []
four = []
for j, k in dic.items():
	if k>=4:
		four.append(j)
	if k>=2:
		two.append(j)
two.sort(reverse=True)
four.sort(reverse=True)
if len(four) == 0:
	if len(two) <= 1:
		print(0)
	else:
		print(two[0]*two[1])	
else:
	if len(two) <= 1:
		print(four[0]**2)
	else:	
		print(max(two[0]*two[1], four[0]**2))

Submission status: Accepted

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

a = sorted(a, reverse=True)

count = 0
edge = []

i = 0
for _ in range(n-1):
    if a[i] == a[i+1]:
        count = count + 1
        edge.append(a[i])
        i = i + 1
        if count == 2:
            break
    i = i + 1

s = edge[0]*edge[1] if count == 2 else 0
print(s)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
count = 0
s = 1
i = 0
A.sort()
A.reverse()

while i < N-1 and count < 2:
  if A[i] == A[i+1]:
    s = s * A[i]
    count += 1
    i += 2
  else:
    i += 1

if count >= 2:
  print(s)
else:
  print(0)

Submission status: Accepted

Solution code:
import collections


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

    c = collections.Counter(a)

    l = 0
    w = 0

    max_num = -1
    for k,v in c.items():
        if max_num < k and v >= 2:
            max_num = k

    if max_num != -1:
        l = max_num
        c[max_num] = c[max_num] - 2

    max_num = -1
    for k, v in c.items():
        if max_num < k and v >= 2:
            max_num = k

    if max_num != -1:
        w = max_num
        c[max_num] = c[max_num] - 2

    print(l*w)

Submission status: Accepted

Solution code:
import collections

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

d = collections.defaultdict(int)
edges = []
for edge in a:
    d[edge] += 1
    if d[edge] % 2 == 0:
        edges.append(edge)

edges.sort(reverse=True)
if len(edges) < 2:
    print(0)
else:
    print(edges[0] * edges[1])

Submission status: Accepted

Solution code:
from collections import Counter as C
input()
A=sorted(C(list(map(int,input().split()))).most_common())
a,b=0,0
for i,j in A:
  if j>=4:
    a=b=i
  elif j>=2:
    a=b
    b=i
print(a*b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
a = 0
b = 0
check = False

for i in range(1, N):
    if check == True:
        check = False
        pass
    else:
        if A[i-1] == A[i]:
            if a == 0:
                a = A[i]
            elif b == 0:
                b = A[i]
                print(a * b)
                exit()
            check = True

print(0)

Submission status: Accepted

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

N = int(input())

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

l = collections.Counter(A)

l24 =list([int(l1[0]) for l1 in l.items() if l1[1]>=2])

l24.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split());d={};r,c=0,0
for a in A:d[a]=d.get(a,0)+1
for l,n in d.items():r,c=sorted([r,c]+[l]*(n//2))[-2:]
print(r*c)

Submission status: Accepted

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

key = list(A.keys())
val = list(A.values())

quad = [key[i] for i in range(len(key)) if val[i] >= 4]
if len(quad) >= 1:
	quad = max(quad)
else:
	quad = 0

bi = sorted([key[i] for i in range(len(key)) if val[i] >= 2], reverse = True)
if len(bi) >= 2:
	bi_1 = bi[0]
	bi_2 = bi[1]
else:
	bi_1 = 0
	bi_2 = 0

print(max(quad**2, bi_1*bi_2))

Submission status: Accepted

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

ans = 1
cnt = 0
A.sort(reverse=True)
hikae = None
for e in A:
    if hikae is None:
        hikae = e
    elif hikae == e:
        ans *= e
        cnt += 1
        hikae = None
        if cnt == 2:
            print(ans)
            exit(0)
    else:
        hikae = e
print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
cnt = Counter(LI())
L = []
for k, v in cnt.items():
    if v >= 4:
        L += [k] * 2
    elif v >= 2:
        L += [k]


L.sort(reverse=True)


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

Submission status: Accepted

Solution code:
# Counterを使わずに
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
rod1 = 0
rod2 = 0
A = sorted(A)[::-1]
for i in range(len(A)-2):
    if rod1:
        i += 1
    #print(A[i],A[i+1])
    if A[i] == A[i+1]:
        if rod1:
            rod2 = A[i]
        else:
            rod1 = A[i]
    if rod1 and rod2:
        break

if (not rod1) and (not rod2):
    print(0)
else:
    print(rod1*rod2)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
C=sorted(Counter(A).items(),key=lambda x:x[0],reverse=True)
m=len(C)
for i in range(m):
    if C[i][1]>=4:
        print(C[i][0]**2)
        exit()
    elif C[i][1]>=2:
        a=C[i][0]
        for j in range(i+1,m):
            if C[j][1]>=2:
                print(a*C[j][0])
                exit()
print(0)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import Counter

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

c = Counter(A)
#print(c)

key = []
for k, v in c.items():
    if v >= 4:
        # 1 1 1 1 とか
        key.append(k)
        key.append(k)

    elif v >= 2:
        key.append(k)

if len(key) < 2:
    print(0)
    exit()

key.sort(reverse=True)
print(key[0]*key[1])

Submission status: Accepted

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

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

    dic = {}
    for t in a:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    
    ans = []
    ok = False
    for l, count in sorted(dic.items(), reverse=True):
        if count >= 4:
            if len(ans) == 0:
                print(l*l)
                ok = True
                break
            else:
                print(ans[0] * l)
                ok = True
                break
        elif count >= 2:
            if len(ans) == 1:
                print(ans[0] * l)
                ok = True
                break
            else:
                ans.append(l)

    if not ok:
        print(0)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

li=[]

for i,j in dic.items():
    if j>=2:
        li.append(i)
    if j>=4:
        li.append(i)
li.sort()


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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input().strip())
A = Counter(list(map(int, input().strip().split(' '))))
tmp = 0
for k,v in sorted(A.items(), reverse=True):
  if v >= 4:
    if tmp > 0:
      print(k*tmp)
      exit()
    else:
      print(k*k)
      exit()
  elif v >= 2:
    if tmp > 0:
      print(k*tmp)
      exit()
    else:
      tmp = k
print(0)

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = []
for a,c in B.items():
    C += [a] * (c//2)
C.sort()

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

Submission status: Accepted

Solution code:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
c = Counter(li)
hen = [i[0] for i in c.items() if i[1] >= 2]
hen2 = [i for i in hen if c[i] >= 4]
hen.sort()
if len(hen) <= 1:
    if len(hen2) == 0:
        print(0)
    else:
        print(max(hen2) ** 2)
else:
    if len(hen2) == 0:
        print(hen[-1] * hen[-2])
    else:
        print(max(hen[-1] * hen[-2], max(hen2) ** 2))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc071/tasks/arc081_a
# C - Make a Rectangle
import collections

N = int(input().split()[0])
a_list = list(map(int, input().split()))

counter = collections.Counter(a_list)
count_dict = {k: v for k, v in counter.items() if v >= 2}
if count_dict:
    length_list = sorted(list(count_dict.keys()), reverse=True)

    if len(length_list) == 1 and counter[length_list[0]] < 4:
        area = 0
    elif counter[length_list[0]] >= 4:
        area = length_list[0] ** 2
    else:
        area = length_list[0] * length_list[1]
else:
    area = 0

print(area)

Submission status: Accepted

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

b = [0,0]

ind = 0
bef = -1
for a in arr:
    if a != bef:
        bef = a
    else:
        b[ind] = a
        ind += 1
        bef=-1
    if ind > 1:
        break

if ind > 1:
    print(b[0]*b[1])
else:
    print(0)

Submission status: Accepted

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

tmp1 = 0
tmp2 = 0
flg = True

for i in range(N-1):
    if A[i] == A[i+1] and tmp1 == 0 and flg:
        tmp1 = A[i]
        flg = False
    elif A[i] == A[i+1] and tmp2 == 0 and flg:
        tmp2 = A[i]
        break
    else:
        flg = True

print(tmp1 * tmp2)

Submission status: Accepted

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

A.sort(reverse=1)

R = [0, 0]
r_ind = 0
a_ind = 0
while r_ind < 2 and a_ind < n-1:
    if A[a_ind] == A[a_ind + 1]:
        R[r_ind] = A[a_ind]
        a_ind += 2
        r_ind += 1
    else:
        a_ind += 1

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = []
n = inp()
a = inpl()
aa = set(a)
aa = sorted(list(aa),reverse=True)
# print(a,aa)
d = defaultdict(int)

for key in a:
    d[key] += 1
for i in aa:
    if d[i] >= 4:
        if ans == []:
            print(i**2)
            quit()
    if d[i] >= 2:
        ans.append(i)
        if len(ans) == 2:
            print(ans[0]*ans[1])
            quit()
print(0)

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split())))
s = []
for k, v in sorted(a.items(), key=lambda x: -x[0]):
    # print(k,v)
        
    if v > 1:
        s.append(k)
        if len(s) > 1:
            print(s[0] * s[1])
            exit()

    if v >= 4:
        print(k ** 2)
        exit()
print(0)

Submission status: Accepted

Solution code:
import collections

n=int(input())
a=list(map(int, input().split()))  
a = collections.Counter(a)
a=a.most_common()
b=0
c=0
a.sort(key=lambda x:x[0])

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
cnt = sorted(collections.Counter(A).items())
cnt_2 = [x for x in cnt if x[1] >= 2]
if len(cnt_2) == 0:
    print(0)
elif cnt_2[-1][1] >= 4:
    print((cnt_2[-1][0])**2)
else:
    if len(cnt_2) == 1:
        print(0)
    else:
        print(cnt_2[-1][0]*cnt_2[-2][0])