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 defaultdict


n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
    d[a[i]] += 1

b = sorted(list(set(a)))[::-1]
newa = []
for i in range(len(b)):
    if d[b[i]] >= 2:
        newa.append((b[i], d[b[i]]))

area = 0
for i in range(len(newa)):
    if newa[i][1] >= 4:
        area = newa[i][0] ** 2
        break
    elif newa[i][1] >= 2:
        for j in range(i + 1, len(newa)):
            area = newa[i][0] * newa[j][0]
            break
        break
print(area)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    import collections
    a = collections.Counter(a).most_common()
    a = sorted(a, key=lambda x: x[0], reverse=True)
    t = -1
    for k, v in a:
        if v >= 4:
            if t != -1:
                print(t * k)
                exit()
            else:
                print(k ** 2)
                exit()
        elif v >= 2:
            if t != -1:
                print(t * k)
                exit()
            else:
                t = k
    print(0)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

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

E = [(k, v) for k, v in d.items() if v >= 2]
E.sort(key=lambda x: -x[0])

if len(E) == 0:
    print(0)
    exit()
if len(E) == 1 and E[0][1] < 4:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = collections.Counter(list(map(int, input().split()))).most_common()
a = sorted(a, reverse=True)
t = 0
for i, v in a:
    if v >= 4:
        if t == 0:
            print(i * i)
            exit()
        else:
            print(t * i)
            exit()
    elif v >= 2:
        if t == 0:
            t = i
        else:
            print(t * i)
            exit()
print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
cnt=0
x=0
d=[]
for i in range(n):
	if x==a[i]:
		cnt+=1
	else:
		x=a[i]
		cnt=0
	if cnt==1:
		d.append(a[i])
	if cnt==3:
		d.append(a[i])
	if len(d)==2:
		break
if len(d)<=1:
	print(0)
	exit()
print(d[0]*d[1])

Submission status: Accepted

Solution code:
import collections

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

c = list(collections.Counter(A).items())
c.sort(reverse=True)

a = 0
b = 0
e = -1

for i in range(N):
    if c[i][1] >= 4:
        a = c[i][0]
        b = c[i][0]
        break
    elif c[i][1] >= 2:
        a = c[i][0]
        e = i
        break

if a == 0:
    print(0)
elif e !=-1:
    for i in range(e+1, N):
        if c[i][1] >= 2:
            b = c[i][0]
            break
    if b == 0:
        print(0)
    else:
        print(a*b)
else:
    print(a*b)

Submission status: Accepted

Solution code:
import collections
import heapq
n=int(input())
a=[-int(item) for item in input().split()]
c = [item for item in list(collections.Counter(a).items()) if item[1]>1]
heapq.heapify(c)
#print(c)

if len(c)==0:
  print(0)
  exit()
if sum([item[1] for item in c])<4:
  print(0)
  exit()

x=heapq.heappop(c)
if c!=[]:
  y=heapq.heappop(c)
else:
  y=(0,0)
if x[1]>=4:
  print(x[0]*x[0])
else:
  print(x[0]*y[0])

Submission status: Accepted

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

A.sort()

first_edge = -1
second_edge = -1

used = [False for i in range(N)]
for i in range(N - 1, 0, -1):
    if first_edge < 0 and A[i] == A[i - 1] and (not used[i]) and (not used[i - 1]):
        first_edge = A[i]
        used[i] = True
        used[i - 1] = True
    if first_edge > 0 and A[i] == A[i - 1] and (not used[i]) and (not used[i - 1]):
        second_edge = A[i]
        break
        
if first_edge < 0 or second_edge < 0:
    print(0)
else:
    print(first_edge * second_edge)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC081C
import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()

count=0
h=0
w=0
i=0
while(1):
#for i in range(0,n-1):
	if(i<n-1):
		if(hoge[n-1-i]==hoge[n-2-i]):
			if(count==0):
				h=hoge[n-1-i]
				count+=1
				i+=1
			else:
				w=hoge[n-1-i]
				break
		i+=1
	else:
		break
