Problem:


Score : 300 points

Problem Statement

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

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

Constraints

4 \leq N \leq 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.

Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.

Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20



Sample input:
6
3 1 2 4 2 1


Sample output:
2

Submission status: Accepted

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

A.sort(reverse=True)
a = 0
b = 0
i = 1
while i < N:
    if A[i] == A[i-1] and a == 0:
        a = A[i]
        i += 2
    elif A[i] == A[i-1] and b == 0:
        b = A[i]
        i += 2
    else:
        i += 1

print(a*b)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = Counter(list(map(int, input().split())))
E = [0, 0]
for k, v in 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)
hen = [key for key, val in c.items() if val > 1]

l = max(hen) if hen else 0
if l != 0:
    if c[l] > 3:
        s = l
    else:
        hen.remove(l)
        s = max(hen) if hen else 0
else:
    s = 0

print(l * s)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
 
from collections import Counter
c = Counter(A)
 
mul = []
for k, v in c.items():
    if v >= 2:
        mul.append(k)
    if v >= 4:
        mul.append(k)
mul.sort()
if len(mul) < 2:
    print(0)
else:
    print(mul[-1]*mul[-2])

Submission status: Accepted

Solution code:
import collections

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


c = collections.Counter(A)

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

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

x = max(z)
del z[z.index(x)]
y = max(z)

print(x*y)

Submission status: Accepted

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    pair = [0, 0]
    dic = defaultdict(int)

    for a in A:
        if dic[a]:
            pair.append(a)
            dic[a] = 0
        else:
            dic[a] = 1

    pair.sort()
    print(pair[-1] * pair[-2])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def examC():
    N = I()
    A = LI()
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    a = [0,0]
    for key,i in d.items():
        if i>=4:
            if a[1]<key:
                a = [key,key]
            elif a[0]<key:
                a = [key,a[1]]
        elif i>=2:
            if a[1]<key:
                a = [a[1],key]
            elif a[0]<key:
                a = [key,a[1]]
    ans = a[0]*a[1]
    print(ans)
    return

def examD():

    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Accepted

Solution code:
import heapq
import sys

N = int(input())
A = [-x for x in map(int, input().split())]
heapq.heapify(A)

while len(A) > 3:
    l1 = -heapq.heappop(A)
    l2 = -heapq.heappop(A)
    if l1 == l2:
        while len(A) > 1:
            s1 = -heapq.heappop(A)
            s2 = -heapq.heappop(A)
            # print(s1, s2)
            if s1 == s2:
                print(l1 * s1)
                sys.exit()
            else:
                heapq.heappush(A, -s2)
                # print(A)

    else:
        if A:
            heapq.heappush(A, -l2)
print(0)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
X = Counter()
for i in range(0, N):
    X[A[i]] += 1
width = 0
height = 0
for x, y in sorted(X.most_common(), reverse=True):
    if y >= 2:
        if y >= 4:
            width = max(width, x)
            height = max(height, x)
            break
        if width != 0:
            height = x
            break
        else:
            width = x
print(height*width)

Submission status: Accepted

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

lengths = []
for i in range(len(A) - 1):
    try:
        if A[i] == A[i+3] and len(lengths) == 0:
            lengths.append(A[i])
            lengths.append(A[i])
            break
    except:
        pass

    if (A[i] not in lengths) and (A[i] == A[i+1]):
        lengths.append(A[i])

    if len(lengths) == 2:
        break

try:
    ans = lengths[0] * lengths[1]
except:
    ans = 0

print(ans)

Submission status: Accepted

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

c = collections.Counter(a).most_common()
c.sort()
c.reverse()
first=0
second=0

for tmp in c:
        if tmp[1] >=4 and first==0 and second==0:
                first=tmp[0]
                second=tmp[0]
                break
        if tmp[1] >=2:
                if first==0:
                        first=tmp[0]
                else:
                        second=tmp[0]
                        break
print(first*second)

Submission status: Accepted

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

edge = []

