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 collections

N = int(input())
A = list(map(int,input().split()))
cc = dict(collections.Counter(A))
ans = 0
max_1 = 0
max_2 = 0
max_3 = 0
for i in cc.items():
  if (i[0] > max_1 and i[1] >= 2):
    max_2 = max_1
    max_1 = i[0]
  elif (i[0] > max_2 and i[1] >= 2):
    max_2 = i[0]
  if (i[1] >= 4):
    max_3 = max(max_3,i[0])
print(max(max_1*max_2,max_3**2))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
Flag = False
base = 0
height = 0
ans = 0
for i in range(N - 1):
    if Flag:
        Flag = False
        continue
    if A[i] == A[i + 1] and base == 0:
        base = A[i]
        Flag = True
    elif A[i] == A[i + 1]:
        height = A[i]
        Flag = True
    area = base * height
    if area > ans:
        ans = area
print(ans)

Submission status: Accepted

Solution code:
import collections

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

d1 = []
d2 = []
for num,v in c.items():
  if v >= 2:
    d1.append(num)
  if v >= 4:
    d2.append(num)
    
d1.sort()
d2.sort()

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
l1 = []
l2 = []
for key,value in D.items():
    if value > 1:
        l1.append(key)
    if value > 3:
        l2.append(key)
if len(l1) < 2:
    print(0)
    exit()
l1.sort()
l2.sort()
if len(l2) > 0:
    print(max(l1[-1]*l1[-2],l2[-1]*l2[-1]))
else:
    print(l1[-1]*l1[-2])

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    cnt=Counter(aa)
    mx=-1
    for a,an in sorted(cnt.items(),reverse=True):
        if an>3 and mx==-1:
            print(a*a)
            break
        elif an>1:
            if mx==-1:mx=a
            else:
                print(mx*a)
                break
    else:
        print(0)



main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=1)
p=0
ans=1
c=0
for x in a:
  q=x
  if p==q:
    ans*=p
    p,q=0,0
    c+=1
    if c==2:
      print(ans)
      exit()
  else:
    p=q
print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
tmp1,tmp2=0,0
for i in range(1,len(a)):
  if a[i]==a[i-1]:
    tmp1=a[i]
    break
a=a[i+1:]
for i in range(1,len(a)):
  if a[i]==a[i-1]:
    tmp2=a[i]
    break
print(tmp1*tmp2)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
#print(A)
cnt = 0
prev = 0
candidates = []
for i in A:
    if i == prev:
        cnt += 1
        prev = i
    elif i != prev:
        prev = i
        cnt = 0
    if cnt >= 3:
        print(i**2)
        exit()
    if cnt == 1:
        candidates.append(i)
    if len(candidates) == 2:
        print(candidates[0]*candidates[1])
        exit()

print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
d = defaultdict(int)
for a in A:
  d[a] += 1
x = 1
cnt = 0
d = sorted(d.items(), key=lambda x:-x[0])
for i, j in d:
  if x == 1 and j >= 4:
    print(i**2)
    exit()
  if j >= 2:
    x *= i
    cnt += 1
    if cnt == 2:
      break
if cnt >= 1:
  print(x)
else:
  print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
condition = True
for i in range(0, n - 3) :
    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])
                break
        break
else :
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
lar=sec=i=0
while(i<n-1):
    if a[i]==a[i+1]:
        i+=1
        if a[i]>lar:
            sec=lar
            lar=a[i]
        elif a[i]>sec:
             sec=a[i]
    i+=1
print(lar*sec)

Submission status: Accepted

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

for i in range(n):
    if(vals[i] in d.keys()):
        d[vals[i]] += 1
    else:
        d[vals[i]] = 1


for i in d.keys():
    if(d[i] >= 4):
        a.append(i)
        a.append(i)
    elif(d[i] >= 2):
        a.append(i)
a.sort()

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

Submission status: Accepted

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

tmp = []
from collections import Counter
c = Counter(a)
for k in c.keys():
    if c[k] >= 2:
        tmp.append(k)
    if c[k] >= 4:
        tmp.append(k)

tmp.sort()

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

Submission status: Accepted

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