print(w*h)

#print(hoge)

Submission status: Accepted

Solution code:
# 2019/08/08

from collections import Counter

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

x=sorted(list(a.items()),reverse=True)



ans=0
for k,v in x:
    if v<2:continue
    if v>3:
        if ans==0:
            ans=k**2
        else:
            ans*=k
        break
    else:
        if ans==0:
            ans=k
        else:
            ans*=k
            break

print(ans)

Submission status: Accepted

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

max_1 = 0
len_a = len(A)
for i, a in enumerate(A):
    if len_a - i >= 4:
        if A[i] == A[i+1] and A[i+1] == A[i+2] and A[i+2] == A[i+3]:
            if max_1 == 0:
                print(A[i] ** 2)
                exit()
            else:
                print(A[i] * max_1)
                exit()
    if len_a - i >= 2:
        if A[i] == A[i+1]:
            if max_1 == 0:
                max_1 = A[i]
            else:
                if max_1 != A[i]:
                    print(A[i] * max_1)
                    exit()
print(0)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in b:
    if i not in c:
        c[i] = 1
    else:
        c[i] += 1
c = sorted(c.items(), key=lambda x: x[0], reverse=True)
d = 0
for k, v in c:
    if v // 2 == 1:
        if d != 0:
            print(d * k)
            exit()
        else:
            d = k
    elif v // 2 >= 2:
        if d != 0:
            print(d * k)
            exit()
        else:
            print(k ** 2)
            exit()
print(0)

Submission status: Accepted

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

num = []
cnt = 1
for i in range(N):
    if i == 0:
        cnt = 1
    else:
        if A[i-1] == A[i]:
            cnt += 1
            if i == N-1:
                num.append([A[i-1],cnt])
        else:
            if cnt > 1:
                num.append([A[i-1],cnt])
                cnt = 1
#print(num)
a = 0
b = 0
if len(num) == 0:
    pass
elif len(num) == 1:
    if num[-1][1] >= 4:
        a = num[-1][0]
        b = a
else:
    if num[-1][1] >= 4:
        a = num[-1][0]
        b = a
    else:
        a = num[-1][0]
        b = num[-2][0]
print(a*b)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
b = sorted(b, reverse=True)
c = []
d = []
for i in range(1, len(b)):
    if i-1 not in d:
        if b[i] == b[i-1]:
            c.append(b[i])
            d.append(i)
        if len(c) == 2:
            print(c[0] * c[1])
            exit()
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(int(_) for _ in input().split())
t1,t2 = [0,0],[0]
for k,v in Counter(a).items():
    if v >= 2: t1.append(k)
    if v >= 4: t2.append(k)

