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:
import sys
from collections import Counter

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    C = Counter(A)
    can = []
    seq = []
    for c in set(A):
        if C[c] >= 2:
            can.append(c)
            if C[c] >= 4:
                seq.append(c)

    if can:
        can = sorted(can)
        if seq:
            seq = sorted(seq)
            print(max(can[-1] * can[-2], seq[-1] ** 2))
        else:
            print(can[-1] * can[-2])
    else:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

tmp = a[0]
ans = []
cnt = 0
for i in range(1,len(a)):
    if tmp == a[i]:
        cnt += 1
        if cnt == 1 or cnt == 3:
            ans.append(tmp)
    else:
        tmp = a[i]
        cnt = 0


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

Submission status: Accepted

Solution code:
import collections
import sys
N=int(input())
ans=0
ANS=[]
A = list(map(int, input().split()))
new_A = sorted(A, reverse=True)
j=0
#print(new_A)
for i in range(len(A)-1):
    if new_A[j]==new_A[j+1]:
        ANS.append(new_A[j])
        #print(ANS)
        j+=1
    if len(ANS)==2:
        print(ANS[0]*ANS[1])
        sys.exit()
    j+=1
print("0")

Submission status: Accepted

Solution code:
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    rankA = list(set(A))
    rankA.sort(reverse=True)
    Acounter = collections.Counter(A)
    res = 4
    ans = []
    for a in rankA:
        count = Acounter[a]
        if count >= 2:
            ans.append(a)
            res = res - 2
            count = count - 2
            if len(ans) == 2:
                break
            if count >= 2:
                ans.append(a)
                break

    if len(ans) < 2:
        print(0)
        return

    a1 = ans.pop()
    a2 = ans.pop()
    ans = a1*a2
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N-1):
    if A[i]==A[i+1]:
        tate=A[i]
        A.remove(A[i+1])
        A.remove(A[i])
        break

for i in range(len(A)-1):
    if A[i]==A[i+1]:
        yoko=A[i]
        break

print(tate*yoko)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
import collections
import math


def r(n, a):
    a.sort(reverse=True)
    side = [0, 0]
    s = 0
    i = 0
    for i in range(s, n - 1):
        if a[i] == a[i + 1]:
            side[0] = a[i]
            break
    s = i + 2
    for i in range(s, n - 1):
    	if a[i] == a[i + 1]:
            side[1] = a[i]
            break
    return side[0] * side[1]


def main():
    input = sys.stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    print(r(n, a))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

max1 = 0
max2 = 0

for i in range(n):
    if a[i] in d:
        if d[a[i]] == 1 or d[a[i]] == 3:
            if a[i] > max2:
                if a[i] > max1:
                    max2 = max1
                    max1 = a[i]
                else:
                    max2 = a[i]
        d[a[i]] += 1
    else:
        d[a[i]] = 1

print(max1*max2)

Submission status: Accepted

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

A.sort(reverse = True)

l = []
tmp = 0
for i in range(n-1):
    if A[i] == A[i+1]:
        l.append(A[i])
        tmp = i+1
        break

for i in range(tmp+1, n-1):
    if A[i] == A[i+1]:
        l.append(A[i])
        break

