Problem:


Score : 300 points

Problem Statement

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

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

Constraints

4 \leq N \leq 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.

Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.

Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20



Sample input:
6
3 1 2 4 2 1


Sample output:
2

Submission status: Accepted

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

a.sort(reverse= True)

cnt = 0
top = []

for i in range(n-1):
    #print(i)
    if len(top) == 2:
        break    
    if a[i] == a[i+1]:
        if len(top) == 2:
            break
        if cnt%2 == 0:
            top.append(a[i])
        cnt += 1
    else:
        cnt = 0

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

print(int(top[0]*top[1]))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
t=A[0]
a,b=0,0
g=0
for i in range(1,N):
    if A[i]==t:
        a=t
        g=i
        break
    else:
        t=A[i]
t=A[g+1]
if a!=0:
    for i in range(g+2,N):
        if t==A[i]:
            b=t
            break
        else:
            t=A[i]
print(a*b)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
squ = 0
rec = []
count = 0
tmp = 0
for i in l:
  if i == tmp:
    count += 1
    if count == 2:
      rec.append(tmp)
    elif count == 4:
      squ = max([squ,tmp])
  else:
    tmp = i
    count = 1
if len(rec)<2:
  print(squ*squ)
else:
  print(max([squ*squ,rec[0]*rec[1]]))

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
squ = 0
rec = []
count = 0
tmp = 0
for i in l:
  if i == tmp:
    count += 1
  else:
    tmp = i
    count = 1
  
  if count == 2:
    rec.append(tmp)
  elif count == 4:
    squ = max([squ,tmp])

if len(rec)<2:
  print(squ*squ)
else:
  print(max([squ*squ,rec[0]*rec[1]]))

Submission status: Accepted

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

