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:
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)

a = raw_input()
a = a.split()
a = map(int,a)

a.sort()

x = 0
y = 0

for i in range(n):
    if a.count(a[-1-i]) >= 4:
        if x == 0:
            x = a[-1-i]
            y = a[-1-i]
            break
        else:
            y = a[-1-i]
            break
    elif a.count(a[-1-i]) >= 2:
        if x == 0:
            x = a[-1-i]
        elif not x == a[-1-i]:
            y = a[-1-i]
            break

ans = x*y

print ans

Submission status: Time Limit Exceeded

Solution code:
num=raw_input()
tmp=map(int, raw_input().split(" "))
arr=[]
arr_v=[]
for i in set(tmp):
    if tmp.count(i) > 1:
        arr.append(i)
    if tmp.count(i) > 3:
        arr_v.append(i)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
A = list(map(int, input().split()))
A = sorted([e for e in A if A.count(e) > 1], reverse = True)

c = None
for a in A:
    if A.count(a) >= 2:
        if c is not None:
            print(c * a)
            sys.exit()
    c = a
    A.remove(a)
    A.remove(a)
print(0)

Submission status: Time Limit Exceeded

Solution code:
#Make a Rectangle
N = int(input())
A = list(map(int, input().split()))
 
a = sorted(list(set(A)), reverse=True)
b = []
for ai in a:
    c = A.count(ai)
    for i in range(c//2):
        b.append(ai)
    if (len(b)>=4):
        break
 
if (len(b)<2):
    print(0)
else:
    print(b[0]*b[1])

Submission status: Time Limit Exceeded

Solution code:
input()
a = list(map(int,input().split()))
sa = list(set(a))
b = [ i for i in sa if a.count(i)>=2 ]
c = [ i for i in sa if a.count(i)>=4 ]
b=b+c
b.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
A = input().split()
li = []

for a in A:
    if A.count(a) > 1:
        li.append(a)
        A.remove(a)
        A.remove(a)
    else:
        A.remove(a)


if len(li) > 1:
    x = max(li)
    li.remove(x)
    y = int(max(li))
    print( int(x) * y )
else:
    print("0")

Submission status: Time Limit Exceeded

Solution code:
N=input()
A=(input()).split(' ')
NewA=[]

while len(A)!=0:
    if A.count(A[0])>1:
        NewA.append(A[0])
    d=A[0]
    while A.count(d)!=0:
        A.remove(d)

if len(NewA)<2:
    print(0)
else:
    NewA.sort()
    NewA.reverse()
    print((int)(NewA[0])*(int)(NewA[1]))

Submission status: Time Limit Exceeded

Solution code:
import sys

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

c = None

for a in A:
    if A.count(a) >= 2:
        if c is not None:
            print(c * a)
            sys.exit()
        c = a
        A.remove(a)
        A.remove(a)
print(0)

Submission status: Time Limit Exceeded

Solution code:
#Make a Rectangle
N = int(input())
A = list(map(int, input().split()))

a = sorted(list(set(A)), reverse=True)
b = []
for ai in a:
    c = A.count(ai)
    b += [ai]*(c//2)
    if (len(b)>=4):
        break
if (len(b)<2):
    print(0)
else:
    print(b[0]*b[1])

Submission status: Time Limit Exceeded

Solution code:
N = input()
A = input().split()
li = []

for a in A:
    if A.count(a) > 1:
        li.append(a)
        A.remove(a)
        A.remove(a)

li.sort()
if len(li) > 1:
    print( int(li[-1])*int(li[-2]) )
else:
    print("0")

Submission status: Time Limit Exceeded

Solution code:
# coding=utf-8
N = int(raw_input())
A = map(int, raw_input().split())

candidates = []
A.sort()
for i in xrange(1, len(A) + 1):
    if A.count(A[-i]) > 1:
        candidates.append(A[-i])
        if len(candidates) == 4:
            break
if len(candidates) < 4:
    print 0
else:
    print candidates[1] * candidates[3]

Submission status: Time Limit Exceeded

Solution code:
#Make a Rectangle
N = int(input())
A = list(map(int, input().split()))

a = sorted(list(set(A)), reverse=True)
b = []
for ai in a:
    c = A.count(ai)
    b += [ai]*(c//2)
    if (len(b)>=4):
        break
b+=[0,0]

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
A = input().split()
li = []

for a in A:
    if A.count(a) > 1:
        li.append(a)
        while a in A:
            A.remove(a)

li.sort()
if len(li) > 1:
    print( int(li[-1])*int(li[-2]) )
else:
    print("0")

Submission status: Time Limit Exceeded

Solution code:
input()
a = list(map(int,input().split()))
sa = list(set(a))
sa.sort(reverse=True)
ans = 0
count = 0

for i in sa:
    if count>=2:
        break

    if a.count(i)>=2:
        if count==0:
            ans = i
            count +=1
            if a.count(i)>3:
                if count < 2:
                    ans *= i
                    count +=1
        else:
            ans *= i
            count +=1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(input().split())
num_list = []

for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        if a[i] == a[j] and int(a[i]) not in num_list:
            num_list.append(int(a[i]))
            break

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

Submission status: Time Limit Exceeded

Solution code:
# coding=utf-8
N = int(raw_input())
A = map(int, raw_input().split())

candidates = []
for a in A:
    if A.count(a) > 1:
        candidates.append(a)
candidates.sort()
if len(candidates) < 4:
    print 0
else:
    print candidates[-1] * candidates[-4]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

to_multiply = []
while len(to_multiply) < 2 and len(arr) > 1:
    if arr[0] == arr[1]:
        to_multiply.append(arr[0])
    arr = arr[2:]
if len(to_multiply) == 2:
    print(to_multiply[0] * to_multiply[1])
else:
    print("0")

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans1=0
ans2=0
A.sort(reverse=True)
flag = False
for i in range(n-1):
  if flag == True:
    flag = False
    continue
  if i < n-1 and A[i+1] == A[i]:
    flag = True
    if A[i] >= ans1:
      ans2 = ans1
      ans1 = A[i]
    elif A[i] > ans2:
      ans2 =A[i]
print(ans1*ans2)

Submission status: Accepted

Solution code:
N = int(input())
data = list(map(int, input().split()))
data.sort()
ans = []
N -= 1
while N > 0:
    if data[N] == data[N - 1]:
        ans.append(data[N])
        N -= 1
    N -= 1
    if len(ans) >= 2:
        break

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
d = {0:4}
for a in A:
    d[a] = d.get(a, 0)+1
longest = 0
for i in d:
    if d[i]>=2:
        longest = max(longest, i)
d[longest]-=2

longest_2nd = 0
for i in d:
    if d[i]>=2:
        longest_2nd = max(longest_2nd, i)
print(longest*longest_2nd)

Submission status: Accepted

Solution code:
from collections import defaultdict
Lineger_Dict = defaultdict(int)
N = int(input())
N_List = list(map(int,input().split()))
for i in N_List:
    Lineger_Dict[i] += 1

    
Rec = sorted([k for k,v in Lineger_Dict.items() if v >= 2] + [k for k,v in Lineger_Dict.items() if v >= 4])
if len(Rec) < 2:
    print(0)
else:
    print(Rec[-1]*Rec[-2])

Submission status: Accepted

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

d={}

for n in range(N):
    if d.get(A[n])==None:
        d[A[n]]=1
    else:
        d[A[n]]+=1

d=sorted(d.items(),reverse=True)

cnt=0
ans=0
for i in range(len(d)):
    if cnt==0:
        if d[i][1]>=4:
            ans=d[i][0]**2
            break
        elif d[i][1]>=2:
            temp=d[i][0]
            cnt+=1
    else:
        if d[i][1]>=2:
            ans=temp*d[i][0]
            break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
import collections
b = collections.Counter(a).most_common()
li4 = []
li2 = []
ansli = []
for k in b:
    if k[1]>=4:
        li4 +=[k[0]]
        ansli += [k[0]**2]
    if k[1]>=2:
        li2 +=[k[0]]

if len(li2)>=2:
    li22 = sorted(li2)
    ansli += [li22[-1]*li22[-2]]
if ansli:
    print(max(ansli))
else:
    print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 23 20:22:31 2020

@author: liang
"""

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

A.sort(reverse=True)

ans = list()
i = 0
while i < N-1:
    if A[i] == A[i+1]:
       # print("A")
        ans.append(A[i])
        i += 1
    if len(ans) == 2:
        break
    i += 1

import numpy as np
#print(ans)
if len(ans) < 2:
    print(0)
else:
    print(np.prod(ans))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = []
flg = 0

A.sort(reverse=True)

for i in range(N-1):
  if A[i] == A[i+1] and flg == 0:
    ans.append(A[i])
    flg = 1
  else:
    flg = 0

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

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(int)

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

ans = []
for i in a:
  d[i] += 1
  if d[i] == 2:
    d[i] = 0
    ans.append(i)
ans.sort(reverse=True)
if len(ans) >= 2:
  print(ans[0]*ans[1])
else:
  print(0)

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

keys = sorted(list(num_map.keys()), reverse=True)

q = deque()
for i in keys:
    if num_map[i] >= 2:
        q.append([i, num_map[i]])
res = 1
counter = 0
while len(q) != 0:
    key, value = q.popleft()
    res *= key
    if value - 2 >= 2:
        q.appendleft([key, value - 2])
    counter += 1
    if counter == 2:
        print(res)
        break
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

keys = sorted(list(num_map.keys()), reverse=True)

two_over = []
counter = 0
res = 1
for i in keys:
    if num_map[i] >= 4:
        res *= i ** (2 - counter)
        counter += 2
    elif num_map[i] >= 2:
        counter += 1
        res *= i
    if counter >= 2:
        print(res)
        break
else:
    print(0)

Submission status: Accepted

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

if n == len(num)+1 or n == len(num):
    print(0)
    exit()

ans = []

for i in num:
    if num[i] >= 2:
        ans.append(i)
    if num[i] >= 4:
        ans.append(i)     
n = max(ans)
ans.pop(ans.index(max(ans)))
m = max(ans)
print(n*m)

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()

    a.sort()

    l = []
    start = a[0]
    cnt = 1
    for i in a:
        if i == start:
            cnt += 1
        else:
            start = i
            cnt = 1
        if cnt == 2:
            l.append(i)
            cnt = 0
    if cnt == 2:
        l.append(i)
    if len(l) < 2:
        print(0)
    else:
        print(l[-1]*l[-2])



if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
from collections import Counter
a = Counter(a)
lis = []
 
for i,j in a.items():
    lis += [i]*(j//2)
 
#print(lis)
 
lis.sort(reverse=True)
if len(lis) <= 1:
    ans = 0
else:
    ans = lis[0]*lis[1]
 
print(ans)

Submission status: Accepted

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

C = Counter(A)

rec = []
squ = []

for a in A:
    if 2 <= C[a]:
        rec.append(a)
    if 4 <= C[a]:
        squ.append(a)
rec = list(set(rec))
squ = list(set(squ))
# print(rec)
# print(squ)

s = 0
if len(squ) != 0:
    s = max(squ)**2

if len(rec) < 2:
    print(s)
else:
    rec.sort(reverse=True)
    print(max(s, rec[0]*rec[1]))

Submission status: Accepted

Solution code:
with open(0) as f:
    N, *A = map(int, f.read().split())

pair = []
unpair = set()
for a in A:
    if a in unpair:
        unpair.remove(a)
        pair.append(a)
    else:
        unpair.add(a)
pair.sort()
print(pair.pop()*pair.pop() if len(pair) > 1 else 0)

Submission status: Accepted

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

i=N-1
ans=1
count=0
while i>=1:
    if A[i-1]==A[i]:
        ans*=A[i]
        i-=2
        count+=1
    else:
        i-=1
    if count==2:
        print(ans)
        break
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  d[a] = d.get(a, 0) + 1
d2 = sorted(d.items(), reverse = True)
s = 0
t = 0
f = 0
for p in d2:
  if s == 0:
    if p[1] >= 4:
      print(p[0] * p[0])
      f = 1
      break
    elif p[1] >= 2:
      s = p[0]
  else:
    if p[1] >= 2:
      print(s * p[0])
      f = 1
      break
if f == 0:
  print(0)

Submission status: Accepted

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

dic = {}
for a in A:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
    
dic = sorted(dic.items(), reverse=True)

ans = 1
check = 0
bool1 = False
for (i,j) in dic:
  cnt = j // 2
  for _ in range(cnt):
    ans *= i
    check += 1
    if check == 2:
      bool1 = True
      break
  if bool1:
    break

print(ans if ans != 1 else 0)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    lst = [0, 0]

    a_lst.sort()
    a_lst.reverse()

    length = a_lst[0]
    count = 0
    for i in range(n):
        if a_lst[i] == length:
            count += 1

            if count == 2:
                lst.append(a_lst[i])
                count = 0

            if len(lst) == 4:
                break

        else:
            count = 1
            length = a_lst[i]

    area = lst[-1] * lst[-2]
    print(area)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
c=1
x=[]
for i in range(n-1):
    if a[i]!=a[i+1]:
        if c>=2:
            x.append(a[i])
        if c>=4:
            x.append(a[i])
        c=1
    else:
        c+=1
if c>=2:
    x.append(a[n-1])
if c>=4:
    x.append(a[n-1])
if len(x)<=1:
    print(0)
else:
    print(x[-1]*x[-2])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().rstrip().split(" ")))
A.sort()
lis = []

for i in range(len(A) - 1):
    if A[i] == A[i + 1]:
        lis.append(A[i])
        A[i + 1] = 0
if len(lis) < 2:
    print(0)
else:
    print(lis[-1] * lis[-2])

Submission status: Accepted

Solution code:
import heapq
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
l = []
for i in set(a):
    if c[i] >= 2:
        for j in range(c[i]//2):
            l.append(i)
if len(l) >= 2:
    print(heapq.nlargest(2, l)[0]*heapq.nlargest(2, l)[1])
else:
    print(0)

Submission status: Accepted

Solution code:
#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


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

    A.sort(reverse=True)
    l1 = l2 = 0
    for i in range(1, N):
        if l1 == 0:
            if A[i] == A[i-1]:
                l1 = A[i-1]
        else:
            if i < N-1 and A[i+1] == A[i]:
                l2 = A[i]
                break

    print(l1*l2)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=reverse)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictsort(dict,reverse=False):
    return sorted( dict.items(), reverse=reverse )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

for i in range(n):
    ddict[ a[i] ] += 1

d = mydictsort(ddict,reverse=True)
# print(d)

h = 0
w = 0
for i in range(len(ddict)):
    if d[i][1]>=4:
        if h==0:
            h = d[i][0]
            print(h*h)
            exit()
    if d[i][1]>=2:
        if h==0:
            h = d[i][0]
        elif w==0:
            w = d[i][0]

if h!=0 and w!=0:
    print(w*h)
else:
    print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-04 15:20:21 +0900
# LastModified: 2020-09-04 15:31:03 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    a_cnt = [[key, val] for key, val in Counter(a).items() if val >= 2]
    if len(a_cnt) == 0:
        print(0)
        return
    a_cnt.sort(key=lambda x: x[0], reverse=True)
    if a_cnt[0][1] >= 4:
        print(a_cnt[0][0]**2)
    elif len(a_cnt) == 1:
        print(0)
    else:
        print(a_cnt[0][0]*a_cnt[1][0])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i,j in a.items():
    lis += [i]*(j//2)

#print(lis)

lis.sort(reverse=True)
if len(lis) <= 1:
    ans = 0
else:
    ans = lis[0]*lis[1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


a.sort()

count=0


def get_num(a):
    count=1
    taishou = a.pop()
    while a!=[]:
        second=a.pop()
        if taishou==second:
            count+=1
        else:
            a.append(second)
            break
    if count==1:
        return taishou,0
    elif count==2 or count==3:
        return taishou,1
    else:
        return taishou,2

one=0
two=0


while a!=[] and (one==0 or two==0):
    hen,length=get_num(a)
    if length==1:
        if one==0:
            one=hen
        else:
            two=hen
    elif length==2:
        if one==0:
            one=hen
            two=hen
        else:
            two=hen

print(one*two)

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort(reverse=True)
    line = -1
    lines = []
    for an in a:
        if line == an:
            lines.append(an)
            if len(lines) == 2:
                break
            line = -1
        else:
            line = an
    print(lines[0] * lines[1] if len(lines) == 2 else 0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

dic = Counter(a)

l = []
for i, j in dic.items():
    if j >= 4:
        l.append(i)
        l.append(i)
    elif j >= 2:
        l.append(i)

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
lsline = []
for i in counterA.keys():
    if counterA[i] >= 2:
        lsline.append(i)
lsline.sort(reverse=True)
if bool(lsline):
    if counterA[lsline[0]] >= 4:
        ans = lsline[0]*lsline[0]
    elif len(lsline) < 2:
        ans = 0
    else:
        ans = lsline[0]*lsline[1]
else:
    ans = 0
print(ans)

Submission status: Accepted

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

for i in range(n):
  dic[a[i]] += 1
ans = 0
ls = list(dic.keys())
ls.sort()
ans_ls = []

for i in range(len(ls)-1,-1,-1):
  if dic[ls[i]] >= 2:
    ans_ls.append(ls[i])
  if dic[ls[i]] >= 4:
    ans_ls.append(ls[i])
if len(ans_ls) < 2:
  print(0)
else:
  print(ans_ls[0] * ans_ls[1])

Submission status: Accepted

Solution code:
from collections import Counter

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

A_ = sorted([[k, v] for k, v in cnt_A.items() if v >= 2], reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

def main():
    N = input()
    A = map(int, input().split())
    c = collections.Counter(A)
    edge1 = None
    for edge, freq in sorted(c.items(), key=lambda x: -x[0]):
        if edge1 is None and freq >= 4:
            print(edge ** 2)
            exit()
        elif edge1 is None and freq >= 2:
            edge1 = edge
        elif edge1 is not None and freq >= 2:
            print(edge1 * edge)
            exit()
    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

pair = []
unpair = set()
for a in A:
    if a in unpair:
        pair.append(a)
        unpair.remove(a)
    else:
        unpair.add(a)

pair.sort()
pair.reverse()
if len(pair) <= 1:
    ans = 0
else:
    ans = pair[0] * pair[1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
counter = dict(Counter(A))
four = []
tow = []
for key in counter.keys():
    if counter[key] >= 4:
        four.append(key)
        tow.append(key)
    elif counter[key]>=2:
        tow.append(key)

if len(four) == 0 and len(tow) <= 1:
    print(0)
else:
    ans = 0
    four.sort(reverse=True)
    tow.sort(reverse=True)
    if len(four) >= 1:
        ans = max(ans, four[0]**2)
    if len(tow) >= 2:
        ans = max(ans, tow[1] * tow[0])
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def solve():
    c = Counter(arr)
    four_edges = [k for k, v in c.items() if v >= 4]
    two_edges = [k for k, v in c.items() if 1 < v < 4]
    four_edges.append(0)
    two_edges.append(0)
    four_edges.sort(reverse=True)
    two_edges.sort(reverse=True)

    area_f = four_edges[0] * four_edges[0]
    if len(two_edges) >= 2:
        area_t = two_edges[0] * two_edges[1]
    else:
        area_t = 0
    area_t_t = two_edges[0] * four_edges[0]
    max_area = max(area_f, max(area_t, area_t_t))
    return max_area


N = int(input())
arr = list(map(int, input().split()))
res = solve()
print(res)

Submission status: Accepted

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

d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d = sorted(d.items(), key=lambda x:x[0], reverse=True)

m = len(d)
ans = 0
flg = True
for i in range(m):
    k, v = d[i][0], d[i][1]
    if ans == 0:
        if v >= 4:
            ans = k**2
            flg = True
            break
        elif v >= 2:
            ans = k
    elif v >= 2:
        ans *= k
        flg = True
        break
print(ans) if flg else print(0)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
C=Counter(A)
L=[]
R=[]
for i in C:
  l=C.get(i)
  if l>=2:
    L.append(i)
    if l>=4:
      R.append(i)
L.sort()
R.sort()

ans=0

if len(L)>=2:
  ans=max(L[-1]*L[-2], ans)
if len(R)>=1:
  ans=max(R[-1]**2, ans)
print(ans)

Submission status: Accepted

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

count = {}
rect = {}
for i in range(N):
    if A[i] in rect:
        rect[A[i]] += 1
    elif A[i] in count:
        rect[A[i]] = 2
    else:
        count[A[i]] = 1

if len(rect) < 1:
    ans = 0
else:
    x = max(rect)
    if rect[x] >= 4:
        ans = x * x 
    else:
        del rect[x]
        if len(rect) < 1:
            ans = 0
        else:
            y = max(rect)
            ans = x * y
print(ans)

Submission status: Accepted

Solution code:
input();a=list(map(int,input().split()));d={}
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
d={i:j for i,j in d.items() if j>1}
if len(d)<2:
  print(0)
else:
  d=sorted(d.items(),key=lambda x:(-x[0],-x[1]))
  print(d[0][0]*d[1][0] if d[0][1]<4 else d[0][0]*d[0][0])

Submission status: Accepted

Solution code:
from collections import Counter
 
input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from heapq import heapify,heappush,heappop#最小（最大）の値をlogNで取り出せる。（値の追加もlogN）
a = []
heapify(a)

dic = {}

N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    if not(A[i] in dic):
        dic[A[i]]=1
    elif dic[A[i]]==1:
        dic[A[i]]=0
        heappush(a,-A[i])
    elif dic[A[i]]==0:
        dic[A[i]]=1

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

w = heappop(a)
h = heappop(a)

print(w*h)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import math
def main():
    n = int(input())
    A=[int(i) for i in input().split()]
    dd = defaultdict(int)
    for i in A:
        dd[i]+=1
    lis = []
    for v in dd.keys():
        if(dd[v]>=4):
            lis.append(v)
            lis.append(v)
        elif(dd[v]>=2):
            lis.append(v)

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



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ca = Counter(A)
ca = sorted(ca.items(), key=lambda x:-x[0])
cnt = 0
m = []
for k, v in ca:
  if 3 >= v >= 2:
    cnt += 1
    m += [k]
  elif v >= 4:
    cnt += 2
    m += [k, k]
  if cnt >= 2:
    break

if len(m) <= 1:
  print(0)
  exit()
print(m[0]*m[1])

Submission status: Accepted

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if len(R)==0:
  print(0)
  exit()
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])