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: Time Limit Exceeded

Solution code:
N=int(input())
list1=[]
L=list(map(int,input().split()))
L.sort(reverse=True)
cnt=1
for i in range(N-1):
    if L[i]!=L[i+1]:
        list1.append([L[i],L.count(L[i])])
list1.append([L[len(L)-1],L.count(L[len(L)-1])])
#print(list1)     
H=0
i=0
for i in range(len(list1)):
    if list1[i][1]>=4:
        if H==0:
            print(list1[i][0]**2)
            exit()
        else:
            print(H*list1[i][0])
            exit()
    elif list1[i][1]>=2:
        if H==0:
            H=list1[i][0]
        else:
            print(H*list1[i][0])
            exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ac = sorted(list(set(a)))
ans = []
for i in ac[::-1]:
    c = a.count(i)
    if len(ans) == 2:
        break
    if not ans and c >= 4:
        print(i ** 2)
        exit()
    if c >= 2:
        ans.append(i)
if len(ans) == 2:
    print(ans[0] * ans[1])
else:
    print(0)

Submission status: Time Limit Exceeded

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

use_1 = 0
use_2 = 0
for i in set(a):
    can = a.count(i) // 2
    if can == 1:
        if use_1 < i:
            use_2 = use_1
            use_1 = i
    elif can > 1:
         use_1 = max(use_1, i)
         use_2 = max(use_2, i)

print(use_1*use_2)

Submission status: Time Limit Exceeded

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

use = []
for i in set(a):
    can = a.count(i) // 2
    if can > 0:
        for j in range(can):
            use.append(i)
use.sort()
if len(use) > 1:
    print(use[-1] * use[-2])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))


def main():
    n = int(input())
    a = readLine_int_list()
    set_a = sorted(list(set(a)), reverse=True)
    
        
    
    pair = []
    
    ans = 0
    if len(a) - len(set_a) == 1:
        print(ans)
    else:
        for i in set_a:
            c = a.count(i)
            if c > 3:
                pair.append(i)
                pair.append(i)
            elif c > 1:
                pair.append(i)
                
            if len(pair) >= 2:
                ans = pair[0] * pair[1]
                break
    
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))


def main():
    n = int(input())
    a = readLine_int_list()
    set_a = sorted(list(set(a)), reverse=True)
    
    pair = []
    
    ans = 0
    for i in set_a:
        c = a.count(i)
        if c > 3:
            pair.append(i)
            pair.append(i)
        elif c > 1:
            pair.append(i)
            
        if len(pair) >= 2:
            ans = pair[0] * pair[1]
            break

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    if a_n.count(max(a_n))>=2:
        if a_n.count(max(a_n))>=4:
            print(max(a_n)**2)
            sys.exit()
        else:
            a=max(a_n)
            for k in range(a_n.count(max(a_n))):
                a_n.remove(max(a_n))
            break
    else:
        a_n.remove(max(a_n))

if not a_n:
    print(0)
    sys.exit()

for i in range(N):
    if a_n.count(max(a_n))>=2:
        b=max(a_n)
        print(a*b)
        sys.exit()
    else:
        a_n.remove(max(a_n))

print(0)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
import sys
N = int(input())
A = list(map(int, input().split()))
a = list(reversed(sorted(list(set(A)))))
width = -1
height = -1
candinate = []
for tmp in a:
    b = A.count(tmp)
    if b >= 4:
        if width == -1:
            width = tmp
        if height == -1:
            height = tmp
    elif b >= 2:
        if width == -1:
            width = tmp
            b = 0
        if height == -1 and b != 0:
            height = tmp
    else:
        pass
    if width != -1 and height != -1:
        print(width*height)
        sys.exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
length = list(map(int, input().split()))
double = []

for i in length:
    if length.count(i) >= 4:
        while i in length:
            length.remove(i)
        double = double + [i, i]

    elif length.count(i) >= 2:
        while i in length:
            length.remove(i)
        double = double + [i]

double = sorted(double)
if double != []:
    print(double[-2] * double[-1])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
input()
a=sorted(list(map(int,input().split())))
e=[1 for x in range(10**9+1)]
r=[]
for i in a:
  if e[i]:
    e[i]=0
  else:
    e[i]=1
    r.append(i)
