Problem:


Score : 300 points

Problem Statement

We have N sticks with negligible thickness.
The length of the i-th stick is A_i.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.

Constraints

4 \leq N \leq 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0.

Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.

Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.

Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20



Sample input:
6
3 1 2 4 2 1


Sample output:
2

Submission status: Accepted

Solution code:
n = int(input())

sList = sorted(list(map(int,input().split())),reverse=True)
res = []
acc = False
for i in range(n-1):
  if acc:
    acc = False
  else:
      if sList[i] == sList[i+1]:
        res.append(sList[i])
        acc = True
      if len(res) == 2:
        print(res[0]*res[1])
        exit(0)

print(0)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)[::-1]
cnt=1
a=0
C=[]
for i in B:
  if a==i:
    cnt+=1
    if cnt==2:
      cnt=0
      C.append(a)
    if len(C)==2:
      print(C[0]*C[1])
      exit()
  else:
    a=i
    cnt=1
print(0)

Submission status: Accepted

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = sorted(map(int, input().split()), reverse=True)
h = 0
w = 0
index = -1
for i in range(n - 3):
    if a[i] == a[i + 1]:
        h = a[i]
        index = i + 2
        break

for i in range(index, n - 1):
    if a[i] == a[i + 1]:
        w = a[i]
        break

print(h * w)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A = sorted(A, reverse=True)
ans1 = 0
ans2 = 0
index = N
for i in range(N-1):
    if A[i] == A[i + 1]:
        ans1 = A[i]
        index = i + 2
        break
for j in range(index, N - 1):
    if A[j] == A[j + 1]:
        ans2 = A[j]
        flag = 1
        break

print(ans1*ans2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
a.sort()
#print(a)
i = 0 # a[-i-1] 
big = 0
small = 0
while True:
    #print(i)
    if i+2 > n: break
    if a[-i-1] == a[-i-2]:
        if big == 0:
            big = a[-i-1]
            #print("b",big)
        else:
            small = a[-i-1]
            #print("s",small)
            break
        i += 2
    else: i += 1
    
print(big*small)

Submission status: Accepted

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

l1 = a[-1]
i=-2
try:
    while a[i]!=l1:
        l1 = a[i]
        i-=1
    i-=1
    l2 = a[i]
    i-=1
    while a[i]!=l2:
        l2 = a[i]
        i-=1
except:
    print(0)
    exit()
print(l1*l2)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
ans = [0, 0]
i = j = 0
while i + 1 < n:
    if a[i] == a[i+1]:
        ans[j] = a[i+1]
        j += 1
        i += 2
        if j == 2: break
    else: i += 1
print(int(ans[0]*ans[1]))

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)

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

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

h = 0
w = 0

new = sorted(d)

for i in new:
  if 4 > d[i] >= 2:
    if h >= w:
      w = i
    else:
      h = i

  elif d[i] >= 4:
    w = i
    h = i
    
print(w * h)

Submission status: Accepted

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

a.sort(reverse = True)

width = 0
height = 0
cnt = 0
for i in range(n - 1):
    if a[i] == a[i + 1] and cnt == 0:
        width = a[i]
        cnt += 1
        del a[i + 1]
    elif a[i] == a[i + 1] and cnt == 1:
        height = a[i]
        break

print(width * height)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

use_clipboard=True
bbn=1000000007
	
#+++++

		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	
	cc=defaultdict(lambda : 0)
	for v in al:
		cc[v] += 1
		
	ccl=[]
	for key in cc:
		ccl.append((key,cc[key]))
	ccl.sort(reverse=True)
	
	ma,mb=0,0
	for v,n in ccl:
		if ma == 0 and n >= 4:
			return v*v
		elif ma == 0 and n >= 2:
			ma = v
		elif n >= 2:
			return ma*v
	return 0
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
class input_clipboard:
	def __init__(self,s):
		self.input_l=s.splitlines()
		self.ii=0
		
	def input(self):
		ret = self.input_l[self.ii]
		self.ii+=1
		return ret