t1.sort()
t2.sort()
print(max(t1[-1]*t1[-2],t2[-1]**2))

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=Counter(list(map(int,input().split())))
b=[i for i,j in a.items() if j>=2]+[0,0]
c=[i for i,j in a.items() if j>=4]+[0]
b.sort(reverse=True)
c.sort(reverse=True)
print(max(b[0]*b[1],c[0]**2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

A_count = collections.Counter(A)
A_most = A_count.most_common()

ans = []
for a in A_most:
    if a[1] > 1:
        ans.append(a[0])
        if a[1] > 3:
            ans.append(a[0])

ans.sort()

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

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
a=list(map(int, input().split()))
A=Counter(a)
A_most = A.most_common()
d=[]
for i in A_most:
    if i[1]>=4:
        d.append(i[0])
        d.append(i[0])
    elif i[1]>=2:
        d.append(i[0])
d=sorted(d)
print(d[-1]*d[-2] if len(d)>0 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
i = 0
flag = False
ans = 0
while i < n-1:
    if not flag and a[i+1] == a[i]:
        flag = True
        h = a[i]
        i += 2
    elif flag and a[i+1] == a[i]:
        ans = h * a[i]
        break
    else:
        i += 1

print(ans)

Submission status: Accepted

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

l = [0,0]
cnt = {}

for a in A:
    if a in cnt:
        cnt[a] += 1
    else:
        cnt[a] = 1
    
    if cnt[a] >= 2:
        if a > l[0]:
            l[1] = l[0]
            l[0] = a
        elif cnt[a] >= 4 and a == l[0]:
            l[1] = a
        elif a < l[0] and a > l[1]:
            l[1] = a

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

Submission status: Accepted

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


def main():
    n = int(input())
    cnt = sorted(
        {
            k: v
            for k, v in Counter(map(int, input().rstrip().split())).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:
# ARC081C - Make a Rectangle (ABC071C)
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:
# ARC081C - Make a Rectangle
from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(Counter(lst).most_common(), reverse=True)
    ans = []
    for i, j in cnt:
        if len(ans) >= 2:
            break
        if j >= 4:
            ans += [i] + [i]
        elif j >= 2:
            ans += [i]
    print(0 if ans == [] else ans[0] * ans[1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    if a in d.keys():
        d[a] += 1
    else:
        d[a] = 1

d = sorted(d.items(), reverse=True)
ans = []
for dd in d:
    if dd[1] > 1:
        if len(ans) == 0 and dd[1] > 3:
            print(dd[0] ** 2)
            exit()
        ans.append(dd[0])
    if len(ans) >= 2:
        break

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
x, y = 0, 0
flag = True
for i in A:
    if flag:
        if x == i:
            flag = False
        else:
            x = i
    else:
        if y == i:
            break
        else:
            y = i

print(x * y)

Submission status: Accepted

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

A.sort()

wh = [0,0]

tmp = 0
for i in A:
    if i == tmp:
        wh.append(i)
        tmp = 0
    else:
        tmp = i

print(wh[-1] * wh[-2])

Submission status: Accepted

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

C = {}

count = 0
H = 0
W = 0

res1=res2=res3=0

for i in A:
    C[i] = 0

for i in A:
    C[i] += 1

for i in A:
    if C[i] >= 2:
        res1 = max(res1, i)

for i in A:
    if C[i] >= 2 and i != res1:
        res2 = max(res2, i)

for i in A:
    if C[i] >= 4:
        res3 = max(res3, i)


print(max(res1 * res2, res3 * res3))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n = I()
    a = LI()
    f = defaultdict(int)
    for i in a:
        f[i-1] += 1
        f[i] += 1
        f[i+1] += 1
    print(max(f.values()))
    return

#E
def E():
    n = I()
    a = LI()
    f = defaultdict(int)
    f[0] = 4
    for i in a:
        f[i] += 1
    f = list(map(list, f.items()))
    f.sort(key = lambda x:-x[0])
    ans = 1
    k = 0
    for i,j in f:
        if j >= 4 and k == 0:
            print(i*i)
            quit()
        if j >= 2:
            k += 1
            ans *= i
        if k == 2:
            print(ans)
            quit()
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    E()

Submission status: Accepted

Solution code:
N = int(input())

ans = 1
cnt = 2
w = 0
for Ai in sorted(map(int, input().split()), reverse=True):
  if w != Ai:
    w = Ai
  else:
    ans *= w
    cnt -= 1
    if cnt <= 0:
      break
    w = 0

print(ans if cnt <= 0 else 0)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)

ans = 0
items = sorted([item for item in c.most_common() if item[1] >= 2], key=lambda x: x[0], reverse=True)
if len(items):
    x, count = items[0]
    y = 0
    if count >= 4:
        y = x
    else:
        if len(items) > 1:
            y, _ = items[1]
    ans = x * y

print(ans)

Submission status: Accepted

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

a_map = {}
for _a in a:
    if _a not in a_map:
        a_map[_a] = 1
    else:
        a_map[_a] += 1
keys =list(a_map.keys())[::]
for k in keys:
    if a_map[k] < 2:
        a_map.pop(k)

candidates = []
for k in a_map.keys():
    num = a_map[k]
    for n in range(num//2):
        candidates.append([k, 2])

if len(candidates) < 2:
    print(0)
else:
    candidates.sort(key=lambda x: x[0], reverse=True)
    print(candidates[0][0] * candidates[1][0])

Submission status: Accepted

Solution code:
from collections import Counter

input()
arr = Counter(list(map(int,input().split())))
ans = [0,0]
for a in arr:  
  if arr[a] > 1:
    ans.append(a)
  if arr[a] > 3:
    ans.append(a)
ans.sort()
print(ans[-1] * ans[-2])

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())

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

c = Counter(a)

can_use = [0, 0]
for i, x in c.items():
    if x >= 2:
        can_use.append(i)
    if x >= 4:
        can_use.append(i)

can_use.sort(reverse=True)

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
c = collections.Counter(A)
b = sorted(c,reverse = True)
tmp  = []
for i in b:
    if c[i] >= 4:
        tmp += [i]
        break
    elif c[i] >= 2:
        tmp += [i]
    if len(tmp) == 2:
        break
    
if len(tmp) == 2:
    print(tmp[0]*tmp[1])
elif len(tmp) == 1:
    print(tmp[0]*tmp[0])
else:
    print(0)

Submission status: Accepted

Solution code:
import collections
n=int(input())
a_list=[int(i) for i in input().split()]
 
node1,node2=0,0
square=0
 
cnt = collections.Counter(a_list)
for k, v in sorted(cnt.items(), key=lambda x: -x[0]):
    if v>=4:
        square=max(square,k**2)
    
    if v>=2:
        if node1==0:
            node1=k
        else:
            node2=k
            break
print(max(node1*node2,square))

Submission status: Accepted

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

nums = {}
for a in As:
    if a in nums.keys():
        nums[a] += 1
    else:
        nums[a] = 1

hens = []
for n in nums.items():
    if n[1] >= 4:
        hens.append(n[0])
    if n[1] >= 2:
        hens.append(n[0])

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

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

Submission status: Accepted

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

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

L.sort(reverse = True)
prev = -1
dic = {}
for n in L:
    if prev != n:
        cnt = 0
        prev = n
    elif prev == n:
        cnt += 1
        dic.setdefault(n, cnt)
        dic[n] += 1
if len(dic.keys()) < 1:
    print(0)
else:
    for k, v in sorted(dic.items(), reverse = True):
        if v >= 4:
            print(k * k)
            exit()
        else:
            break
    cand = list(dic.keys())
    cand.sort(reverse=True)
    print(cand[0] * cand[1])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
li = [0]*2
cnt = 0
i = 0
prev = 0
A.sort(reverse=True)
while(i<N):
    if(prev == A[i]):
        if(li[0] != 0):
            li[1] = A[i]
            break
        else:
            li[0] = A[i]
            if(i+1>=N):
                break
            prev = A[i+1]
            i += 2
    else:
        prev = A[i]
        i += 1
print(li[0]*li[1])

Submission status: Accepted

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

node1,node2=0,0
square=0

cnt = collections.Counter(a_list)
for k, v in sorted(cnt.items(), key=lambda x: -x[0]):
    if v>=4:
        square=max(square,k**2)
    
    if v>=2:
        if node1==0:
            node1=k
        else:
            node2=k
            break
print(max(node1*node2,square))

Submission status: Accepted

Solution code:
import itertools
N = input()
l = list(map(int,input().split(" ")))
l.sort(reverse=True)
N = int(N)
i = 0
hen =[]

while True:
    if i >= N-1 or len(hen) == 2:
        break
    if l[i] == l[i+1]:
        hen.append(l[i])
        i+=1
    i+= 1

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for a in input().split():
    d[a] += 1
ls = [(k, d[k]) for k in d if d[k] >= 2]
if ls == []:
    print(0)
elif len(ls) == 1:
    print(0 if ls[0][1] < 4 else int(ls[0][0])**2)
else:
    ls.sort(key= lambda x: int(x[0]), reverse=True)
    m,n = ls[0],ls[1]
    print(int(m[0])*int(n[0]) if m[1] < 4 else int(m[0])**2)

Submission status: Accepted

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

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    """戦略
    長方形の条件は、縦の2辺の長さが等しくて、横の2辺の長さが等しい。
    自分と同じ数字のものを複数持つ数字を、大きいものから2つ取ってくれば、その2つの数字が長方形の2辺になる。   
    """

    A.sort(reverse=True)
    a = A[0]
    for i in range(1, len(A)):
        if a == A[i]:
            break
        a = A[i]

    if i >= len(A)-1:
        print(0)
        return

    b = A[i+1]
    for j in range(i+2, len(A)):
        if b == A[j]:
            break
        b = A[j]

    if j == len(A):
        print(0)
        return
    
    print(a*b)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)


"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n = ip()                                     #入力整数1つ
#h,m= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
a.sort()
c = 1
cnum = a[0]
s = []
for i in range(1,n):
    if a[i] != cnum:
        if c > 1:
            s.append(cnum)
        if c > 3:
            s.append(cnum)
        c = 1
        cnum = a[i]
    else:
        c+=1
if c > 1:
    s.append(cnum)
if c > 3:
    s.append(cnum)
s.sort(reverse=True)
if len(s) < 2:
    print(0)
else:
    print(s[0]*s[1])

Submission status: Accepted

Solution code:
import collections as col

N = int(input())
A = list(map(int,input().split()))
L = col.Counter(A).most_common()
# ans[0] > ans[1]
ans = [0] * 2
square = 0

for _, item in enumerate(L):
    if item[1] >= 4:
        square = max(square, item[0])
    if item[1] >= 2:
        if ans[0] < item[0]:
            ans[1] = ans[0]
            ans[0] = item[0]
        elif ans[1] < item[0]:
            ans[1] = item[0]

print(max(ans[0]*ans[1],square**2))

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1={}
l2=[]
for i in l:
  if i in l1:
    if l1[i]%2==0:
      l1[i]+=1
    else:
      l2.append(i)
      l1[i]+=1
  else:
    l1[i]=1
if len(l2)<2:
  print(0)
else:
  m1=max(l2)
  del l2[l2.index(m1)]
  m2=max(l2)
  print(m1*m2)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1={}
l2=[]
for i in l:
  if i in l1:
    if l1[i]%2==0:
      l1[i]+=1
    else:
      l2.append(i)
      l1[i]+=1
  else:
    l1[i]=1
if len(l2)<2:
  print(0)
else:
  l2=sorted(l2)
  print(l2[-1]*l2[-2])

Submission status: Accepted

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

A.sort(reverse=True)

cur = 0
E = []
while cur < N:
    a = A[cur]
    count = 0
    while cur < N and A[cur] == a:
        count += 1
        cur += 1

    if 2 <= count:
        E.append(a)
    if 4 <= count:
        E.append(a)

    if len(E) >= 2:
        print(E[0] * E[1])
        quit()

print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
side = [0,0]
tmp = 0
for i in A:
    if i == tmp:
        side.append(i)
        tmp = 0
    else:
        tmp = i
print(side[-1]*side[-2])

Submission status: Accepted

Solution code:
from collections import Counter

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

E = [0, 0]
for k, v in Counter(A).items():
    if v >= 2:
        E.append(k)
    if v >= 4:
        E.append(k)
E.sort()
print(E[-1] * E[-2])

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(A).most_common()
C.sort()
C.reverse()

e = []
for i, j in C:
    if j >= 2:
        e.append(i)
        if j >= 4:
            e.append(i)
    if len(e) >= 2:
        break
if len(e) >= 2:
    print(e[0] * e[1])
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for a in list(map(int, input().split())):
    if not a in d.keys():
        d[a] = 0
    d[a] += 1

w = 0
h = 0
for k in sorted(d.keys()):
    if d[k] >= 2:
        h = w
        w = k
    if d[k] >= 4:
        h = w

print(h*w)

Submission status: Accepted

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

d = {}
for a in A:
    if not(a in d.keys()):
        d[a] = 0
    d[a] += 1

e = [x for x in d.items() if x[1] >= 2]
if len(e) <= 1:
    print(0)
    exit()
e = sorted(e,key=lambda x:x[0],reverse=True)
if e[0][1] >= 4:
    print(e[0][0]**2)
else:
    print(e[0][0]*e[1][0])

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
B=Counter(A)
#print(B)      
C=list(B.items())
C.sort(reverse=True)
#print(C)

H=0
W=0
for i in range(len(C)):
    if H==0:
        if C[i][1]>=4:
            print(C[i][0]**2)
            exit()
        elif C[i][1]>=2:
            H=C[i][0]
    else:
        if C[i][1]>=2:
            print(H*C[i][0])
            exit()
print(0)

Submission status: Accepted

Solution code:
n = int(input())
li = [ int(it) for it in input().split()]
li.sort()

import collections
col = collections.Counter(li)
li2 = []
pai = []

mxk1=0
mxv1=0
mxk2=0
mxv2=0
for k,v in col.items():
  if (v>1):
    if (k>mxk1):
      mxk2=mxk1
      mxv2=mxv1
      mxk1=k
      mxv1=v
    elif (k>mxk2):
      mxk2=k
      mxv2=v
#print (mxk1,mxv1,mxk2,mxv2)
if (mxv1>3):
	print (mxk1*mxk1)
elif (mxv1>1 and mxv2>1):
  	print(mxk1*mxk2)
else:
	print(0)

Submission status: Accepted

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

A.sort()
now = 0
B = []
for i in range(N-1, -1, -1):
    if now == A[i]:
        B.append(A[i])
        now = A[i] + 1
    elif now != A[i]:
        now = A[i]
    if len(B) == 2:
        break

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

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce
import bisect
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # Greatest Common Divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # Least Common Multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n, a = II(), LI()
counter = sorted(C(a).items(), key=lambda x: x[0], reverse=True)
for i in range(n):
    if 4 <= counter[i][1]:
        print(counter[i][0] ** 2)
        exit()
    elif 2 <= counter[i][1]:
        for j in range(i+1, n):
            if 2 <= counter[j][1]:
                print(counter[i][0] * counter[j][0])
                exit()
print(0)

Submission status: Accepted

Solution code:
n=int(input())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
ans=[0,0]
for i in d.keys():
  for _ in range(d[i]//2):
    ans.append(i)
ans.sort(reverse=1)
print(ans[0]*ans[1])

Submission status: Accepted

Solution code:
import collections
import copy
def main():
    ct=collections.Counter
    N=int(input())
    A=[int(i) for i in input().split()]
    B=ct(A)
    anum=sorted(B,reverse=True)
    tate=0
    yoko=0
    for _ in range(2):
        for k,a in enumerate(anum):
            if B[a]>=2 and tate==0:
                tate=a
                break
            elif B[a]>=2 and tate:
                if a==tate and B[a]<4:continue;
                else:
                    yoko=a
                    break
    print(tate*yoko)
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
two = [k for k, v in c.items() if v > 1]
four = [k for k, v in c.items() if v > 3]
if len(two) < 2 and not four:
    print(0)
    sys.exit(0)

St = 0
Sf = 0
if two:
    two.sort(reverse=True)
    St = 1
    for i in range(2):
        St *= two[i]
if four:
    Sf = max(four) ** 2
print(St if St > Sf else Sf)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = Counter([int(_) for _ in stdin.readline().rstrip().split()]).most_common()
B = [t for t in A if t[1] >= 2]
B.sort(reverse=True)
if len(B) < 2:
    print(0)
    sys.exit()
if B[0][1] >= 4:
    print(B[0][0]**2)
else:
    print(B[0][0]*B[1][0])

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
an=[]
for b,count in c.items():
    for _ in range(count//2):
        an.append(b)
an.sort(reverse=True)
if len(an)<2:
    print(0)
else:
    print(an[0]*an[1])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A)
op = []
for a, cnt in c.items():
    for _ in range(cnt // 2):
        op.append(a)
op.sort(reverse=True)
if len(op) < 2:
    print(0)
else:
    print(op[0]*op[1])