print(0 if len(r) < 2 else r[-1] * r[-2])

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8
import numpy as np
_=input()
bars=[i for i in map(int,input().split())]
np_data=np.array(bars)
bars.sort(reverse=True)

stock=[]
len_stock=0
ret=0
_old=-1
for bar in bars:
    if bar==_old:
        continue
    _old=bar
    count=np.where(np_data==bar)[0].size
    if count>=4:
        if len_stock!=0 and  bar not in stock:
            #print("ret bar bar")
            ret=bar*stock[0]
        else:
            #print("ret bar bar")
            ret=bar*bar
        break
    elif count>=2:
        if bar in stock:
            continue
        stock.append(bar)
        len_stock+=1
        if len_stock==2 :
            #print("ret stock stock")
            ret=stock[0]*stock[1]
            break
print(ret)

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8
_=input()
bars=[i for i in map(int,input().split())]
bars.sort(reverse=True)
stock=[]
ret=0
_old=-1
for bar in bars:
    if bar==_old:
        continue
    _old=bar
    count=bars.count(bar)
    if count>=4:
        if len(stock)!=0 and  bar not in stock:
            #print("ret bar bar")
            ret=bar*stock[0]
        else:
            #print("ret bar bar")
            ret=bar*bar
        break
    elif count>=2:
        if bar in stock:
            continue
        stock.append(bar)
        if len(stock)==2 :
            #print("ret stock stock")
            ret=stock[0]*stock[1]
            break
print(ret)

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8
_=input()
bars=[i for i in map(int,input().split())]
bars.sort(reverse=True)
stock=[]
ret=0
for bar in bars:
    count=bars.count(bar)
    if count>=4:
        if len(stock)!=0 and  bar not in stock:
            #print("ret bar bar")
            ret=bar*stock[0]
        else:
            #print("ret bar bar")
            ret=bar*bar
        break
    elif count>=2:
        if bar in stock:
            continue
        stock.append(bar)
        if len(stock)==2 :
            #print("ret stock stock")
            ret=stock[0]*stock[1]
            break
print(ret)

Submission status: Time Limit Exceeded

Solution code:
#coding-utf-8

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

A_item = sorted(list(set(A)))[::-1]

S_index = []

for a in A_item:
    tmp = A.count(a)
    num = tmp//2
    S_index += [a]*num
    if len(S_index)>=2:
        break

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
t = [int(i) for i in input().split()]
ans = []
for i in t:
  if i in ans:
    continue
  c = t.count(i)
  if c >= 2:
    if c >= 4:
      ans.extend([i,i])
    else:
      ans.append(i)
ans.sort()
if len(ans) < 2:
  print(0)
else:
  print(ans[-1]*ans[-2])

Submission status: Time Limit Exceeded

Solution code:
n = input()
t = [int(i) for i in input().split()]
ans = []
for i in t:
  if i in ans:
    continue
  c = t.count(i)
  if c >= 2:
    if c >= 4:
      ans.extend([i,i])
    else:
      ans.append(i)
ans.sort()
if len(ans) < 2:
  print(0)