A.sort(reverse=True)
ans = 0
x = 0
y = 0
i = 0

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

    i += 1

A.sort(reverse=True)
i = 0
while i in range(len(A) - 1):
    if A[i] == A[i+1]:
        y = A[i]
        A[i] = -1
        A[i+1] = -1
        break

    i += 1

if x <= 0 or y <= 0:
    print(0)
else:
    print(x * y)

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:
n=int(input())
a=list(map(int,input().split()))
import collections as c
d=c.Counter(a)
d=list(d.items())
d=sorted(d,reverse=True)
x,y=0,0
for i in d:
    if i[1]>=4 and x==0 and y==0:
        print(i[0]**2)
        exit()
    if x==0 and i[1]>=2:
        x=i[0]
        continue
    if y==0 and i[1]>=2:
        y=i[0]
        break
print(x*y)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ans = []
flag = False
for i in range(len(a) - 1):
    if flag == 1:
        flag = -1
        continue
    if a[i] == a[i+1]:
        ans.append(a[i])
        if flag == -1:
            break
        flag = 1
if len(ans) == 2:
    print(ans[0] * ans[1])
else:
    print(0)

Submission status: Accepted

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

A.sort(reverse=True)
c1 = 0
c2 = 0
i = 1
while i < N:
    if A[i] == A[i-1]:
        if c1 == 0:
            c1 = A[i]
            i += 1
        else:
            c2 = A[i]
            break
    i += 1
    
print(c1*c2)

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort(reverse=True)
lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))

mae = 0
ato = 0
for i in lin:
    if i[1] >= 4 and mae == 0:
        mae = i[0]
        ato = i[0]
    elif i[1] >= 2 and mae == 0:
        mae = i[0]
    elif i[1] >= 2 and ato == 0:
        ato = i[0]

print(mae*ato)

Submission status: Accepted

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

for a in A:
	if a in dic:
		dic[a] += 1
	else:
		dic[a] = 1

dic_sorted = list(sorted(list(dic.items()), key=lambda x:x[0], reverse = True))
# print(dic_sorted)
res = []

for i in range(len(dic_sorted)):
	if len(res) == 2: break
	remain = dic_sorted[i][1]
	while remain >= 2:
		res.append(dic_sorted[i][0])
		remain -= 2
		if len(res) == 2: break

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))[::-1]

i=0
find=0
ans=1
while i<len(a)-1:
  if a[i]==a[i+1]:
    find+=1
    ans*=a[i]
    i+=2
    if find==2:
      print(ans)
      break
  else:
    i+=1
else:
  print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
counter=collections.Counter(a)
parts=[]
for item in counter.items():
  key=item[0]
  val=item[1]
  if val<2:
    continue
  loop=val//2
  for i in range(loop):
    parts.append(key)
    
if len(parts)<2:
  print(0)
else:
  parts=sorted(parts)
  print(parts[-1]*parts[-2])

Submission status: Accepted

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

c = col.Counter(li)
#print(list(c.items()))
c = sorted(list(c.items()),key = lambda x:-x[0])
tmp1 = 0
tmp2 = 0
for i in range(n):
  if c[i][1] >= 2:
    if tmp1 != 0:
      tmp2 = c[i][0]
      #print("i1")
      break
    elif c[i][1] < 4:
      tmp1 = c[i][0]
      #print("i2")
    else:
      tmp1 = c[i][0]
      tmp2 = c[i][0]
      #print("i3")
      break
else:
  print(0)
  exit()
print(tmp1*tmp2)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from collections import Counter
def resolve():
    int(input())
    C=Counter(map(int,input().split()))
    C=[(k,v) for k,v in C.items()]
    C.sort(reverse=1)
    ans=0
    for k,v in C:
        if(v>=4):
            ans=k*k
            break

    a=0; b=0
    for i in range(len(C)):
        k,v=C[i]
        if(v>=2):
            a=k
            C[i]=(0,0)
            break

    for i in range(len(C)):
        k,v=C[i]
        if(v>=2):
            b=k
            C[i]=(0,0)
            break

    print(max(ans,a*b))
resolve()

Submission status: Accepted

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

first = 0
second = 0