edges=[]
for k,v in c.items():
    if v>=2:
        for i in range(v//2):
            edges.append(k)
if len(edges)>=2:
    edges.sort(reverse=True)
    print(edges[0]*edges[1])
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.sort(reverse=True)
rs = []
a = -1
for i in range(N):
  A = As[i]
  if A == a:
    rs.append(A)
    a = -1
  else:
    a = A
if len(rs) < 2:
  print(0)
  exit()
r = rs[0]*rs[1]
print(r)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    d = dict()
    for a in A: d[a] = d.get(a, 0) + 1

    max_area = 0
    edges = list(d.keys())
    for a in edges:
        if d[a] > 3:
            max_area = max(max_area, a*a)
        if d[a] == 1:
            del d[a]

    edges = sorted(d.keys(), reverse = True)
    if len(edges) > 1:
        max_area = max(max_area, edges[0]*edges[1])

    return max_area



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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in map(int,input().split()):
  d[i] += 1
c = dict()
for i in d:
  if d[i] >= 2:
    c[i] = d[i]
if len(c) == 0:
  print(0)
  exit()
f = max(c)
if c[f] < 4:
  del c[f]
if len(c) == 0:
  print(0)
  exit()
s = max(c)
print(f*s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

A.sort(reverse=True)
i = 0
ret = 0
while i < N :
    if i + 3 < N and A[i] == A[i+1] == A[i+2] == A[i+3] :
        if ret == 0 :
            ret = A[i] * A[i]
        else :
            ret *= A[i]
        break
    elif i + 1 < N and A[i] == A[i+1] :
        if ret == 0 :
            ret = A[i]
            i += 1
        else :
            ret *= A[i]
            break
    
    i += 1
    
print(ret)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = Counter(map(int,input().split()))
four = []
two = []
for k,v in a.items():
  if v  >= 4 :
    four.append(k)
  if v >= 2:
    two.append(k)
f,t = 0,0
if four:
  f = max(four)**2
if len(two) > 1:
  two.sort()
  t = two.pop() * two.pop()
print(max(f,t,0))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

from collections import Counter

def main(N,A):
    a = b = 0
    count = Counter(A)
    length = sorted(set(A), reverse=True)
    for i in length:
        if(count[i]>=4 and a==b==0):
            a = b = i
            break
        elif(count[i]>=2 and a==0):
            a = i
        elif(count[i]>=2 and b==0):
            b = i
            break
    print(a*b)

if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Submission status: Accepted

Solution code:
from collections import*
n,*a=map(int,open(0).read().split())
r=[0,0];s=[0]
for k,v in Counter(a).items():
	if v>1:
		r+=[k]
	if v>3:
		s+=[k]
r.sort();s.sort()
print(max(r[-1]*r[-2],s[-1]**2))

Submission status: Accepted

Solution code:
from collections import*
n,*a=map(int,open(0).read().split())
r=[];s=[]
for k,v in Counter(a).items():
	if v>1:
		r+=[k]
	if v>3:
		s+=[k]
if len(r)<2 and len(s)<1:
	print(0)
	exit()
r+=[0,0]
s+=[0]
r.sort()
s.sort()
print(max(r[-1]*r[-2],s[-1]**2))

Submission status: Accepted

Solution code:
n = int(input())
l = map(int, input().split())
d = {}
for a in l:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

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

m.sort(reverse=True)
if len(m) == 0:
  print(0)
elif m[0][1] >= 4:
  print(m[0][0]**2)
elif len(m) >= 2:
  print(m[0][0]*m[1][0])
else:
  print(0)

Submission status: Accepted

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

for k,d in ac.items():
    if 2 <= d < 4:
        side.append(k)
    elif d >= 4:
        side.append(k)
        side.append(k)

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
count_dict = collections.Counter(A)
d = []
for k,v in count_dict.items():
	d.append([k,v])

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = sorted(collections.Counter(list(map(int, input().split()))).items(), reverse=True)
h = w = 0
for k, v in a:
    if h == 0 or w == 0:
        t = v
        while True:
            if t >= 2:
                if h == 0:
                    h = k
                    t -= 2
                elif w == 0:
                    w = k
                    t -= 2
                else:
                    break
            else:
                break
    else:
        break
print(h * w)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

A.sort(reverse=True)
lengCount = defaultdict(int)
for a in A:
    lengCount[a] += 1

lengList = [[leng, count] for leng, count in lengCount.items()]
lengList.sort(key=lambda A : A[0], reverse=True)

firstLeng = 0
for i in range(len(lengList)):
    if lengList[i][1] >= 2:
        firstLeng = lengList[i][0]
        lengList[i][1] -= 2
        break

secondLeng = 0
for i in range(len(lengList)):
    if lengList[i][1] >= 2:
        secondLeng = lengList[i][0]
        break
print(firstLeng * secondLeng)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
d = 0
ans = []
ap = 0
for i in range(n):
    if ap == a[i]:
        d += 1
        if d == 2:
            ans.append(a[i])
        elif d == 4:
            ans.append(a[i])
    else:
        d = 1
        ap = a[i]    
    if len(ans)> 1:
      break
ans.append(0)
ans.append(0)
print(ans[0]*ans[1])

Submission status: Accepted

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

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

cand = [k for k, v in d.items() if v >= 2]
cand.sort()

ans = 0
if len(cand) >= 1 and d[cand[-1]] >= 4:
    ans = cand[-1] ** 2
elif len(cand) >= 2:
    ans = cand[-1] * cand[-2]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a.reverse()
oktwo = 0
skip = 0
for i in range(1,n):
  if skip == 1:
    skip = 0
    continue
  if a[i-1] == a[i]:
    if oktwo != 0:
      print(oktwo*a[i])
      break
    else:
      oktwo = a[i]
      danger = 1
      skip = 1
else:
  print(0)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=b=c=0
for i in sorted(A)[::-1]:
    c+=1
    if a==i:break
    a=i
B=sorted(A)[:-c:]
c=0
d=len(B)
for i in B[::-1]:
    c+=1
    if b==i:break
    b=i
    if c==d:b=0
print(a*b)

Submission status: Accepted

Solution code:
from collections import Counter

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

x,y = 0,0

c = Counter(lst)

for k,v in c.items():
    if 4 <= v:
        x = max(x,k)
        y = max(y,k)

    elif 2 <= v:
        s = min(x,y)
        if k > s:
            x = max(x,y)
            y = k
print(x*y)

Submission status: Accepted

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

pre = 10**10
cnt = 0
l = [0] * 2
i = N-1
while cnt < 2 and i > 0:
    if A[i] == A[i-1]:
        l[cnt] = A[i]
        cnt += 1
        i -= 2
    else:
        i -= 1

ans = l[0] * l[1]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections


def solve(N: int, A: "List[int]"):
    c = collections.Counter(A).items()
    a = [aa[0] for aa in c if aa[1] > 1]
    a.sort()
    s = [aa[0] for aa in c if aa[1] > 3]
    s.sort()

    if len(a) > 1:
        r = a[-1] * a[-2]
    else:
        r = 0
    
    if len(s) > 0:
        ss = s[-1] ** 2
    else:
        ss = 0
    
    print(max(r, ss))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
# -*- coding: utf-8 -*-
a = int(input())
b = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for i in b:
    d[i]+=1
sorted_d = sorted(d.items(),key=lambda x:x[0],reverse=True)

rec_cnt = 0
rec_len_list = []
for k,v in sorted_d:
    if rec_cnt == 0:
        if v >= 4:
            rec_len_list = [k,k]
            rec_cnt=2
        elif v >= 2:
            rec_len_list.append(k)
            rec_cnt=1
        else:
            pass
    elif rec_cnt == 1:
        if v >= 2:
            rec_len_list.append(k)
            rec_cnt+=1
    else:
        break
if len(rec_len_list) < 2:
    print(0)
else:
    print(rec_len_list[0] * rec_len_list[1])

Submission status: Accepted

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

from collections import Counter
c = Counter(A)

A = sorted([(l,c) for l, c in c.items() if c >= 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 Counter

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

c = Counter(A).most_common()
c.sort(key=lambda x: x[0], reverse=True)

tmp = []
for i in range(len(c)):
    if c[i][1] >= 4 and len(tmp) == 0:
        print(c[i][0]**2)
        exit()
    elif c[i][1] >= 2:
        tmp.append(c[i][0])
    if len(tmp) == 2:
        print(tmp[0]*tmp[1])
        exit()
print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, A: "List[int]"):
    counter = Counter(A)
    # 作れるか
    count = 0
    cand = []
    for k in counter:
        if counter[k] >= 4:
            cand.append(k)
            cand.append(k)
        elif counter[k] >= 2:
            cand.append(k)
    if len(cand) < 2:
        print(0)
        return
    else:
        cand.sort(reverse=True)
        area = cand[0]*cand[1]
        print(area)
    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 = sorted(list(map(int, input().split())),reverse=True)
x, y = 0, 0
for i in range(N-1):
    if A[i] == A[i+1]:
        x = A[i]
        break
for j in range(i+2,N-1):
    if A[j] == A[j+1]:
        y = A[j]
        break
print(x*y)

Submission status: Accepted

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

for i in range(n-3):
  if a[i] == a[i+1]:
    for j in range(i+2, n):
      if a[j] == a[j+1]:
        print(a[i] * a[j])
        exit()

print(0)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left

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

A.sort()
B = set(A)

ans = []

for i in B:
    p = bisect_right(A, i) - bisect_left(A, i)
    if 4 > p >= 2:
        ans.append(i)
    elif p >= 4:
        ans.append(i)
        ans.append(i)
        

ans.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())
sticks = list(map(int, input().split()))
s_dict = {}
for stick in sticks:
  if stick in s_dict:
    s_dict[stick] += 1
  else:
    s_dict[stick] = 1
sorted_dict = sorted(s_dict.items(), key=lambda x:-x[0])
side1 = 0
side2 = 0
for elem in sorted_dict:
  if elem[1] >= 4:
    if side1 == 0:
      side1 = side2 = elem[0]
    else:
      side2 = elem[0]
  elif elem[1] == 2 or elem[1] == 3:
    if side1 == 0:
      side1 = elem[0]
    else:
      side2 = elem[0]
  if side1 != 0 and side2 != 0:
    print(side1*side2)
    exit()
print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    tmp = {}
    for i, val in enumerate(A):
        if val in tmp:
            tmp[val] += 1
        else:
            tmp[val] = 1
            
    ans = []
    for k, v in tmp.items():
        if v >= 4:
            ans.append(k)
            ans.append(k)
        elif v >= 2:
            ans.append(k)
            
    if len(ans) == 0:
        print(0)
        sys.exit()
    ans.sort()
    print(ans[-1] * ans[-2])
    
    
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
s=t=0
i=n-1
while i>=4 and a[i]!=a[i-1]:i-=1
if a[i]==a[i-1]:s=a[i];i-=2
while i>=2 and a[i]!=a[i-1]:i-=1
if a[i]==a[i-1]:t=a[i]
print(s*t)

Submission status: Accepted

Solution code:
import collections
import sys
def input():
    return sys.stdin.readline()[:-1]
    
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()

Submission status: Accepted

Solution code:
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()

Submission status: Accepted

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

l = {}
for i in a:
    l.setdefault(i, 0)
    l[i] += 1
l2 = [i for i in l.keys() if l[i] >= 2]
if len(l2) <= 1:
    print(0)
else:
    l2.sort()
    if l[l2[-1]] >= 4:
        print(l2[-1] ** 2)
    else:
        print(l2[-1] * l2[-2])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    from collections import Counter

    c = Counter(A)

    a = 0
    b = 0

    for k,v in sorted(c.items(), reverse=True):
        if(v >= 4):
            if(a == 0 and b == 0):
                a = k
                b = k
                break
            else:
                b = k
                break
        if(2 <= v < 4):
            if(a != 0):
                b = k
                break
            else:
                a = k

    print(a*b)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
import collections

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

B = collections.Counter(A)

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

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

Submission status: Accepted

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

A_dict = {}

for i in A:
    if i in A_dict:
        A_dict[i] += 1
    else:
        A_dict[i] = 1



A_tuple = sorted(A_dict.items(), key=lambda x: -x[0])
side = []


for i in A_tuple:
    if i[1] >= 4:
        side.append(i[0])
        side.append(i[0])
    elif i[1] >= 2:
        side.append(i[0])
    if len(side) >= 2:
        break


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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
alp = [chr(ord('a') + i) for i in range(26)]
#A
def A():
    x, a, b = LI()
    if abs(x - a) > abs(x - b):
        print("B")
    else:
        print("A")
    return

#B
def B():
    s = S()
    s = set(s)
    for i in s:
        alp.remove(i)
    if len(alp) == 0:
        print("None")
    else:
        print(alp[0])
    return

#C
def C():
    n = II()
    a = LI()
    i = 1
    a.sort(reverse=True)
    ans = []
    while i < n:
        if a[i] == a[i - 1]:
            ans.append(a[i])
            if len(ans) == 2:
                print(ans[0] * ans[1])
                return
            i += 2
        else:
            i += 1
    print(0)

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
import copy
import sys
import math

def main():
	n = int(input())
	a = list(map(int,input().split()))
	a.sort()
	tmp = listtodict(a)
	b = {}
	for k,v in tmp.items():
		b[k] = int(v/2)
	b = sorted(b.items(), key=lambda x:x[0])
	w = -1
	for i in reversed(b):
		k=i[0]
		v=i[1]
		if(v>1 and w==-1):
			print(k**2)
			sys.exit()
		elif(v>0 and w==-1):
			w = k
		elif(v>0):
			print(w*k)
			sys.exit()
	print(0)


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Accepted

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

long1=0
long2=0
A=sorted(A)
pair=1
for i in range(N-1):
    if A[i]==A[i+1] and pair==1:
        long2=long1
        long1=A[i]
        pair=0
    else:
        pair=1
if long2==0:
    ans=0
else:
    ans=long1*long2
print(ans)

Submission status: Accepted

Solution code:
import copy
import sys
import math

def main():
	n = int(input())
	a = list(map(int,input().split()))
	a.sort()
	tmp = listtodict(a)
	b = {}
	for k,v in tmp.items():
		b[k] = int(v/2)
	b = sorted(b.items(), key=lambda x:x[0])
	w = -1
	for i in reversed(b):
		k=i[0]
		v=i[1]
		if(v>1 and w==-1):
			print(k**2)
			sys.exit()
		elif(v>0 and w==-1):
			w = k
		elif(v>0):
			print(w*k)
			sys.exit()
	print(0)


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Accepted

Solution code:
import collections 
N = int(input())
A = [int(i) for i in input().split()]
A = collections.Counter(A)
A = sorted(A.items(), key=lambda x:x[0],reverse = True)
e = []

for k,v in A:
  if v >= 4:
    e.append(k)
    e.append(k)
  elif v >= 2:
    e.append(k)
  if len(e) >= 2:
    break
if len(e) < 2:
  ans = 0
else:
  ans = e[0]*e[1]
print(ans)

Submission status: Accepted

Solution code:
import collections
n=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)
mc=c.most_common()
lec=sorted([i[0] for i in mc if i[1]>=4]+[i[0] for i in mc if i[1]>=2],reverse=True)
if len(lec)<=1:print(0);exit()
else:print(lec[0]*lec[1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
flagBIG = 0
BIG = 0
SMALL = 0
i=1
while i<N:
    if A[i] == A[i-1] and flagBIG == 1:
        SMALL = A[i]
        break
    if A[i] == A[i-1] and flagBIG == 0:
        BIG = A[i]
        flagBIG = 1
        i = i+1
    i=i+1
if BIG!= 0 and SMALL!=0:
    print(BIG*SMALL)
else:
    print(0)

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
C=collections.Counter(A)
C=sorted(list(C.items()),reverse=True)
li=[]
for i,j in C:
  if j>=4:
    li.append(i)
    break
  if j>=2:
    li.append(i)
  if len(li)==2:
    break
if len(li)==0:
  print(0)
if len(li)==1:
  print(li[0]**2)
if len(li)==2:
  print(li[0]*li[1])

Submission status: Accepted

Solution code:
n=int(input())
D={}
a_list=list(map(int,input().split()))
for i in a_list:
    if not i in D:
        D[i]=1
    else:
        D[i]+=1
l1=0
l2=0
for i in D:
    if D[i]>=2:
        if D[i]<4:
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
        else:
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
print(l1*l2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC71 C

from collections import Counter

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

a = Counter(a)
a = list(a.items())

b = []

for i,j in a:
    if j >= 2:
        b.append(i)
        if j >= 4:
            b.append(i)
b.sort()
if len(b) < 2:
    print(0)
else:
    x = b[-1]
    y = b[-2]
    print(x*y)

Submission status: Accepted

Solution code:
from collections import*
n,*a=map(int,open(0).read().split())
d=defaultdict(int)
l=[]
for i in a:
    if d[i]%2:l.append(i)
    d[i]+=1
if len(l)>1:
    *_,a,b=sorted(l)
    print(a*b)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
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 = int(input())
a = sorted(list(map(int, input().split())))

hen = [0, 0]
i, j = 0, 0
while i<n:
    if a[i]==a[i-1]:
        hen[j] = a[i]
        j = (j+1)%2
        i += 1
    i += 1
print(hen[0]*hen[1])

Submission status: Accepted

Solution code:

def C():
    n = int(input())
    a = sorted(list(map(int,input().split())),reverse=True)
    i=0
    longer = 0
    shorter = 0
    while i < len(a)-1:
        if a[i] == a[i+1]:
            if longer == 0:
                longer = a[i]
                i+=1
            elif shorter == 0:
                shorter = a[i]
                i+=1
        i+=1
    print(longer*shorter)
C()

Submission status: Accepted

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

for i in range(N-1):
    if A[i] == A[i+1]:
        A[i+1] = 0
    elif A[i] != A[i+1]:
        A[i] = 0
A.sort(reverse = True)
print(A[0] * A[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

ac = list(sorted([(a, c) for a, c in Counter(A).items() if c >= 2]))
if len(ac) >= 2:
    if ac[-1][1] >= 4:
        print(ac[-1][0] ** 2)
    else:
        print(ac[-1][0] * ac[-2][0])
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
d = {}
for c in a:d[c]=d.get(c,0)+1
l = []
sq = []
for k in d.keys():
    if d[k]>=4:sq.append(k)
    if d[k]>=2:l.append(k)

area = 0
if len(sq)>=1:
    area = max(sq) * max(sq)

if len(l)>=2:
    l1 = sorted(l,reverse = True)
    area = max(area,l1[0]*l1[1])
    print(area)
else:print(0)

Submission status: Accepted

Solution code:

N = int(input())

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

dic = {}
lis = []


for i in A:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
        lis.append(i)

lis.sort()
lis.reverse()

L = 0
S = 0

for i in lis:

    if L != 0 and S != 0:
        break

    if dic[i] >= 4:

        L = max(L,i)
        S = max(S,i)

    elif dic[i] >= 2 and L == 0:

        L = i

    elif dic[i] >= 2 and S == 0:

        S = i

print (L*S)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
l=[]
ll=[]
for i in range(len(a)):
    d[a[i]]=d.get(a[i],0)+1
for i in d.keys():
    if d[i]>=2:
        l.append(i)
    if d[i]>=4:
        ll.append(i)

l.sort(reverse=True)
ll.sort(reverse=True)
if len(l)>=2 and len(ll)>=1:
    print(max(l[0]*l[1],ll[0]**2))
elif len(l)>=2:
    print(l[0]*l[1])
elif len(ll)>=1:
    print(ll[0]**2)
else:
    print(0)

Submission status: Accepted

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

dict={}

for i in range(n):
    if not a[i] in dict:
        dict[a[i]]=0
    dict[a[i]]+=1


a=sorted(dict.items(), key=lambda x:x[0])
one=0
two=0
for i in range(len(a)):
    if a[i][1]>3:
            one=a[i][0]
            two=one

    elif a[i][1]>1:
        two=one
        one=a[i][0]
    
print(one*two)