else:
  print(ans[-1]*ans[-2])

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    tmp_max_square = 0
    tmp_max_dup_1 = 0
    tmp_max_dup_2 = 0
    while len(A) != 0:
        tmp = A[0]
        tmp_count = A.count(tmp)
        # print(tmp_count)
        if tmp_count >= 4:
            if tmp_max_square < tmp:
                tmp_max_square = tmp

            if tmp_max_dup_2 < tmp < tmp_max_dup_1:
                tmp_max_dup_2 = tmp
            elif tmp_max_dup_1 <= tmp:
                tmp_max_dup_2 = tmp_max_dup_1
                tmp_max_dup_1 = tmp
        elif tmp_count >= 2:
            if tmp_max_dup_2 < tmp < tmp_max_dup_1:
                tmp_max_dup_2 = tmp
            elif tmp_max_dup_1 <= tmp:
                tmp_max_dup_2 = tmp_max_dup_1
                tmp_max_dup_1 = tmp

        for i in range(tmp_count):
            A.remove(tmp)

    square_ans = tmp_max_square * tmp_max_square
    rectan_ans = tmp_max_dup_1 * tmp_max_dup_2
    if square_ans < rectan_ans:
        print(rectan_ans)
    else:
        print(square_ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    t = set()
    no_dup = list(set([x for x in A if x in t or t.add(x)]))
    square_list = []
    for i in no_dup:
        if 4 <= A.count(i):
            square_list.append(i)

    no_dup.sort(reverse=True)
    if len(no_dup) == 0:
        print(0)
    else:
        if len(square_list) == 0:
            square_area = 0
        else:
            square_max = max(square_list)
            square_area = square_max * square_max
            
        if len(no_dup) == 1:
            rectan_area = 0
        else:
            rectan_area = no_dup[0] * no_dup[1]
            
        if square_area < rectan_area:
            print(rectan_area)
        else:
            print(square_area)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    t = set()
    dup = [x for x in A if x in t or t.add(x)]
    no_dup = list(set(dup))
    square_list = []
    for i in no_dup:
        if 3 <= dup.count(i):
            square_list.append(i)

    no_dup.sort(reverse=True)
    square_list.sort(reverse=True)
    if len(no_dup) == 0:
        print(0)
    else:
        if len(square_list) == 0:
            square_area = 0
        else:
            square_area = square_list[0] * square_list[0]
        if len(no_dup) == 1:
            rectan_area = 0
        else:
            rectan_area = no_dup[0] * no_dup[1]
        if square_area < rectan_area:
            print(rectan_area)
        else:
            print(square_area)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
  if A[i] in B:
    C+=[A[i]]
    B.remove(A[i])
  else: 
    B+=[A[i]]
C.sort(reverse=1)
if len(C)<2:
  print(0)
else:
  print(C[0]*C[1])

Submission status: Accepted

Solution code:
from collections import Counter

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

over4 = []
over2 = []

for k, v in c.items():
    if v >= 4:
        over4.append(k)
    elif v >= 2:
        over2.append(k)

over4.sort(reverse=True)
over2.sort(reverse=True)

x, y, z = 0, 0, 0
if len(over4) > 0:
    x = over4[0] ** 2
if len(over2) >= 2:
    y = over2[0] * over2[1]
if len(over4) > 0 and len(over2) > 0:
    z = over4[0] * over2[0]

print(max(x, y, z))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ac=Counter(a)
v=sorted(ac.items(),reverse=1)
ans=[]
ans1=[]

for i in range(len(ac)):
  if v[i][1]>=2:
    ans.append(v[i][0])
  if v[i][1]>=4:
    ans1.append(v[i][0])
if len(ans)>=2:
  if len(ans1)>=1:
      print(max(ans[0]*ans[1],ans1[0]**2))
  else:
      print(ans[0]*ans[1])
else:
  if len(ans1)>=1:
      print(max(0,ans1[0]**2))
  else:
      print(0)

Submission status: Accepted

Solution code:
import collections
n = int(input())
aa = list(map(int, input().split()))
ca = collections.Counter(aa)
la = sorted([a for a in ca.items()], key = lambda x:x[0], reverse=True)

list1 = []
list2 = []

for a in la:
  if a[1] > 1:
    list1.append(a)
  if a[1] >3:
    list2.append(a)
    
if len(list1) > 1:    
    xr = list1[0][0] * list1[1][0]
else:
  xr = 0
    
if len(list2) > 0:
  xs = list2[0][0] * list2[0][0]
else:
  xs = 0
  
ans = max(xr, xs)

print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
aa = list(map(int, input().split()))
ca = collections.Counter(aa)
la = sorted([a for a in ca.items()], key = lambda x:x[0], reverse=True)

list1 = []
list2 = []

for a in la:
  if a[1] > 1:
    list1.append(a)
  if a[1] >3:
    list2.append(a)
    
if len(list1) > 1:    
    xr = list1[0][0] * list1[1][0]
else:
  xr = 0
    
if len(list2) > 0:
  xs = list2[0][0] * list2[0][0]
else:
  xs = 0
  
ans = max(xr, xs)

print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
alist = list(map(int,input().split()))
adic = collections.Counter(alist)
A = [0,0]
for i in adic:
  if adic[i] > 1:
    A.append(i)
  if adic[i] > 3:
    A.append(i)
sortedA = sorted(A)
print(sortedA[-1]*sortedA[-2])

Submission status: Accepted

Solution code:
N = int(input())
List = list(map(int,input().split()))
List = sorted(List)[::-1]
L = 0
S = 0
temp = 0
for i in range(N-1):
  if List[i] == List[i+1]:
    L = List[i]
    temp =i+1
    break
for i in range(temp+1,N-1):
  if List[i] == List[i+1]:
    S = List[i]
    break
print(L*S)

Submission status: Accepted

Solution code:
from collections import Counter

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

over4 = []
over2 = []

for k, v in c.items():
    if v >= 4:
        over4.append(k)
    elif v >= 2:
        over2.append(k)

over4.sort(reverse=True)
over2.sort(reverse=True)

s1, s2, s3 = 0, 0, 0
if len(over4) > 0:
    s1 = over4[0]**2
if len(over2) >= 2:
    s2 = over2[0]*over2[1]
if len(over4) > 0 and len(over2) > 0:
    s3 = over4[0]*over2[0]

print(max(s1, s2, s3))

Submission status: Accepted

Solution code:
# import math
# import statistics
# import itertools
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
# e1,e2,e3,e4 = map(int,input().split())
f = list(map(int,input().split()))
# g = [int(input()) for _ in range(a)]

f.sort()
ma =[]
count=1
for i in range(len(f)-1):
    if f[i]==f[i+1] and f[i]!=0:
        count+=1
    elif f[i]!=f[i+1] and count>=2 :
        ma.append(f[i])
        count=1
    elif  f[i]!=f[i+1] and count==1 :
        count=1
    else:
        count=1

if count>=4:
    ma.append(f[-1])
    ma.append(f[-1])
elif count>=2:
    ma.append(f[-1])


if ma==[]:
    print(0)
else:
    print(ma[-1]*ma[-2])

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
a = l()

a.sort(reverse=True)
b = -1

for i in a:
    if i==b:
        if ans != 0:
            ans *= i
            break
        else:
            ans = i
            b = -1
            continue
    b = i
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
b=-1
for i in a:
  if i==b:
    if ans!=0:
      ans*=i
      break
    else:
      ans=i
      b=-1
      continue
  b=i
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = Counter(A)

parts = []
for k in sorted(cnt.keys(),reverse=True):
    if cnt[k] >= 4:
        parts += [k,k]
    elif cnt[k] >= 2:
        parts.append(k)

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

Submission status: Accepted

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

cnt = collections.Counter(a)
l1 = 0
l2 = 0

for i in cnt.keys():
    if cnt[i] >= 4:
        l1 = i
        l2 = i
    elif cnt[i] >= 2:
        l1, l2 = i, l1
print(l1 * l2)

Submission status: Accepted

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

one = 0
theo = 0
skip = False
for i in range(N-1):
    if skip:
        skip = False
        continue
    if A[i] == A[i+1]:
        if one == 0:
            one = A[i+1]
            skip = True
        else:
            theo = A[i+1]
            break
print(one*theo)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
A=Counter(a)
s=set(a)
S=sorted(list(s))
S.reverse()
h=0
w=0
for i in S:
  res=A[i]
  if res>=4:
    if h==0:
      h=i
    if w==0:
      w=i
  elif 2<=res<4:
    if w==0:
      w=i
    elif w!=0 and h==0:
      h=i
print(h*w)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    dct = defaultdict(int)
    for a in A:
        dct[a] += 1
    # print(sorted(dct.items(), key=lambda x: x[0], reverse=True))
    # ans = 0
    left = 2
    pre = 0
    for n, c in sorted(dct.items(), key=lambda x: x[0], reverse=True):
        # print(n, c)
        if c >= 4:
            if left == 2:
                print(n ** 2)
                return
            elif left == 1:
                print(pre * n)
                return
        elif c >= 2:
            if left == 2:
                pre = n
                left -= 1
                continue
            elif left == 1:
                print(pre * n)
                return
    print(0)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class countdict(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1        

N,A = ilint()
S = countdict()
L = list()
for a in A:
    S.add(a)
    if S[a]>=2:
        L.append(a)
        S[a] -= 2
L.sort(reverse=True)
print(0 if len(L)<2 else L[0]*L[1])

Submission status: Accepted

Solution code:
from collections import Counter

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

B = set(A)
C = sorted(list(B))
A = Counter(A)


ans = 0
keep = 0

for i in C:
    kazu = A[i]
    if kazu >= 4:
        ans = i**2
        keep = i
    elif kazu >= 2:
        ans = keep * i
        keep = i
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
b=a.sort(reverse=True)
for i in range(n-1):
    if a[i]==a[i+1]:
        for j in range(i+2,n-1):
            if a[j]==a[j+1]:
                print(a[i]*a[j])
                exit()
else:
    print(0)

Submission status: Accepted

Solution code:
#49 C - Make a Rectangle
import collections 
N = int(input())
A = map(int,input().split())

cnt = collections.Counter(A)
# 2 個以上含まれる数字をリストアップ
cnt_2 = [i for i , j in cnt.items() if j>=2]
# 4 個以上含まれる数字をリストアップ
cnt_4 = [i for i, j in cnt.items() if j>=4]
# 降順にソート
cnt_2 = sorted(cnt_2,reverse = True)
cnt_4 = sorted(cnt_4,reverse = True)

ans1 = 0
ans2 = 0 
if len(cnt_2) >=2:
    ans1 = cnt_2[0]*cnt_2[1]
if len(cnt_4) >=1:
    ans2 = cnt_4[0]**2
    
print(max(ans1,ans2))

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

x = [(l, n) for l, n in sorted(d.items(), reverse=True, key=lambda x:x[0]) if n >= 2]
y = [(l, n) for l, n in sorted(d.items(), reverse=True, key=lambda x:x[0]) if n >= 4]

if x == [] and y == []:
    print(0)
else:
    ans = 0
    if len(x) >= 2:
        ans = max(ans, x[0][0] * x[1][0])
    if len(y) >= 1:
        ans = max(ans, y[0][0]**2)
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
count_a = Counter(a)
new_a = [i for i in count_a.keys() if count_a[i] >= 2]
#print(new_a)
if len(new_a) < 2:
    print(0)
    exit()
new_a = sorted(new_a, reverse=True)
if count_a[new_a[0]] >= 4:
    ans = new_a[0] ** 2
else:
    ans = new_a[0] * new_a[1]
print(ans)

Submission status: Accepted

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

d = {}
l = []
for a in A:
  if a in d:
    d[a] += 1
    if d[a] % 2 == 0:
      l.append(a)
  else:
    d[a] = 1
  
  if len(l) == 2:
    print(l[0] * l[1])
    quit()

print(0)

Submission status: Accepted

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

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

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

l2.sort()
l4.sort()
if len(l2) > 1:
    if len(l4) > 0:
        ans = max(l2[-1]*l2[-2], l4[-1]**2)
    else:
        ans = l2[-1]*l2[-2]
elif len(l2) == 1:
    if len(l4) > 0:
        ans = l4[-1]**2
    else:
        ans = 0
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

A = sorted(A.items(), key=lambda x: -x[0])

x = []
while len(x) < 2:
    for a, cnt in A:
        while cnt > 1 and len(x) < 2:
            x.append(a)
            cnt -= 2
    else:
        break

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

Submission status: Accepted

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

b1 = [i[0] for i in c.items() if i[1] >= 4]
b2 = [i[0] for i in c.items() if i[1] >= 2]
b = b1 + b2 + [0,0]

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A_Counter = Counter(A)
A_Counter = sorted(A_Counter.items(), key=lambda x:x[0],reverse=True)



anslis = []
count = 0 
for single in A_Counter:

    key = int(single[0])
    value = int(single[1])
    
    if value >= 4:
        if count == 0:
            anslis.append(int(key))
            break
        else:
            anslis.append(int(key))
            count += 1
    
    if 2 <= value <= 3:
        anslis.append(int(key))
        count += 1
    
    if count == 2:
        break

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

Submission status: Accepted

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

x = [0,0]
for key, value in A.items():
    if A[key] > 1:
        x.append(key)
    if A[key] > 3:
        x.append(key)
x = sorted(x)

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
li=[]
A.sort()
s=True

for i in range(N-1):
    if A[i]==A[i+1] and s==True:
        li.append(A[i])
        s=False
    else:
        s=True
li.sort(reverse=True)

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
c=1
x=y=0
for i in range(n-1):
    if A[i]==A[i+1]:
        c+=1
        if c==2:
            if x!=0:
                y=A[i]
                break
            else:
                x=A[i]
        if c==4:
            x=y=A[i]
            break
    else:
        c=1
print(x*y)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(N-1):
    if A[i] == A[i+1]:
        for j in range(i+2, N-1):
            if A[j] == A[j+1]:
                print(A[i]*A[j])
                exit()
else:
    print(0)

Submission status: Accepted

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

L = R = 0
for k, v in c.items():
    if 4 <= v:
        L = max(L, k)
        R = max(R, k)
    elif 2 <= v:
        if R < L:
            L, R = R, L
        L = max(L, k)

print(L*R)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    a = LI()
    a.sort()
    gr = itertools.groupby(a)
    lst = []
    for key, group in gr:
        lenth = len(list(group))
        if lenth >= 4:
            lst.append(key)
        if lenth >= 2:
            lst.append(key)

    ans = 0
    if len(lst) >= 2:
        ans = lst[-1] * lst[-2]
    print(ans)
main()

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
four=0
two=[]
numbers=Counter(A)
for key,value in numbers.items():
    if value>=4:
        four=max(four,key**2)
    if value>=2:
        two.append(key)
sorted_two=sorted(two)
if four==0 and len(sorted_two)<=1:
    print(0)
else:
    print(max(four,sorted_two[-1]*sorted_two[-2]))

Submission status: Accepted

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

A.sort(reverse = True)
a=0
b=0
cnt = 1
for i in range(1,len(A)):
    if A[i]==A[i-1]:
        cnt+=1
    else:
        cnt=1
        
    if cnt==2:
        if a==0:
            a=A[i]
        elif b==0:
            b=A[i]
        cnt=0
        
        if a*b!=0:
            break

print(a*b)

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
d={}
for a in A:
    d[a] = d.get(a, 0)+1
s=sorted([(k,v) for k,v in d.items() if 2<=v], reverse=True)

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


n = inint()
A = inintl()

A = Counter(A)
b = []

m = 0

for a in A:
    if A[a] >= 4:
        if a > m:
            m = a
    if A[a] >= 2:
        b.append(a)

b = sorted(b)[::-1]


if len(b) < 2:
    if m != 0:
        print(m*m)
    else:
        print(0)
elif m*m > b[0]*b[1]:
    print(m*m)
else:
    print(b[0]*b[1])

Submission status: Accepted

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

a = list(map(int, input().split()))
c = Counter(a)
f = [0,0]
for k in c.keys():
    if c[k] >= 2:
        f.append(k)
    if c[k] >= 4:
        f.append(k)

f.sort()

[a, b] = f[-2:]

print(a*b)

Submission status: Accepted

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

a = [0] * 2
i = j = 0
while i < N - 1:
    if A[i] == A[i + 1]:
        a[j] = A[i]
        i += 1
        j += 1
    if j == 2:
        break
    i += 1
print(a[0] * a[1])

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
counter_a = Counter(a)
ok_list = []
for key,value in counter_a.items():
    if value >= 4:
        ok_list.append(key)
        ok_list.append(key)
    elif value >= 2:
        ok_list.append(key)
    else:
        continue
ok_list.sort(reverse=True)
if len(ok_list) >= 2:
    ans = ok_list[0] * ok_list[1]
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c = collections.OrderedDict(sorted(c.items(), key=lambda x:x[0],reverse=True))
high=0
low=0
for i,j in zip(c.keys(),c.values()):
    if(j>=4):
        if(high==0):
            high=i
        if(low==0):
            low =i
        break
    elif(j>=2):
        if(high==0):
            high=i
        else:
            low=i
            break
print(high*low)