d = defaultdict(int)
for a in A:
    d[a] += 1

A = set(A)
A = list(A)
A.sort(reverse=True)

for a in A:
    if 4 <= d[a]:
        if first>0:
            second = a
            break
        first = a
        second = a
        break
    elif 2<= d[a] <4:
        if first==0:
            first = a
            continue
        if first>0:
            second = a
            break

if first*second == 0:
    print(0)
else:
    print(first*second)

Submission status: Accepted

Solution code:
import heapq
n=int(input())
a=list(map(int,input().split()))
a=[-b for b in a]
heapq.heapify(a)
x=0
y=0
c=0
cnt=0
while len(a)>0:
    d=heapq.heappop(a)
    if c!=d:
        c=d
        cnt=1
    elif c==d:
        if x==0:
            x=d
            c=0
            continue
        elif x!=0 and y==0:
            y=d
            break
print(x*y)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
b = collections.Counter(a)
c = [ 0 for _ in range(n)]
i = 0
for l, cnt in b.items():
    if 1 < cnt < 4:
        c[i] = l
        i += 1
    elif 3 < cnt:
        c[i] = l
        c[i + 1] = l
        i += 2
c.sort(reverse=True)
print(c[0] * c[1])

Submission status: Accepted

Solution code:
N = int(input())
array = list(map(int,input().split()))
array.sort(reverse=True)
array2 = []
tmp = array[0]
for i in range(1,N):
    if tmp == array[i]:
        array2.append(array[i])
    tmp = array[i]
if len(array2) >= 1 and array2.count(max(array2)) >= 4:
    print(max(array2)**2)
    exit()
array3 = list(set(array2))
array3.sort(reverse=True)
if 2 <= len(array3):
    print(array3[0]*array3[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter as C
N = int(input())
A = C([int(a) for a in input().split()])
L = []
for k in sorted(A.keys())[::-1]:
    if A[k] >= 2:
        if len(L) <= 1:
            L.append(k)
    if A[k] >= 4:
        if len(L) <= 1:
            L.append(k)

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
A = list(map(int, input().split()))
S = sorted(list(set(A)), reverse=True)
c = collections.Counter(A)

L = []
for s in S:
    if c[s] > 3:
        L.append(s)
        L.append(s)
    elif c[s] > 1:
        L.append(s)
    if len(L) > 1:
        print(L[0]*L[1])
        break
else:
    print(0)

Submission status: Accepted

Solution code:
def examC():
    N = I()
    A = LI(); A.sort(reverse = True)
    d = defaultdict(int)
    cur = []
    ans = 0
    for i in range(N):
        d[A[i]] +=1
        if d[A[i]]==2:
            cur.append(A[i])
        elif d[A[i]]==4:
            cur.append(A[i])
        if len(cur)==2:
            ans = cur[0] * cur[1]
            break
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
import collections

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

ca =collections.Counter(a)
res = []
for kca in list(ca.keys()):
    if ca[kca] >= 2:
        res.append(kca)
    if ca[kca] >= 4:
        res.append(kca)

res.sort()
if len(res)>= 2:
    print(res[-1]*res[-2])
else:
    print(0)

Submission status: Accepted

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

sameCnt = 1
valueCnt = 0
x, y = 0, 0
i = 0

while i < (num - 1):
  if sequence[i] == sequence[i+1]:
    if valueCnt == 0:
      x = sequence[i]
      valueCnt += 1
    elif valueCnt == 1:
      y = sequence[i]
      break
    i += 1
  i += 1

ans = x * y
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int,input().split()))
li.sort()
a = 0
b = 0
while len(li) >= 2:
  if li[-1] == li[-2] and a == 0:
    a = li[-1]
    del li[-1]
    del li[-1]
  elif li[-1] != li[-2]:
    del li[-1]
  elif li[-1] == li[-2] and a != 0:
    b = li[-1]
    break
print(a * b)

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort(reverse=True)
i = 0
flag = False
while i != (n-1):
    if flag is False:
        if a[i] == a[i+1]:
            first = a[i]
            i += 2
            flag = True
        else:
            i += 1
    else:
        if a[i] == a[i+1]:
            second = a[i]
            print(first*second)
            exit()

        else:
            i += 1