print(l[0] * l[1] if len(l) == 2 else 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:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    edge = [k for k, v in cnt.items() if v >= 2]
    edge.sort(reverse=True)


    if len(edge) >= 1 and cnt[edge[0]] >= 4:
        ans = edge[0] ** 2
    elif len(edge) >= 2:
        ans = edge[0] * edge[1]
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    edge = [(k, v) for k, v in cnt.items() if v >= 2]
    edge.sort(reverse=True)

    if len(edge) >= 1 and edge[0][1] >= 4:
        ans = edge[0][0] ** 2
    elif len(edge) >= 2:
        ans = edge[0][0] * edge[1][0]
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  c = Counter(A)
  B = [k for k,v in c.items() if v>=2]
  C = [k for k,v in c.items() if v>=4]
  B.extend(C)
  B.sort(reverse=True)
  if len(B)<2:
    return 0
  ans = B[0]*B[1]
  return ans
print(solve())

Submission status: Accepted

Solution code:
from collections import Counter

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

d = Counter(a)
l = []
flag = False
for k,v in list(sorted(d.items()))[::-1]:
  if v >= 4:
    l.append(k)
    l.append(k)
  elif v >= 2:
    l.append(k)
  if len(l) >= 2:
    flag = True
    break

ans = 0
if flag:
  ans = l[0]*l[1]


print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
c = sorted(collections.Counter(a).items(),reverse = True)

num2 = []
num4 = []
ans = [0]

for k in c:
  if k[1]>=4:
    num4.append(k[0])
  if k[1]>=2:
    num2.append(k[0])

if len(num2)>=2:
  ans.append(num2[0]*num2[1])
if len(num4)>=1:
  ans.append(num4[0]**2)

print(max(ans))

Submission status: Accepted

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

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

tmp = 0
ans=[]

for k in c:
  if k[1]>=4:
    tmp = max(tmp,k[0]*k[0])
  if k[1]>=2:
    ans.append(k[0])
  else:
    continue

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = [0,0]
for i in set(A):
    if B[i] >= 4:
        C.append(i)
    if B[i] >= 2:
        C.append(i)
C.sort(reverse=True)
print(C[0]*C[1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
i = 1
j = 0
ans = 1
while i < n and j < 2:
    if a[i-1] == a[i]:
        ans *= a[i]
        j += 1
        i += 2
    else:
        i += 1
if j == 2:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter


def read():
    N = int(input().strip())
    A = map(int, input().strip().split())
    return N, A


def solve(N, A):
    C = Counter(A)
    first = 0
    second = 0
    for k in C.keys():
        if k > first and C[k] >= 2:
            first = k
    C[first] -= 2
    for k in C.keys():
        if k > second and C[k] >= 2:
            second = k
    return first * second


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import heapq
N = int(input())
A = list(map(int, input().split()))+[0]*4
A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)
a, b = -10**18, -10**18
while True:
  x = heapq.heappop(A)
  if a == x:
    break
  else:
    a = x
while True:
  x = heapq.heappop(A)
  if b == x:
    break
  else:
    b = x
print(a*b)

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
A=[int(i) for i in input().split()]
A=Counter(A)
e1=0
e2=0
for key,value in A.items():
    if value<2:
        continue
    elif value>=4:
        e1=max(e1,key)
        e2=max(e2,key)
    else:
        if key>e1:
            e2=e1
            e1=key
        else:
            e2=max(e2,key)
print(e1*e2)

Submission status: Accepted

Solution code:
from collections import Counter
input()
A = Counter(list(map(int, input().split()))+[0]*4)
A = [(a[0], a[1]) for a in A.most_common()  if a[1]>1]
A.sort(key=lambda l: -l[0])
print(A[0][0]**2 if A[0][1]>3 else A[0][0]*A[1][0])

Submission status: Accepted

Solution code:
from sys import stdin
from collections import Counter
def main():
  readline = stdin.readline
  N = int(input())
  A = list((map(int, readline().split())))
  C = Counter(A)
  A = sorted(set(A))
  flag = False
  for a in A[::-1]:
    if flag:
      if C[a] >= 2:
        print(a*b)
        break
    elif C[a] >= 4:
      print(a*a)
      break
    elif C[a] >= 2:
      b = a
      flag = True
  else:
    print(0)
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict

n, *a = map(int, open(0).read().split())
ans = [0, 0]
d = defaultdict(int)
for i in a:
    d[i] += 1
    if d[i] > 1 and i > ans[0]:
        ans = sorted(ans + [i])[-2:]
        d[i] -= 2
print(ans[0] * ans[1])

Submission status: Accepted

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

for i in range(len(a)):
  if x[1]<=a[i][0] and x[0]<=a[i][0] and a[i][1]>=4:
    x[0],x[1]=a[i][0],a[i][0]
  elif (x[1]<=a[i][0] or x[0]<=a[i][0]) and a[i][1]>=2:
    if x[0]<x[1]:
      x[0]=a[i][0]
    else:
      x[1]=a[i][0]
print(x[0]*x[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

x=sorted([i for i in A.items() if i[1]>=2])

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
V = sorted([(k, v) for k, v in C.most_common() if v >= 2])
a = 0
b = 0
for v in V[::-1]:
    if a == 0:
        if v[1] >= 4:
            a, b = v[0], v[0]
            break
        else:
            a = v[0]
    else:
        b = v[0]
        break
print(a * b)

Submission status: Accepted

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

D={}
for a in A:
    if a in D:
        D[a]+=1
    else:
        D[a]=1
        
S=[0,0]
for a in D:
    for _ in range(D[a]//2):
        S.append(a)
        
x=max(S)
del S[S.index(x)]
y=max(S)
print(x*y)

Submission status: Accepted

Solution code:
from collections import Counter

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

d = Counter(A)

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

ans = 0
tmp_2.sort()
tmp_4.sort()
if len(tmp_4):
    ans = tmp_4[-1]**2
if len(tmp_2) >= 2:
    ans = max(ans, tmp_2[-1]*tmp_2[-2])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

set_A = sorted((set(A)), reverse=True)
tmp = 0
for a in set_A:
    if A_dic[a] >= 4:
        print(max(tmp*a, a*a))
        exit()
    if A_dic[a] >= 2:
        ans = tmp * a
        if ans != 0:
            print(ans)
            exit()
        tmp = a
print(0)

Submission status: Accepted

Solution code:
from collections import Counter

def solve():
    N = int(input())
    R = map(int, input().split())
    counter = Counter(R)
    rect = []
    ret = 0
    edges = sorted(counter.items(), key=lambda x: -1*x[0])
    for a,b in edges:
        if b >= 4:
            rect.append(a)
            rect.append(a)
        elif b >= 2:
            rect.append(a)
        
        if len(rect) >= 2: 
            ret = rect[0]*rect[1]
            break
            
    print(ret)
    
solve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

a.sort()
res = []
while a and len(res) < 2:
    #print(a,res)
    if len(a) >= 2 and a[-1] == a[-2]:
        res.append(a[-1])
        a.pop()
        a.pop()
    else:
        a.pop()

#print(res)

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

Submission status: Accepted

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

kl1 = sorted([k for k, v in c if v >= 2], reverse=True)
kl2 = sorted([k for k, v in c if v >= 4], reverse=True)
if len(kl1) < 2:
  print(0 if not kl2 else kl2[0] ** 2)
else:
  print(kl1[0] * kl1[1] if not kl2 else max(kl1[0] * kl1[1], kl2[0] ** 2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    for e in a:
        d[e] += 1
    sq = []
    re = []
    for k in d:
        if d[k] > 1:
            re.append(k)
        if d[k] > 3:
            sq.append(k)
    sq.sort()
    re.sort()
    ans = 0
    if sq:
        ans = sq[-1] * sq[-1]
    if len(re) > 1:
        ans = max(ans, re[-1] * re[-2])
    print(ans)

        



t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Accepted

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

len1 = 0
len2 = 0

for k,v in hashmap.items():
    if v>=4:
        len1, len2 = max(len1,k), max(len2,k)
    elif v>=2:
        if len1<k:
            len1, len2 = k, len1
        else:
            len2 = max(len2,k)
print(len1*len2)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    As = [int(item) for item in input().split()]

    cnt = collections.Counter(As)
    cnt = sorted(cnt.items(), reverse=True)
    # print(sorted(cnt.items(), reverse=True))
    edges = []
    lim = 0
    res = 0
    if len(cnt) >=2:
        for i, v in cnt:
            if v >= 4:
                edges.append(i)
                edges.append(i)
                lim += 2
            elif v>=2:
                edges.append(i)
                lim += 1

            if lim >= 2:
                res = edges[0]*edges[1]
                break
    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

counter = Counter(A)
ans = 0
pair = []
for l, count in sorted(counter.items(), reverse=True):
    # print(l, count)
    if count < 2:
        continue
    if count >= 4 and len(pair) == 0:
        pair = [l, l]
        break
    pair.append(l)
    if len(pair) == 2:
        break
if len(pair) == 2:
    print(pair[0] * pair[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
c = sorted((e for e in c.items() if e[1] > 1), key=lambda e: -e[0])
if len(c) < 2:
  print(0)
elif c[0][1] >= 4:
  print(c[0][0] ** 2)
else:
  print(c[0][0] * c[1][0])

Submission status: Accepted

Solution code:
from collections import Counter

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

P = sorted([i for i in A.items() if i[1] >= 2])

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

Submission status: Accepted

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

A = list(map(int, input().split()))
stick = defaultdict(int)

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

stick = {key: value for key, value in stick.items() if value >= 2}


if len(stick) >= 2:
  len1 = max(stick.keys())
  if stick[len1] < 4:
    stick.pop(len1)
  len2 = max(stick.keys())
  print(len1 * len2)
else:
  print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
d = Counter(a)
lg = 0
lt = 0
for k in d.keys():
  if d[k]>=2 and k>lg:
    lg = k
d[lg] -= 2
for k in d.keys():
  if d[k]>=2 and k>lt:
    lt = k
print(lg*lt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[38]:


import collections


# In[52]:


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


# In[54]:


a_cnt = collections.Counter(A)
p = sorted([i for i in a_cnt.items() if i[1] >= 2], reverse=True)
if len(p) > 0:
    if p[0][1]>=4:
        print(p[0][0]**2)
    elif len(p) > 1:
        print(p[0][0]*p[1][0])
    else:
        print(0)
else:
    print(0)


# In[ ]:

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()

d = Counter(readInts())

d = [i for i in sorted(d.items(), reverse=True) if i[1]>=2]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()
if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = collections.Counter(list(map(int,input().split())))
p = sorted([i for i in a.items() if i[1]>=2])
if len(p)<2:
    print(0)
elif p[-1][1]>=4:
    print(p[-1][0]**2)
else:
    print(p[-1][0]*p[-2][0])

Submission status: Accepted

Solution code:
from collections import Counter

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

acnt = Counter(A)

b = []

for k, v in acnt.items():
    if v < 2:
        continue
    if v >= 4:
        b.append(k)
    b.append(k)

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

Submission status: Accepted

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

cnt=Counter(a)
edge=[0,0]

for i in cnt:
    if cnt[i]>=4:
        edge.append(i)
    if cnt[i]>=2:
        edge.append(i)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
A = map(int, input().split())
C = defaultdict(int)
for a in A:
    C[a] += 1
C = sorted(C.items(), key=lambda x: x[0], reverse=True)
rods = []
for k, v in C:
    if v >= 4:
        rods.append(k)
        rods.append(k)
        break
    if v >= 2:
        rods.append(k)
    if len(rods) == 2:
        break
if len(rods) >= 2:
    ans = rods[0]*rods[1]
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = Counter(list(map(int, input().split())))
A = sorted(A.most_common(), reverse=True)
rods = []
for a in A:
    if a[1] >= 4:
        rods.append(a[0])
        rods.append(a[0])
        break
    if a[1] >= 2:
        rods.append(a[0])
    if len(rods) == 2:
        break
if len(rods) >= 2:
    ans = rods[0]*rods[1]
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

from collections import Counter
c = Counter(As)

area = 0
for n, c in sorted(c.most_common())[::-1]:
    if c<2:
        pass
    elif c>=4:
        area = max(area*n, n**2)
        break
    else:
        if area:
            area = area*n
            break
        else:
            area = n

print(area)

Submission status: Accepted

Solution code:
from collections import Counter

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

C_al = Counter(al)

al.sort(reverse=True)

tate = 0
yoko = 0

lst = list(C_al.keys())
lst.sort(reverse=True)

for edge in lst:
    if C_al[edge] >= 2:
        if tate == 0:
            tate = edge
            if C_al[edge] >= 4 and yoko == 0:
                yoko = edge
                print(tate * yoko)
                exit()
            else:
                pass
        else:
            yoko = edge
            print(tate * yoko)
            exit()
print(tate * yoko)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    l = list(IL())
    a = Counter(l)
    f = s = 0
    l = list(set(l))
    l.sort(reverse=True)
    for rep in l:
        if 4<=a[rep]:
            f = max(f,rep)
            s = max(s,rep)
            break
        elif 2<=a[rep]:
            if f==0:
                f = rep
            else:
                s = rep
                break
    
    print(f*s)
    return

if __name__=='__main__':
    Main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
B2 = []
B4 = []
for a in C:
    if 3>=C[a]>=2:
        B2.append(a)
    elif C[a]>=4:
        B4.append(a)
B2 = sorted(B2,reverse=True)
B4 = sorted(B4,reverse=True)
cmax = 0
if len(B2)>=2:
    cmax = max(cmax,B2[0]*B2[1])
if B4:
    cmax = max(cmax,B4[0]**2)
if B2 and B4:
    cmax = max(cmax,B2[0]*B4[0])
print(cmax)

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools
 
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    box = []
    for i in c:
        if c[i] >= 2:
            for _ in range(c[i]//2):
                box.append(i)
    if len(box) < 2:
        print(0)
    else:
        box.sort(reverse=True)
        print(box[0]*box[1])
    return 0
 
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
L = []
for k, v in C.items():
  if v >= 2:
    L.append(k)
  if v >= 4:
    L.append(k)
if len(L) < 2:
  print(0)
else:
  L.sort()
  ans = L[-1] * L[-2]
  print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=sorted(lmp(),reverse=True)
a.append(0)
i=0
ans=[]
while i<n:
    if a[i]==a[i+1]:
        ans.append(a[i])
        i+=1
    i+=1
ans.append(0)
ans.append(0)
print(ans[0]*ans[1])

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    box = []
    for i in c:
        if c[i] >= 2:
            for _ in range(c[i]//2):
                box.append(i)
    if len(box) < 2:
        print(0)
    else:
        box.sort(reverse=True)
        print(box[0]*box[1])
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def INT():
    return int(input())

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

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

from collections import Counter
import sys

N = INT()
A = LI()
count_A = Counter(A)
ans = 0

if sum([c > 1 for c in count_A.values()]) <= 1:
    print(ans)
    sys.exit()
    
count_st = []

for k, v in count_A.items():
    if v == 1:
        continue
    
    count_st.append(k)
    
    if v >= 4:
        count_st.append(k)
    
count_st.sort(reverse = True)
ans = count_st[0] * count_st[1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
a = sorted(a)[::-1]
counter = Counter(a).items()
hen4 = [elem[0] for elem in counter if elem[1] >= 4]
hen2 = [elem[0] for elem in counter if elem[1] >= 2]
if len(hen4) == 0 and len(hen2) == 0:
    print(0)
    sys.exit()

if len(hen4) > 0:
    seihoukei = hen4[0] ** 2
    if len(hen2) >= 2:
        chouhoukei = hen2[0] * hen2[1]
        ans = max(seihoukei, chouhoukei)
    else:
        ans = seihoukei
    print(ans)

else:
    print(hen2[0] * hen2[1])

Submission status: Accepted

Solution code:
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST(), reverse=True)

h = 0
w = 0
reg = n-1
for i in range(n-1):
   if a[i] == a[i+1]:
        h = a[i]
        reg = i
        break
for i in range(reg+2, n-1):
   if a[i] == a[i+1]:
        w = a[i]
        break

print(h*w)

Submission status: Accepted

Solution code:
import collections
N = int(input())

a = collections.Counter(list(map(int,input().split())))
#a = sorted(a.items(), key=lambda x: -x[0],reverse=True)
#for k, v in sorted(a.items(), key=lambda x: -x[0]):pass
a = sorted(a.items(), key=lambda x:x[0],reverse=True)

#print(a)

cnt = 0
num = []
n = 0
for i,v in a:
    if 4 <= v:
        n = max(n,(i*i))
    if 2 <= v:
        num.append(i)
        cnt += 1
    if 2 == cnt:
        break
if cnt == 2:
    print(max(num[0]*num[1],n))
else:
    print(n)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc081/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))

# まずは使える辺の長さを抽出
from collections import Counter
A_cnt = Counter(A)
candi = []
for k, v in A_cnt.items():
    if v >= 4:
        candi.extend([k, k])
    if v >= 2:
        candi.append(k)
if len(candi) < 2:
    print(0)
    exit()
A_ls = sorted(candi, reverse=True)
print(A_ls[0] * A_ls[1])

Submission status: Accepted

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

c = Counter(a)
m1=0
m2=0
m3=0
for k,v in c.items():
  if v>1:
    if k>=m1:
      m2=m1
      m1=k
    elif m2<k:
      m2=k
  if v>3 and k>m3:
    m3=k
    
print(max(m1*m2,m3**2))

Submission status: Accepted

Solution code:
import collections
N =int(input())
A =list(map(int,input().split()))
col = (collections.Counter(A))
col_key = sorted(col.keys(),reverse = 1)
hen = []
counter  =0
for i in range(len(col_key)):
    if 2 <= col[col_key[i]] <4:
        hen.append(col_key[i])
        counter += 1
    elif col[col_key[i]] >= 4:
        hen.append(col_key[i])
        hen.append(col_key[i])
        counter +=2
    if counter>=2:
        break
if counter<2:
    print(0)
else:
    print(hen[0]*hen[1])

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1

    key = list(d.keys())
    key.sort(reverse=True)
    cnt = 0
    ans = 0
    tmp = 0
    flag = False
    for i in key:
        if d[i] >= 4:
            ans = i * i
            flag = True
            break
    for i in key:
        if d[i] >= 2:
            if cnt == 0:
                tmp = i
            elif cnt == 1:
                tmp *= i
                ans = max(ans, tmp)
                print(ans)
                exit()
            cnt += 1

    if not flag:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

c = Counter(a)

e = []
for k, v in c.items():
    if v > 3:
        e.append(k)
        e.append(k)
    elif v > 1:
        e.append(k)
e.sort(reverse=True)

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

Submission status: Accepted

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

c = Counter(A)
check = 0
for i in range(N):
    if (c[A[i]] > 1):
        check += 1
if (check <= 1):
    print(0)
    exit()

L = []
for i, v in c.items():
    if (v > 3):
        L.append(i)
        L.append(i)
    elif (v > 1 and v <= 3):
        L.append(i)

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