for i in range(1,N):
  if A[i] == A[i - 1] and A[i] not in edge:
    edge.append(A[i])
  elif A[i] == A[i - 3]:
    edge.append(A[i])
  
  if len(edge) == 2:
    break
    
if len(edge) <= 1:
  print(0)
else:
  print(edge[0] * edge[1])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
Ac = Counter(list(map(int, input().split())))
over2 = [ele for ele in Ac.items() if ele[1]>=2]
if len(over2) == 0:
  print(0)
elif len(over2) == 1:
  if over2[0][1] >= 4:
    print(over2[0][0]**2)
else:
  over2.sort(reverse=True)
  if over2[0][1] >= 4:
    print(over2[0][0]**2)
  else:
    print(over2[0][0]*over2[1][0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N = Scanner.int()
    A = Scanner.map_int()
    A.sort(reverse = True)
    h,w = 0,0
    i = 0
    while i < N - 1:
        if A[i] == A[i + 1]:
            if h == 0:
                h = A[i]
                i +=1
            else:
                w = A[i]
                break
        i += 1
    print(h * w)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
from collections import Counter
INF = float('inf')


N=int(input())
An=sorted(list(map(int, input().split())))
# 各要素の出現回数をカウント
C = Counter(An)
# 1回以上出現しているものを抽出
C = [(k ,v) for k, v in C.items() if v > 1]
if len(C) < 2:
    print(0)
else:
    C = sorted(C, key=lambda x:x[0])
    # 正方形
    if C[-1][1] >= 4:
        print(C[-1][0] ** 2)
    else:
        print(C[-1][0]*C[-2][0])

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = map(int, input().split())
A_count = dict(collections.Counter(A))
A_countsort = sorted(A_count, reverse=True)
# print(A_countsort)
hen_list = []
for key in A_countsort:
    if A_count[key] >= 4:
        hen_list.append(key)
        hen_list.append(key)
    elif A_count[key] >= 2:
        hen_list.append(key)

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

Submission status: Accepted

Solution code:
from collections import Counter
N, *A = map(int, open(0).read().split())
C = Counter(A)
C = [(k,v) for k,v in C.items() if v > 1]
if len(C) < 2:
  print(0)
else:
  C = sorted(C, key=lambda x:x[0])
  if C[-1][1] >= 4:
    print(C[-1][0]**2)
  else:
    print(C[-1][0]*C[-2][0])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
p = A[0]
ok = -1
v = []
for i in range(N):
    if len(v) == 2:
        break
    if ok == 1:
        v.append(A[i-1])
        ok = -1
    if A[i] == p:
        ok += 1
    else:
        p = A[i]
        ok = 0
if ok == 1:
    v.append(A[i-1])
if len(v) <=1:
    print(0)
else:
    print(v[0]*v[1])

Submission status: Accepted

Solution code:
n=int(input())
a=map(int,input().split())
a=sorted(a)
a=list(reversed(a))
h,w=0,0
tmp=0
f=0
for x in a:
    if tmp==x:
        if w!=0:
            h=x
            break
        else:
            w=x
            tmp=0
            continue
    tmp=x
print(w*h)

Submission status: Accepted

Solution code:
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter
    import heapq

    n = int(input())

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

    b = []
    heapq.heapify(b)
    ln = 0
    cou = 0
    for i in a:
        if ln != i:
            ln = i
            cou = 0
        cou += 1
        if cou > 1:
            heapq.heappush(b, -i)
            cou = 0
    try:
        print(heapq.heappop(b)*heapq.heappop(b))
    except:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter
    import heapq

    n = int(input())

    def fun(i):
        return -int(i)

    a = list(map(fun, input().split()))
    heapq.heapify(a)

    b = []
    heapq.heapify(b)
    ln = 0
    cou = 0
    mn = 0
    while(len(a) > 0):
        i = -heapq.heappop(a)
        # print(i)
        if ln != i:
            ln = i
            cou = 0
        cou += 1
        if cou > 1:
            heapq.heappush(b, -i)
            cou = 0
    try:
        print(heapq.heappop(b)*heapq.heappop(b))
    except:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Ac = Counter(A)
flag = False
a = 0
b = 0
ac2 = sorted(Ac.items(),reverse=True)
for k,v in ac2:
    if v < 2:
        continue
    elif v >= 4:
        if flag:
            b = k
            break
        else:
            a = k
            b = k
            break
    else:
        if flag:
            b = k
            break
        else:
            a = k
            flag = True
print(a*b)

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(ls)

ls_s = c.most_common()
ls_s.sort(reverse=True)

mul = []

for i in range(len(ls_s)):
    if ls_s[i][1] >= 4:
        if len(mul) == 0:
            print(ls_s[i][0] ** 2)
            break
        elif len(mul) == 1:
            print(ls_s[i][0] * mul[0])
            break
    elif ls_s[i][1] >= 2:
        mul.append(ls_s[i][0])
    
    if len(mul) >= 2:
        print(mul[0] * mul[1])
        break
    elif i == len(ls_s) - 1:
        print(0)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
flg = False
new_ct = []
for i, j in sorted(ct.items(), key=lambda x:x[0], reverse=True):
    if j >= 4:
        flg = True
    if j > 1:
        new_ct.append((i, j))
if len(new_ct) == 0:
    print(0)
elif len(new_ct) == 1 and not flg:
    print(0)
else:
    if new_ct[0][1] >= 4:
        print(new_ct[0][0] ** 2)
    else:
        print(new_ct[0][0] * new_ct[1][0])

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=Counter(sorted(list(map(int,input().split()))))
A=[[i,A[i]] for i in A if A[i]>=2]
A.sort(reverse=True)
try:
    if A[0][1]>=4:
        print(A[0][0]**2)
    else:
        print(A[0][0]*A[1][0])
except:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
aset = set()
a2set = set()
a3set = set()
a4set = set()
for i in a:
    if i in a3set:
        a4set.add(i)
    if i in a2set:
        a3set.add(i)
    if i in aset:
        a2set.add(i)
    aset.add(i)
if len(a2set) < 2 and len(a4set) == 0:
    ans = 0
else:
    x = max(a2set)
    if x in a4set:
        ans = x ** 2
    else:
        a2set.remove(x)
        y = max(a2set)
        ans = x * y
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = (A[d:d+4]).count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
A = Counter(A).most_common()
A = sorted(A)[::-1]
cnt = 0
l = []
ans = [0]
for i, v in A:
  if v >= 4:
    ans.append(i*i)
  if 2<=v:
    cnt += 1
    l.append(i)
    if cnt == 2:
      ans.append(l[0]*l[1])
print(max(ans))

Submission status: Accepted

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

d = dict()
for a in A:
    d[a] = d.get(a, 0) + 1

two, four = [], []
for k, v in d.items():
    if v >= 2:
        two.append(k)
    if v >= 4:
        four.append(k)

two = sorted(two)
four = sorted(four)
ans = []
if four != []:
    ans.append(four[-1]**2)
if len(two) >= 2:
    ans.append(two[-1]*two[-2])

if ans == []:
    print(0)
else:
    print(max(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:
import collections
n = int(input())
a = list(map(int, input().split()))
s = collections.Counter(a)
c = []
for i in s.keys():
	if s[i] >= 2:
		c.append(i)
c.sort(reverse=  True)
if len(c) < 2:
	print (0)
else:
	if s[c[0]] >= 4:
		print (c[0]**2)
	else:
		print (c[0]*c[1])

Submission status: Accepted

Solution code:
#第二問　make a rectangle
import collections
n=int(input())
lists=list(map(int,input().split()))
A=dict(collections.Counter(lists))
dictdict=[]


for j in A.keys():
    for _ in range(A[j]//2):
        dictdict.append(j)

dictdict=sorted(dictdict,reverse=True)
if len(dictdict)>=2:
    print(dictdict[0]*dictdict[1])
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a = collections.Counter(a)
    c = 0
    t = 0
    for k, v in sorted(a.items(), reverse=True):
        if v >= 4:
            print(k * k if c == 0 else t * k)
            exit()
        elif v >= 2:
            if c != 0:
                print(t * k)
                exit()
            else:
                t += k
                c += 1
    print(0)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

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

d = {}
for i in range(N):
    if A[i] not in d:
        d[A[i]] = 0
    d[A[i]] += 1


ans = {0}
s1 = [k for k, v in d.items() if v >= 4]
if len(s1) > 0:
    s1.sort()
    ans.add(s1[-1] ** 2)

s2 = [k for k, v in d.items() if v >= 2]
if len(s2) >= 2:
    s2.sort()
    ans.add(s2[-1] * s2[-2])

print(max(ans))

Submission status: Accepted

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

import collections

c = collections.Counter(a)
cs = sorted(c.items(), key=lambda x:x[0],reverse=True)
a=[0,0]
f=0
sq=0
for i in cs:
    if sq == 0 and i[1] >= 4:
        sq=i[0]**2
    if i[1] >= 2:
        a[f]=i[0]
        f+=1
    if f >= 2:
        break
print(max(sq,a[0]*a[1]))

Submission status: Accepted

Solution code:
from collections import Counter

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

a = list(Counter(A).items())
b = []

for i in range(len(a)):
    if a[i][1] >= 4:
        b.append(a[i][0])
        b.append(a[i][0])
    elif a[i][1] >= 2:
        b.append(a[i][0])

if len(b) < 2:
    print(0)
else:
    b.sort()
    print(b[-2] * b[-1])

Submission status: Accepted

Solution code:
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=1
cnt=0
i=0
while i<n-1 and cnt<2:
    if a[i]==a[i+1]:
        ans*=a[i]
        i+=2
        cnt+=1
    else:
        i+=1
if cnt==2:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]
c=collections.Counter(a)
d=list(c.keys())
d.sort()
d=d[::-1]
z=0
ans=1
for i in d:
    if c[i]>=4:
        if z==0:
            print(i**2)
            break
        elif z==2:
            ans*=i
            print(ans)
            break
    elif 2<=c[i]<=3:
        if z==0:
            z+=2
            ans*=i
            continue
        elif z==2:
            ans*=i
            print(ans)
            break
else:
    print(0)

Submission status: Accepted

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

f = 0
x = 0
for i in range(len(a)-1):
    if a[i] == a[i+1] != x:
        f += 1
    if f == 1:
        x = a[i]
        f += 1
        if a.count(x) >= 4:
          f = 3
    if f >= 3:
        print(x*a[i])
        exit()
print(0)

Submission status: Accepted

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

A.sort(reverse = True)
one = 0
two = 0
idx = 1
while idx < N:
  if A[idx-1]==A[idx]:
    one = A[idx]
    break
  idx += 1
idx += 2
while idx < N:
  if A[idx-1]==A[idx]:
    two =A[idx]
    break
  idx += 1
print(one*two)

Submission status: Accepted

Solution code:
import heapq
N = int(input())
A = list(map(int, input().split()))
hq = []
for i in range(N):
    heapq.heappush(hq, -A[i])
X, x1, x2, Y, y1, y2= 0, 0, 0, 0, 0, 0
x1 = -heapq.heappop(hq)
while hq:
    x2 = -heapq.heappop(hq)
    if x1 == x2:
        X = x1
        break
    else:
        x1 = x2
if len(hq) != 0:
    y1 = -heapq.heappop(hq)
    while hq:
        y2 = -heapq.heappop(hq)
        if y1 == y2:
            Y = y1
            break
        else:
            y1 = y2
print(X*Y)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
l = []
for key in A:
  d[key] += 1
  if d[key] == 2:
    l.append(key)
    d[key] = 0
if len(l) < 2:
  print(0)
else:
  l.sort(reverse=True)
  print(l[0]*l[1])

Submission status: Accepted

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

Submission status: Accepted

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

Dict={}
for i in A:
    if(Dict.get(i,None)==None):
        Dict[i]=1
    else:
        Dict[i]+=1

T=1
C=0
Dict = sorted(Dict.items(), key=lambda x:-x[0])
for i in Dict:
    if((i[1]>=2)&(C>=1)):
        T*=i[0]
        C+=1
        break
    if(i[1]>=4):
        T*=i[0]*i[0]
        C=2
        break
    if(i[1]>=2):
        T*=i[0]
        C+=1

if(C==2):
    print(T)
else:
    print("0")

Submission status: Accepted

Solution code:
import sys
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    s = set()
    q = [0, 0]
    for a in map(int, input().split()):
        if a > q[0]:
            try:
                s.remove(a)
                heapq.heapreplace(q, a)
            except:
                s.add(a)
    print(q[0]*q[1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import math
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    n=int(input())
    a = list(map(int,input().split()))
    x={}
    for i in range(n):
        if a[i] not in x:
            x[a[i]]=1
        else:
            x[a[i]]+=1
    y=[]
    for i in x:
        if x[i]>=2:
            y.append(i)
            if x[i]>=4:
                y.append(i)
    y.sort(reverse=True)
    if len(y)>=2:
        print(y[0]*y[1])
    else:
        print(0)

main()

Submission status: Accepted

Solution code:
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  ans = 0
  a = sorted(a,reverse = True)
  query = []
  flag = False
  for i in range(n-1):
    if flag:
      flag = False
      continue
      
    if a[i] == a[i+1]:
      query.append(a[i])
      flag = True

  if len(query)>=2:
    ans = query[0]*query[1]
  print(ans)
solve()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = Counter(list(map(int, input().split())))
A = {k: v for k, v in A.items() if v >= 2}
A = sorted(A.items(), key=lambda x: x[0], reverse=True)
A.extend([(0, 0), (0, 0)])
if A[0][1] >= 4:
    print(A[0][0]**2)
else:
    print(A[0][0]*A[1][0])

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
up2_max = 0
up2_2nd = 0
up4_max = 0

from bisect import bisect_left, bisect_right
B = sorted(list(set(A)), reverse=True)
for cand in B:
  num = bisect_right(A, cand) - bisect_left(A, cand)
  if num >= 4:
    up4_max = cand
    break
for i, cand in enumerate(B):
  num = bisect_right(A, cand) - bisect_left(A, cand)
  if num >= 2:
    up2_max = cand
    break
for j in range(i+1, n):
  num = bisect_right(A, B[j]) - bisect_left(A, B[j])
  if num >= 2:
    up2_2nd = B[j]
    break
print(max(up4_max**2, up2_max * up2_2nd))

Submission status: Accepted

Solution code:
n= int(input())
a= list(map(int, input().split()))
from collections import Counter
c= Counter(a).most_common()
c.sort(key=lambda x: x[0],reverse=True)
tate=0
kouho=0
sei=0
chou=0
for i in c:
    if sei==0 and i[1]>=4:
        if tate:
            sei=i[0]*tate
        else:
            sei=i[0]**2
    elif chou==0 and i[1]>=2:
        if tate:
            yoko=i[0]
            chou=yoko*tate
        else:
            tate=i[0]
print(max(chou,sei))

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
w = 0
h = 0
for i in range(n-1):
    if a[i] == a[i+1] and w == 0:
        w = a[i]
        a[i+1] = 0
    if a[i] == a[i+1] and w != 0:
        h = a[i]
        break
if w == 0 or h == 0:
    ans = 0
else:
    ans = int(h*w)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
flag1 = 1
flag2 = 0
w = 0
h = 0
for i in range(n-1):
    flag2 = 1
    if a[i] == a[i+1] and flag1:
        w = a[i]
        a.pop(i+1)
        flag1 = 0
        flag2 = 0
    if a[i] == a[i+1] and flag2:
        h = a[i]
        break
if w == 0 or h == 0:
    ans = 0
else:
    ans = int(h*w)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    c = sorted([[k, v] for k, v in c.items() if v > 1])
    if len(c) < 2:
        print(0)
        return
    if c[-1][1] >= 4:
        print(c[-1][0] ** 2)
    else:
        print(c[-1][0] * c[-2][0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections 

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

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

x,y=0,0
for a in A:
  if x and a[1]>=2:
    y=a[0]
    break
  if a[1]>=2:
    if a[1]>=4:
      x,y=a[0],a[0]
      break
    else:
      x=a[0]
#print(x,y)
print(x*y)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=map(int,input().split())
    from collections import Counter
    c=Counter(A)
    ans=0
    first=0
    second=0
    for k,v in c.items():
        if v>=4: ans=max(ans,k*k)
        if v>=2:
            if k>first:
                first,second=k,first
            elif k>second:
                second=k
    print(max(ans,first*second))
resolve()

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = [0, 0]
for k in sorted(A.keys(), reverse=True):
    if A[k] >= 2:
        ans.append(k)
    if A[k] >= 4:
        ans.append(k)
ans = sorted(ans)
print(ans[-1]*ans[-2])

Submission status: Accepted

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

A.sort(reverse=True)

cnt=1
r=[]
for i in range(1,N):
    if A[i-1]==A[i]:
        cnt+=1
    else:
        if len(r)==0 and cnt>=4:
            print(A[i-1]*A[i-1])
            exit()
        elif cnt>=2:
            r.append(A[i-1])
            if len(r)==2:
                print(r[0]*r[1])
                exit()
            cnt=1
        else:
            cnt=1
if cnt>=2:
    r.append(A[i-1])
    if len(r)==2:
        print(r[0]*r[1])
        exit()

print(0)

Submission status: Accepted

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

rect = [-1, -1]
for key in sorted(A.keys(), reverse=True):
  if A[key] >= 4:
    print(max(rect[0]*key, key**2))
    exit()
  elif A[key] >= 2:
    if rect == [-1,-1]: rect[0] = key
    else:
      print(rect[0]*key)
      exit()
print(0)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = Counter(list(map(int, input().split())))
x = [0, 0]
for a in A:
    if A[a] >= 2:
        x.append(a)
    if A[a] >= 4:
        x.append(a)
x.sort()
print(x[-1] * x[-2])

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a = sorted(collections.Counter(a).most_common(), key=lambda x: x[0], reverse=True)
    ans = []
    for k, v in a:
        if v >= 2:
            for i in range(v // 2 * 2):
                ans.append(k)
        if len(ans) >= 4:
            print(ans[0] * ans[2])
            exit()
    print(0)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

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


dic = collections.defaultdict(int)

for x in A:
    dic[x] += 1

dic = list(dic.items())
dic = [x for x in dic if x[1] >= 2]
dic = sorted(dic, reverse=True, key=lambda x: x[0])

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

Submission status: Accepted

Solution code:
import heapq

N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: -x, A))

heapq.heapify(A)
a = - heapq.heappop(A)
for i in range(N-1):
    b = - heapq.heappop(A)
    if a == b:
        x = a
        break
    else:
        a = b
else:
    x = 0

if len(A) >= 2:
    c = - heapq.heappop(A)
    for j in range(len(A)):
        d = - heapq.heappop(A)
        if c == d:
            y = c
            break
        else:
            c = d
    else:
        y = 0
else:
    y = 0

ans = x*y
print(ans)

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

h,w=0,0
l=0
n=int(input().rstrip())
a=sorted(Counter([int(i) for i in input().split()]).most_common(),reverse=1)
#print(a)
for i in range(len(a)):
    if a[i][1]>=4:
        print(a[i][0]**2)
        exit()
    elif a[i][1]>=2:
        h=a[i][0]
        l=i+1
        break

for i in range(l,len(a)):
    if a[i][1]>=2:
        w=a[i][0]
        break
print(h*w)