print(0)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
swi = 0
s = [0, 0]
i = 0
while i < len(a) - 1:
    if a[i] == a[i + 1]:
        s[swi] = a[i]
        i += 1
        swi += 1
        if swi == 2:
            break
    i += 1

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

Submission status: Accepted

Solution code:
#71c
import collections

N = int(input())
A_list = [int(e) for e in input().split()]

#4 本の異なる棒を選び，それらの棒を辺として長方形（正方形を含む）を作りたいです．
#作ることができる最大の長方形の面積を求めてください
stick_one = 0
stick_two = 0

c = collections.Counter(A_list)

for stick in sorted(c.items(), reverse=True):
    if stick[1] >= 4 and stick_one == 0:
        stick_one = stick[0]
        stick_two = stick[0]
        print(stick_one * stick_two)
        break
    elif 4 > stick[1] >= 2 and stick_one == 0:
        stick_one = stick[0]
    elif stick[1] >= 2 and stick_one != 0:
        stick_two = stick[0]
        print(stick_one * stick_two)
        break
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(aa)
mc = counter.most_common()
mc = sorted(mc,key=lambda x:x[0],reverse=True)

first = 0
second = 0
 
for i,c in mc:  
  if c>=2:
    if first == 0:  
      first=i
      if c>=4:
        second=i
        break
    else:
      second = i
      break    
  
print(first*second)

Submission status: Accepted

Solution code:
from sys import exit
from collections import Counter
N = int(input())
Alist = Counter(list(map(int, input().split())))
over_2 = []
for A in sorted(Alist.items(), reverse=True):
    if A[1] >= 4:
        if len(over_2) == 0:
            print(A[0] ** 2)
        else:
            print(A[0] * over_2[0])
        exit()
    elif A[1] >= 2:
        over_2.append(A[0])
        if len(over_2) == 2:
            print(over_2[0] * over_2[1])
            exit()
    else:
        continue