if __name__ == "__main__":
	if sys.platform =='ios':
		if use_clipboard:
			import clipboard
			input_text=clipboard.get()
			ic=input_clipboard(input_text)
			input = lambda : ic.input()
		else:
			sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n = int(input())
als = list(map(int,input().split()))
a1 = 0
a2 = 0
als.sort(reverse=1)
# print(als)
i = 0
while i < n-1:
    # print(i)
    if als[i] == als[i+1] and a1 == 0:
        a1 = als[i]
        i += 2
        continue
    if als[i] == als[i+1] and a1 != 0:
        a2 = als[i]
        break
    i += 1
print(a1*a2)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
c_dic={}
for i in l:
    if i in c_dic:
        c_dic[i]+=1
    else:
        c_dic[i]=1
c_l=[]
for i,j in c_dic.items():
    if j>=2:
        c_l.append(i)
    if j>=4:
        c_l.append(i)
c_l.sort(reverse=True)
if len(c_l)<2:
    print(0)
else:
    print(c_l[0]*c_l[1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = {}
for i in a:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1
edges = []
for i,j in count.items():
  if j >= 2:
    edges.append(i)
  if j >= 4:
    edges.append(i)

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

Submission status: Accepted

Solution code:
import collections
import heapq
n = int(input())
p = list(map(int, input().split()))
c = collections.Counter(p)
cond = 0
h = []
for line, cnt in c.most_common():
  if(cnt >= 2):
    for _ in range(cnt // 2):
      heapq.heappush(h, int(-1*line))
if(len(h) < 2):
  print(0)
  exit()
print(heapq.heappop(h) * heapq.heappop(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
D = {}
N = int(input())
A = list(map(int, input().split()))
Rec = []
Sq = []
for i in A:
  if i in D:
    D[i] += 1
  else:
    D[i] = 1
for i in D:
  if D[i] >= 4:
    Sq.append(i)
  if D[i] >= 2:
    Rec.append(i)
Rec.sort(reverse=True)
if len(Rec) <= 1 and len(Sq) == 0:
  print(0)
elif len(Sq) != 0 and len(Rec) >= 2:
  print(max(Rec[0] * Rec[1], max(Sq) * max(Sq)))
elif len(Sq) == 0 and len(Rec) >= 2:
  print(Rec[0] * Rec[1])

Submission status: Accepted

Solution code:
n=int(input())

a=sorted(list(map(int,input().split())),reverse=True)

stack=-1
t=[]
for i in a:
    if stack==i:
        t.append(i)
        stack=-1
    else:
        stack=i
    
    if len(t)>=2:
        break
try:
    print(t[0]*t[1])
except:
    print(0)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=[]
l=0
while l<N-1:
    #print(cnt,ans)
    if A[l]==A[l+1]:
        ans.append(A[l])
        if len(ans)==2:
            break
        else:
            l+=2
    else:
        l+=1
#print(A)
if len(ans)<=1:
    print(0)
else:
    print(ans[0]*ans[1])

Submission status: Accepted

Solution code:
import sys
import collections

input = sys.stdin.readline


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

    C = collections.Counter(A)

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

    if len(B) == 0:
        print("0")
        return
    elif len(B) == 1:
        B.sort(reverse=True)
        if C[B[0]] <= 3:
            print("0")
        else:
            print(B[0] * B[0])
        return
    else:
        B.sort(reverse=True)
        if C[B[0]] <= 3:
            print(B[0] * B[1])
        else:
            print(B[0] * B[0])

        return






    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int, input().split()))
edge = collections.Counter(A)
a = 0
b = 0
c = 0
for i in sorted(edge.items()):
    if i[1] >= 2:
        if i[0] > a:
            b = a
            a = i[0]
    if i[1] >= 4:
        c = i[0]

if a * b >= c * c:
    answer = a * b
else:
    answer = c * c

print(answer)

Submission status: Accepted

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

cnt = {}

for a in A:
    cnt.setdefault(a, 0)
    cnt[a] += 1

cnt_filter = list(filter(lambda x: x[1] >= 2, cnt.items()))
cnt_filter.sort(key=lambda x: x[0], reverse=True)

x = 0
y = 0

if len(cnt_filter) >= 2:
    x = cnt_filter[0][0]
    y = cnt_filter[1][0]
    if cnt_filter[0][1] >= 4:
        y = x

ans = x * y

print(ans)

Submission status: Accepted

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

from collections import Counter
a=Counter(a)
a=sorted(a.items(), reverse=True)

x=0
y=0

for p,q in a:
  if q>=4:
    if x==0:
      x=y=p
      break
    else:
      y=p
      break
  elif q>=2:
    if x==0:
      x=p
    else:
      y=p
      break
print(x*y)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())

d = defaultdict(int)
nums = []
for num in input().split():
    num = int(num)
    d[num] += 1
    # 同じ長さの棒が4本ある場合に対応するためこのような方法をとる
    if d[num] == 2:
        d.pop(num)
        nums.append(num)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
l = 0
m = 0
while len(A) >= 2:
    a = A.pop()
    b = A.pop()
    if a == b:
        if l == 0:
            l = a
        elif m == 0:
            m = a
    else:
        A.append(b)
print(l * m)

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
    
first = 0
second = 0
for i,j in dic.items():
  if j >= 2:
    if i > first :
      second = first
      first = i
    elif i > second:
      second = i
      
  if j >= 4:
    if i > first :
      second = first
      first = i
    elif i > second:
      second = i
  
print(first*second)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

edges = sorted(d.items(), key=lambda x: x[0], reverse=True)
w, h = 0, 0
ans = 0
for edge, amount in edges:
    if amount < 2:
        continue

    if amount >= 4:
        w, h = max(w, edge), max(h, edge)
        ans = max(ans, w*h)
    if amount >= 2:
        if not w:
            w = edge
        else:
            h = edge
            ans = max(ans, w*h)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
ans = 0
import collections
from collections import deque
d1 = deque()
count = 0
for i in range(N-1) :
    if A[i] == A[i+1] :
        count += 1
    else :
        if count == 0 :
            count = 0
            continue
        elif count < 3 :
            d1.append(A[i])
        else :
            d1.append(A[i])
            d1.append(A[i])
        count = 0
    if i == N-2 :
        if 0 < count < 3 :
            d1.append(A[i])
        elif count >= 3 :
            d1.append(A[i])
            d1.append(A[i])
if len(d1) < 2 :
    print(ans)
else :
    print(d1[-1] * d1[-2])

Submission status: Accepted

Solution code:
from collections import Counter
N = input()
A = list(map(int, input().split()))
C = Counter(A)
M = [0, 0]
for k, v in C.items():
    if v < 2: continue
    M.append(k)
    if v >= 4:
        M.append(k)
    M.sort(reverse=True)
    M = M[:2]
print(M[0]*M[1])

Submission status: Accepted

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
ANS=[0,0]
c = collections.Counter(L).most_common()
    
for k,v in c:
  if v <= 1:
    break
  if v >= 4:
    ANS.append(k)
    ANS.append(k)
  else:
    ANS.append(k)

Z=sorted(ANS)
print(Z[-1]*Z[-2])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
x=[0,0]
for i in range(n):
    try:
        d[a[i]]+=1
        if d[a[i]]==2 or d[a[i]]==4:
            x.append(a[i])
    except:
        d[a[i]]=1


x.sort()
x.reverse()
print(x[0]*x[1])

Submission status: Accepted

Solution code:

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

from collections import Counter

ans = []

for (key, value) in Counter(A).items():
  if value >=2:
    ans.append(key)
  if value >= 4:
    ans.append(key)

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
c=Counter(a).items()
f=0
s=0
for k,v in c:
    if v>=4:
        if k>f:
            s=k
            f=k
        elif k>s:
            s=k
    if v>=2:
        if k>f:
            s=f
            f=k
        elif k>s:
            s=k

print(s*f)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
count = Counter(A)
A = sorted(list(set(A)),reverse = True)
a,b = 0,0
for i in A:
    if a == 0:
        if count[i] >= 4:
            a,b = i,i
            break
        elif count[i] >= 2:
            a = i
    else:
        if count[i] >= 2:
            b = i
            break
print(a*b)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A.sort(reverse=True)
A = Counter(A)
ans = 1
for k in sorted(A, reverse=True):
	if A[k] >= 4:
		if ans == 1:
			ans = k**2
			break
		else:
			ans *= k
			break
	elif  A[k] >= 2:
		if ans == 1:
			ans *= k
		else:
			ans *= k
			break
else:
	ans = 0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse = True)
HW = []
i = 1
while i<N:
  if A[i]==A[i-1]:
    n = A.count(A[i])
    HW += [A[i]]*(min(n//2,2))
    i = i + n -1
  else:
    i = i + 1
  if len(HW)>=2:
    break
if len(HW)<2:
  print(0)
else:
  print(HW[0]*HW[1])

Submission status: Accepted

Solution code:
n = int(input())
list1 = [int(x) for x in input().split()]
list2 = list(reversed(sorted(list1)))

fflag = 0
ans = []
for i in range(len(list2) - 1):
  if fflag ==0:
    if list2[i] == list2[i + 1]:
      ans.append(list2[i])
      fflag = 1
  elif fflag == 1:
    fflag = 0
    continue
  if len(ans) == 2:
    break

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

Submission status: Accepted

Solution code:
from collections import Counter

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

bar = []
for k, v in A.items():
  bar += [k]*(v//2)
bar.sort(reverse=True)  

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
As = list(set(A))
As.sort(reverse=True)
h1 = 0
h2 = 0
for i in range(len(As)):
    if c[As[i]] >= 4:
        if h1 == 0:
            h1 = As[i]
        h2 = As[i]
    elif c[As[i]] >= 2:
        if h1 == 0:
            h1 = As[i]
        else: h2 = As[i]
    if h1*h2 > 0:
        break
print(h1*h2)

Submission status: Accepted

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


for i in range(1,n):
    if target == a[i]:
        cnt += 1
        if cnt == 2:
            hen.append(a[i])
            cnt = 0
    else:
        target = a[i]
        cnt = 1
    
    if len(hen) == 2:
        print(hen[0]*hen[1])
        exit()

print(0)

Submission status: Accepted

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    A = LI()
    d = collections.OrderedDict()
    A = sorted(A)[::-1]
    for a in A:
        if not a in d:
            d[a] = 1
        else:
            d[a] += 1
    l_num = -1
    ans = 0
    for num, freq in d.items():
        if freq < 2:
            continue
        else:
            if l_num == -1:
                l_num = num
            else:
                ans = l_num * num
                break
        if freq >= 4:
            ans = num * num
            break
    print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import *
n = int(input())
a = list(map(int, input().split()))
x = Counter(a)
if len(x) == 1:
    print(x[0][1]**2)
    exit()
d2 = deque()
d4 = deque()
for i in x.most_common():
    if i[1] > 3:
        d2.append(i[0])
        d4.append(i[0])
    elif i[1] > 1:
        d2.append(i[0])
    else:
        break
D2 = sorted(list(d2))
D4 = sorted(list(d4))
ans = 0
if len(D2) > 1:
    ans = D2[-1] * D2[-2]
if len(D4) > 0:
    ans = max(ans, D4[-1]**2)
print(ans)

Submission status: Accepted

Solution code:
import collections

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

C = collections.Counter(A)

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

num.sort(reverse=True)
num2.sort(reverse=True)
if (len(num) >= 2 and len(num2) >= 1):
    print(max(num[0]*num[1],num2[0]**2))
elif (len(num) >= 2):
    print(num[0]*num[1])
else:
    print(0)

Submission status: Accepted

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

r = [0, 0]

_a = a[0]
for i in range(1, n):
    if _a == a[i]:
        r.append(a[i])
        _a = -1
    else:
        _a = a[i]

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
x,y=0,0
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
b=groupby(a)
l=len(b)
for i in range(l):
    if x==0:
        if b[i][1]>=4:
            x,y=b[i][0],b[i][0]
        elif b[i][1]>=2:
            x=b[i][0]
    elif y==0:
        if b[i][1]>=2:
            y=b[i][0]
    else:
        break
print(x*y)

Submission status: Accepted

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])
#print(ans_lis)
if not ans_lis:
    print(0)
    sys.exit()

if len(ans_lis) == 1 and ans_lis[0][1] < 4:
    print(0)
elif len(ans_lis) == 1 and ans_lis[0][1] >= 4:
    print(ans_lis[0][0] ** 2)
elif len(ans_lis) >= 2:
    area_1 = ans_lis[0][0] * ans_lis[1][0]
    area_2 = 0
    if ans_lis[0][1] >= 4:
        area_2 = ans_lis[0][0] ** 2
    print(max(area_1, area_2))

Submission status: Accepted

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if len(ans_lis) <= 1 or ans_lis[0][1] is None:
        print(0)
        sys.exit()

area_1 = ans_lis[0][0] * ans_lis[1][0]
area_2 = 0
if ans_lis[0][1] >= 4:
    area_2 = ans_lis[0][0] ** 2
print(max(area_1, area_2))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
H=0
W=0
for i in range(N-1):
  if A[i]==A[i+1]:
    H=A[i]
    A[i]=0
    A[i+1]=0
    break
A.sort(reverse=True)
for i in range(N-1):
  if A[i]==A[i+1]:
    W=A[i]
    A[i]=0
    A[i+1]=0
    break
print(H*W)

Submission status: Accepted

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

A_dic = dict()
for i in range(N):
    if A[i] in A_dic:
        A_dic[A[i]] += 1
    else:
        A_dic[A[i]] = 1
        
max_key = 0
sub_max_key = 0
for k, v in A_dic.items():
    if v <= 1:
        pass
    elif v <= 3:
        if k > max_key:
            sub_max_key = max_key
            max_key = k
        elif k > sub_max_key:
            sub_max_key = k
    else:
        if k > max_key:
            sub_max_key = k
            max_key = k
            
print(max_key * sub_max_key)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]
import collections
c = collections.Counter(A)
d = c.items()
e = []
for i in d:
    if i[1] >= 4:
        e.append(i[0])
        e.append(i[0])
    elif i[1] >= 2:
        e.append(i[0])
if len(e) < 2:
    print(0)
    sys.exit()
e = sorted(e,reverse=True)
print(e[0] * e[1])

Submission status: Accepted

Solution code:
import sys

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

def main():
    l.sort(reverse=True)

    a = b = 0
    i = 0
    while i <= n - 2:
        if l[i] == l[i+1]:
            if a:
                b = l[i]
                break
            else:
                a = l[i]
                i += 2
                continue
        i += 1
    
    return a * b

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [a[0]]
cnt = 1
for i in range(1, n):
	if a[i] == b[-1]:
		b.append(a[i])
		cnt = cnt + 1
	else:
		if (cnt & 1):
			b.pop()
		b.append(a[i])
		cnt = 1
if (cnt & 1):
	b.pop()
if len(b) < 4:
	print(0)
else:
	print(b[-1] * b[-3])

Submission status: Accepted

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

r = []
i = 0
while i < n:
    if i < n - 1 and a[i] == a[i + 1]:
        r.append(a[i])
        i += 2
    else:
        i += 1
    if len(r) == 2:
        break
if len(r) == 2:
    print(r[0] * r[1])
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
C=collections.Counter(A)
S=sorted(C.items(),reverse=True)
# print(S)
for si in S:
    c=si[1]//2
    if count==0 and c==1:
        ans=si[0]
        count +=1
    elif count==0 and c>=2:
        print(si[0]**2)
        exit()
    elif count==1 and c>=1:
        print(ans*si[0])
        exit()
    # print(ans)
print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
l = [int(i) for i in input().split()]
c = sorted(Counter(l).most_common(),key = lambda x : -x[0])

edge = []
for i in c:
    if i[1] >= 4:
        edge.append(i[0])
        break
    elif i[1] >= 2:
        edge.append(i[0])
        if len(edge) == 2:
            break
    else:
        pass
    
print(edge[0]**2 if len(edge) == 1 else edge[0]*edge[1] if edge else 0)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=list(Counter(a).items())
c.sort(reverse=True)
ans=0
for a,b in c:
    if(b>=4):
        if(ans==0):
            print(a*a)
            exit()
        else:
            print(ans*a)
            exit()
    elif(b>=2):
        if(ans!=0):
            print(ans*a)
            exit()
        else:
            ans=a
print(0)

Submission status: Accepted

Solution code:
import collections

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

over_two = collections.Counter(A)
Over_two = []
Over_four = []

for key, val in over_two.items():
    if val <= 1:
        pass
    elif val >= 4:
        Over_four.append(key)
        Over_two.append(key)
    else:
        Over_two.append(key)

Over_four.append(0)
Over_two.append(0)
Over_two.append(0)

Over_two = sorted(Over_two, reverse=True)
Over_four = sorted(Over_four, reverse=True)

can_one = Over_four[0] * Over_four[0]
can_two = Over_two[0] * Over_two[1]

ans = max(can_one, can_two)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=list(Counter(a).items())
c.sort(reverse=True)
hen=0
ans=[0]
for a,b in c:
  if b>=4:
    if hen==0:
      ans.append(a**2)
    else:
      ans.append(hen*a)
  elif b>=2:
    if hen==0:
      hen=a
    else:
      ans.append(hen*a)
  else:
    continue
print(max(ans))

Submission status: Accepted

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

flag = True
pairs = []
for i in range(1, len(a)):
    if flag:
        if a[i] == a[i-1]:
            pairs.append(a[i])
            if len(pairs) == 2:
                print(pairs[0]*pairs[1])
                exit()
            flag = False
    else:
        flag = True
print(0)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from operator import itemgetter
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

C = Counter(A).most_common()
C = sorted(C, key=itemgetter(0), reverse=True)

x, y = 0, 0
for c in C:
	if c[1] >= 4:
		if c[0] >= x:
			x, y = c[0], c[0]
		else:
			y = c[0]
	elif c[1] >= 2:
		if x != 0: y = c[0]
		else: x = c[0]
	if x!=0 and y!=0: break

#print(x, y)
print(x*y)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v < 2:
        continue
    if v >= 4:
        if w == 0:
            w = h = k
            break
        else:
            h = k
            break
    elif v >= 2:
        if w == 0:
            w = k
        elif h == 0:
            h = k
            break
print(w*h)

Submission status: Accepted

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

from collections import defaultdict
dic = defaultdict(int)

for a in al:
    dic[a] += 1


a = [k for k, v in dic.items() if v >= 2]
b = [k for k, v in dic.items() if v >= 4]
a = sorted(a + b)

if len(a) < 2:
    print(0)
    import sys
    sys.exit()
print(a[-1] * a[-2])

Submission status: Accepted

Solution code:
n=int(input())
b=sorted([int(i) for i in input().split()],reverse=True)
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
A=groupby(b)
l=len(A)
B=[]
for i in range(l):
    A[i][1]=min(A[i][1]//2,2)
    if A[i][1]!=0:
        B.append(A[i])

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

Submission status: Accepted

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

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

E =  sorted([(k,v) for k,v in D.items() if v>=2] + [(0,4)])

l1, n1 = E[-1]
if n1>=4:
    print(l1*l1)
else:
    l2, n2 = E[-2]
    print(l1*l2)

Submission status: Accepted

Solution code:
from collections import Counter


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

    B = []
    for a, b in D.items():
        if b >= 4:
            B.append(a)
            B.append(a)
        elif b >= 2:
            B.append(a)

    B.append(0)
    B.append(0)

    B = sorted(B)[::-1]
    print(B[0] * B[1])


main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = sorted(Counter(list(map(int, input().split()))).most_common(), reverse=True)

tmp = []
for elt, cnt in A:
    if 1 >= cnt:
        continue
    if cnt >= 4:
        tmp.append(elt)
        tmp.append(elt)
        break
    if cnt >= 2:
        tmp.append(elt)

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