else:
    print(0)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    li = [(k, v) for k, v in c.items() if v >= 2]
    li.sort(reverse=True)
    if li and li[0][1] >= 4:
        return print(li[0][0] * li[0][0])
    elif len(li) <= 1:
        return print(0)
    else:
        return print(li[0][0] * li[1][0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    A.sort(reverse=True)
    lines = []
    prev = ''
    for ai in A:
        if ai == prev:
            lines.append(ai)
            prev = ''
        else:
            prev = ai

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

A.sort(reverse=True)
# print(A)
lines = []

cnt = 1
before = 'XXX'
for ai in A + ['YYY']:
    if ai == before:
        cnt += 1
    else:
        if cnt >= 4:
            lines.append(before)
            lines.append(before)
        elif cnt >=2:
            lines.append(before)

        if len(lines) >= 2:
            break
        
        cnt = 1
        before = ai


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

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter()

for ai in A:
    c[ai] += 1

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

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

Submission status: Accepted

Solution code:
from sys import stdin

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

l_count = {}
for l in a:
    l_count.update({l: l_count.get(l, 0) + 1})
  
long_side, short_side = 0, 0
for l, c in sorted(l_count.items(), reverse=1):
    if c != 1:
        if not long_side:
            if c >= 4:
                print(l ** 2)
                exit()
            else:
                long_side = l
        else:
            short_side = l
            break

print(long_side * short_side)

Submission status: Accepted

Solution code:
from sys import stdin

n, *a = map(int, stdin.read().split())    
a.sort(reverse=1)

l_count = {}
for l in a:
    l_count.update({l: l_count.get(l, 0) + 1})
  
long_side, short_side = 0, 0
for l, c in sorted(l_count.items(), reverse=1):
    if c != 1:
        if not long_side:
            if c >= 4:
                print(l ** 2)
                exit()
            else:
                long_side = l
        else:
            short_side = l
            break

print(long_side * short_side)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(map(int,input().split()),reverse=True)
i=1;l=0;r=0
while(i<n):
  if a[i-1]==a[i]:
    if l==0:l=a[i];i+=1
    else:r=a[i];i=n
  i+=1
print(l*r)

Submission status: Accepted

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

Submission status: Accepted

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

import collections
C=collections.Counter(A)
values,counts=zip(*C.most_common())
R=[]
for i in range(len(values)):
    R.append([values[i],counts[i]])
R.sort(reverse=True)

Long=0
Short=0

for i in range(len(values)):
    if R[i][1]>=4 and Long==Short==0:
        Long=R[i][0]
        Short=R[i][0]
        break
    elif R[i][1]>=2 and Long==0:
        Long=R[i][0]
    elif R[i][1]>=2 and Long!=0:
        Short=R[i][0]
        break

print(Long*Short)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = Counter([int(x) for x in input().split()])

tmp = 0
for x, y in sorted(list(a.items()), key=lambda x: x[0], reverse=True):
    if tmp != 0 and y >= 2:
        print(tmp * x)
        break
    if y >= 4:
        print(x**2)
        break
    if y >= 2:
        tmp = x
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    rods = string_to_int(inputs[0])
    rods_counter = collections.Counter(rods)
    available_rods = []
    four_count_rods = []
    for length, count in rods_counter.items():
        if count >= 2:
            available_rods.append(length)
        if count >= 4:
            four_count_rods.append(length)
    available_rods.sort()
    four_count_rods.sort()

    max_square = []

    if len(available_rods) < 2:
        max_square.append(0)
    else:
        max_square.append(available_rods[-1] * available_rods[-2])

    if len(four_count_rods) < 1:
        max_square.append(0)
    else:
        max_square.append(four_count_rods[-1] * four_count_rods[-1])
    return max(max_square)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
import collections

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

l4=sorted([Ai for Ai in c if c[Ai]>=4])
l2=sorted([Ai for Ai in c if c[Ai]>=2])

S=R=0

if len(l4)>=1:
    S=l4[-1]**2
if len(l2)>=2:
    R=l2[-1]*l2[-2]

print(max(S,R))

Submission status: Accepted

Solution code:
import sys
import collections

def solve(N: int, A: "List[int]"):
    counter = collections.Counter(A)
    counter = sorted(counter.items(), key=lambda x:x[0], reverse=True)

    w =0
    h =0
    for i,item in enumerate(counter):
        if item[1] >=2:
            w = item[0]
            counter[i] = (item[0],item[1]-2)
            break
    
    for i,item in enumerate(counter):
        if item[1] >=2:
            h = item[0]
            break
    
    print(w*h)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

dic = {}

memo1 = 0
memo2 = 0
for i in range(len(a)):
    if a[i] in dic.keys():
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

for i,j in dic.items():
    if j >= 2 and j<4:
        if memo1 < int(i):
            c = memo1
            memo1 = int(i)
            if memo2 < c:
                memo2 = c
        elif memo2 <= int(i):
            memo2 = int(i)
    
    elif j >= 4:
        if memo1 < int(i):
            memo1 = int(i)
        if memo2 < int(i):
            memo2 = int(i)


print(memo1*memo2)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(_) for _ in input().split()], reverse=True)

e = []
pre = 0
for i in range(N):
    if pre == A[i]:
        e.append(A[i])
        if len(e) >= 2: break
        pre = 0
    else:
        pre = A[i]
if len(e) < 2: print(0)
else: print(e[0] * e[1])

Submission status: Accepted

Solution code:
n=int(raw_input())
l=[int(i) for i in raw_input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in c: 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Submission status: Accepted

Solution code:
import collections

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

li_count=collections.Counter(li)
a=0
b=0
for k in li_count.keys():
    if li_count[k]>=4:
        if k>a:
            a=k
        if k>b:
            b=k
    elif li_count[k]>=2 and (k>a or k>b):
        if a>=b:
            b=k
        else:
            a=k
print(a*b)

Submission status: Accepted

Solution code:
def test():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    b = []
    i = 0
    while i + 1 < n:
        if a[i] == a[i+1]:
            b.append(a[i])
            i += 2
        else:
            i += 1
    print(b[-1]*b[-2] if len(b)>=2 else 0)


if __name__ == "__main__":
    test()

Submission status: Accepted

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

A.sort(reverse=True)
x,y=0,0
flag=False
for i in range(1,n):
  if flag:
    flag=False
    continue
  if A[i-1]==A[i]:
    if x==0:
      x=A[i]
      flag=True
    else:
      y=A[i]
  if x!=0 and y!=0:
    break
print(x*y)

Submission status: Accepted

Solution code:
import collections
n = int(input())
list_a = list(map(int, input().split()))
count = collections.Counter(list_a)
sort_count = sorted(count.items(), reverse=True)
rect = []
for k, v in sort_count:
  if v >= 4:
    rect.append(k)
    break
  if v >= 2:
    rect.append(k)
    if len(rect) >= 2:
      break
if len(rect) == 0:
  print(0)
elif len(rect) == 1:
  print(rect[0] ** 2)
else:
  print(rect[0] * rect[1])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
x,y,i=0,0,0
while i<n:
  if a[i-1]==a[i]:
    x,y=y,a[i]
    i+=1
  i+=1
print(x*y)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a.sort(reverse=True)
for i in range(1,n):
    if a[i]==a[i-1]:
        a[i]=0
    else:
        a[i-1]=0
a.sort()
print(a[-1]*a[-2])

Submission status: Accepted

Solution code:
from collections import Counter
n,*a=map(int,open(0).read().split())
b=[i for i in Counter(a).items() if i[1]>1]
b.sort()
c=[0]
for i in b[::-1]:
    if i[1]>=4:
        c.append(i[0]**2)
if len(b)>=2:
    c.append(b[-1][0]*b[-2][0])
print(max(c))

Submission status: Accepted

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

d = {}

for i in range(N):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1

q = []

for x in d:
    for i in range(d[x]//2):
        heapq.heappush(q,-x)

if len(q) <2:
    print(0)
else:
    h = - heapq.heappop(q)
    w = - heapq.heappop(q)
    print(h * w)

Submission status: Accepted

Solution code:
N = int(input())
Data = list(map(int,input().split()))
Dic = {}
for d in Data:
    if not d in Dic:
        Dic[d] = 1
    else:
        Dic[d] += 1

Data2 = []
for k,d in Dic.items():
    if d >= 4:
        Data2.append(k)
        Data2.append(k)
    elif d >= 2:
        Data2.append(k)

Data2.sort(reverse=True)

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

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    a=sorted(list(map(int,input().split(' '))),reverse=True)
    next=0
    long=0
    short=0
    for i in range(n-1):
        if a[i] == a[i+1]:
            long = a[i]
            next=i+2
            break
    for j in range(next,n-1):
        if a[j] == a[j+1]:
            short = a[j]
            break
    print(long*short)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
l.append(-1)
i=0
ma=0
while i<n:
    if l[i]==l[i+1] and ma==0:
        ma=l[i]
        i+=2
    elif l[i]==l[i+1] and ma!=0:
        print(ma*l[i])
        exit()
    else:
        i+=1
print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]
a+=0,0,0
l=[]
i=0
c=0
while i<=n-1:
    if a[i]==a[i+1]==a[i+2]==a[i+3] and c==0:
        print(a[i]*a[i+1])
        break
    elif a[i]==a[i+1]==a[i+2]==a[i+3] and c==1:
        l.append(a[i])
        i=n
    elif a[i]==a[i+1]==a[i+2]:
        l.append(a[i])
        i+=3
        c+=1
    elif a[i]==a[i+1]:
        l.append(a[i])
        i+=2
        c+=1
    else:
        i+=1
    if c==2:
        i=n
else:
    if len(l)<=1:
        print(0)
    else:
        l.sort()
        l=l[::-1]
        print(l[0]*l[1])

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

l = [k for k in d if d[k] >= 2]
l.sort(reverse=True)

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = sorted(map(int, input().split()))[::-1]

dict = {}
line = []
for a in A:
    if a not in dict:
        dict[a] = 1
    else:
        dict[a] += 1

    if dict[a] == 2:
        line.append(a)
    if dict[a] == 4:
        line.append(a)
    if len(line) == 2:
        print(line[0]*line[1])
        break
else:
    print(0)