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: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
aSet = sorted(set(a), reverse=True)
recStock = 0
recSquare = 0
for i in aSet:
    test = a.count(i)
    if a.count(i) >= 4:
        rectangle = i * 2
        break
    elif a.count(i) >= 2:
        if recStock > 0:
            recSquare = i * recStock
        else:
            recStock = i
print(recSquare)

Submission status: Wrong Answer

Solution code:
from collections import Counter
input()
a = list(map(int, input().split()))
ca = Counter(a)
sca = sorted(ca.items(), key=lambda x: -x[0])
# print(sca)
a = [0]
for k, v in sca:
  if v >= 4:
    print(int(k)**2)
    exit()
  else:
    if v >= 2:
      if a[0] != 0:
        print(a[0] * int(k))
        exit()
      else:
        a[0] = int(k)
print(0)

Submission status: Wrong Answer

Solution code:
import collections

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

c = [k for k, v in collections.Counter(a).items() if v > 1]
c.sort(reverse=True)

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

Submission status: Wrong Answer

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

N = int(input())

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

l = collections.Counter(A)

l24 =list([int(l1[0]) for l1 in l.items() if l1[1]>=2])

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

Submission status: Wrong Answer

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

key = list(A.keys())
val = list(A.values())

cond = 0
for i in range(len(key)):
	if cond == 0:
		if val[-(i+1)] >= 4:
			print(key[-(i+1)] ** 2)
			sys.exit()
		elif val[-(i+1)] >= 2:
			a_1 = key[-(i+1)]
			cond += 1
			continue
	elif cond == 1:
		if val[-(i+1)] >= 2:
			print(a_1*key[-(i+1)])
			sys.exit()

print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
count = 0
s = 1

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

for b in B:
  if A.count(b) >= 2:
    s = s * b
    count += 1
  if count >= 2:
    break

if count >= 2:
  print(s)
else:
  print(0)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import Counter

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

c = Counter(A)
#print(c)

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

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

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

Submission status: Wrong Answer

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

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

    dic = {}
    for t in a:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    
    ans = []
    ok = False
    for l, count in sorted(dic.items(), reverse=True):
        if count >= 4:
            if len(ans) == 0:
                print(l*l)
                ok = True
                break
        elif count >= 2:
            if len(ans) == 1:
                print(ans[0] * l)
                ok = True
                break
            else:
                ans.append(l)

    if not ok:
        print(0)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    dic = {}
    for t in a:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    
    ans = []
    for l, count in sorted(dic.items(), reverse=True):
        if count >= 2:
            ans.append(l)
        if len(ans) >= 2:
            break
    if len(ans) >= 2:
        print(ans[0] * ans[1])
    else:
        print(0)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

li=[]
li2=[]
for i,j in dic.items():
    if j>=2:
        li.append(i)
    if j>=4:
        li2.append(i)
li.sort()
li2.sort()

if len(li)==1 and len(li2)==1:
    print(li2[0]**2)
elif len(li)>=2 and len(li2)>=1:
    print(li[-1]*max(li[-2],li2[-1]))
elif len(li)>=2 and len(li2)==0:
    print(li[-1]*li[-2])
else:
    0

Submission status: Wrong Answer

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

li=[]
for i,j in dic.items():
    if j>=2:
        li.append(i)
li.sort()

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input().strip())
A = Counter(list(map(int, input().strip().split(' '))))
tmp = 0
for k,v in sorted(A.items(), reverse=True):
  if v > 4:
    if tmp > 0:
      print(k*tmp)
      exit()
    else:
      print(k*k)
      exit()
  elif v > 2:
    if tmp > 0:
      print(k*tmp)
      exit()
    else:
      tmp = k
print(0)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = sorted(list(map(int,input().split())), reverse = True)
B = set(A)
edge = []

for b in B:
    if A.count(b) < 2:
        continue
    edge.append(b)
    if len(edge) == 2:
        print(edge[0]*edge[1])
        exit()
    if A.count(b) >= 4:
            print(b*b)
            exit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = sorted(list(map(int,input().split())), reverse = True)
A = list(filter(lambda n:A.count(n)>=2, A))
B = set(A)
edge = []

for b in B:
    edge.append(b)
    if len(edge) == 2:
        print(edge[0]*edge[1])
        exit()
    if A.count(b) >= 4:
            print(b*b)
            exit()
print(0)

Submission status: Wrong Answer

Solution code:
c={}
n=int(input())
for i in list(map(int,input().split())):
    if i in c:
        c[i]+=1
    else:
        c[i]=1
d=[i for i in c.items() if i[1]>1]
c=sorted(d)
if len(d)==0 or (len(d)==1 and c[-1][1]<4):
    print(0)
else:
    if len(d)==1 and c[-1][1]>3:
        print(c[-1][0]**2)
    else:
        print(c[-1][0]*c[-2][0])

Submission status: Wrong Answer

Solution code:
c={}
n=int(input())
for i in list(map(int,input().split())):
    if i in c:
        c[i]+=1
    else:
        c[i]=1
d=[i for i in c.items() if i[1]>1]
c=sorted(d)
if len(d)==0 or (len(d)==1 and d[-1][1]<4):
    print(0)
else:
    if len(d)==1 and d[-1][1]>3:
        print(d[-1][0]**2)
    else:
        print(d[-1][0]*d[-2][0])

Submission status: Wrong Answer

Solution code:
c={}
n=int(input())
for i in list(map(int,input().split())):
    if i in c:
        c[i]+=1
    else:
        c[i]=1
d=[i for i in c.items() if i[1]>1]
c=sorted(d)
if len(d)==0 or (len(d)==1 and d[-1][1]<4):
    print(0)
else:
    if len(d)==1 and d[-1][1]>3:
        print(d[-1][0]**2)
    else:
        print(d[-1][0]*d[-2][0])

Submission status: Wrong Answer

Solution code:
c={}
n=int(input())
for i in list(map(int,input().split())):
    if i in c:
        c[i]+=1
    else:
        c[i]=1
d=[i for i in c.items() if i[1]>1]
c=sorted(d)
if len(d)==0:
    print(0)
else:
    if len(d)==1 and d[-1][1]>3:
        print(d[-1][0]**2)
    else:
        print(d[-1][0]*d[-2][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = []
n = inp()
a = inpl()
aa = set(a)
aa = sorted(list(aa),reverse=True)
print(a,aa)
d = defaultdict(int)

for key in a:
    d[key] += 1
for i in aa:
    if d[i] >= 4:
        if ans == []:
            print(i**2)
            quit()
    if d[i] >= 2:
        ans.append(i)
        if len(ans) == 2:
            print(ans[0]*ans[1])
            quit()
print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = []
n = inp()
a = inpl()
aa = set(a)
aa = sorted(list(aa),reverse=True)
# print(a)
d = defaultdict(int)

for key in a:
    d[key] += 1
for i in aa:
    if d[i] >= 2:
        ans.append(i)
        if len(ans) == 2:
            print(ans[0]*ans[1])
            quit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split())))
s = []
for k, v in sorted(a.items(), key=lambda x: -x[0]):
    # print(k,v)
    if v >= 4:
        print(k ** 2)
        exit()
    elif v > 1:
        s.append(k)
        if len(s) > 1:
            print(s[0] * s[1])
            exit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split())))
s = []
for k, v in sorted(a.items(), key=lambda x: -x[0]):
    if v >= 4:
        print(v ** 2)
        exit()
    elif v > 1:
        s.append(k)
        if len(s) > 1:
            print(s[0] * s[1])
            exit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split())))
s = []
for k, v in sorted(a.items(), key=lambda x: -x[0]):
    if v > 1:
        s.append(k)
        if len(s) > 1:
            print(s[0] * s[1])
            exit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
a=list(map(int, input().split()))  
a = collections.Counter(a)
a=a.most_common()
b=0
c=0

for i in range(len(a)):
    if a[len(a)-i-1][1]>=4:
        if b==0:
            b=a[len(a)-i-1][0]
            print(b**2)
            exit()
            
    if a[len(a)-i-1][1]>=2:
        if b==0:
            b=a[len(a)-i-1][0]
        else:
            c=a[len(a)-i-1][0]
            print(b*c)
            exit()
        
print(0)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
a=list(map(int, input().split()))  
a = collections.Counter(a)
a=a.most_common()
b=0
c=0

for i in range(len(a)):
    if a[len(a)-i-1][1]>=2:
        if b==0:
            b=a[len(a)-i-1][0]
        else:
            c=a[len(a)-i-1][0]
            print(b*c)
            exit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
a=list(map(int, input().split()))  
a = collections.Counter(a)
a=a.most_common()
b=0
c=0
print(a)
for i in range(len(a)):
    print(a[len(a)-i-1])
    if a[len(a)-i-1][1]>=2:
        if b==0:
            b=a[len(a)-i-1][0]
        else:
            c=a[len(a)-i-1][0]
            print(b*c)
            exit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
a=list(map(int, input().split()))  
a = collections.Counter(a)
a=a.most_common()
b=0
c=0

for i in range(len(a)):
    if a[len(a)-i-1][1]>=2:
        if b==0 and c==0:
            b=a[len(a)-i-1][0]
        elif c==0:
            c=a[len(a)-i-1][0]
            print(b*c)
            exit()
print(0)

Submission status: Wrong Answer

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: Wrong Answer

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):
    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: Wrong Answer

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):
    if len(top) == 2:
        break    
    if a[i] == a[i+1]:
        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: Wrong Answer

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]
for i in range(g+1,N):
    if A[i]==t and a!=A[i]:
        b=A[i]
        break
    else:
        t=A[i]
print(a*b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
a=0
B=[]
C=[]
count=1
for i in range(len(A)):
    if A[i]==a:
        count+=1
    else:
        if count>=2:
            B.append(A[i-1])
        if count>=4:
            C.append(A[i-1])
        a=A[i]
        count=1
if count>=2:
    B.append(A[N-1])
if len(B)<2 and len(C)<1:
    print(0)
else:
    if len(B)<2:
        print(C[len(C)-1]*C[len(C)-1])
    elif len(C)<1:
        print(B[len(B) - 1] * B[len(B) - 2])
    else:
        print(max(B[len(B)-1]*B[len(B)-2],C[len(C)-1]*C[len(C)-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
elif len(two) > 1:
  two.sort()
  t = two.pop() * two.pop()
print(max(f,t,0))

Submission status: Wrong Answer

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)
if four:
  print(max(four)**2)
elif len(two) > 1:
  two.sort()
  print(two.pop() * two.pop())
else:
  print(0)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
from collections import*
n,*a=map(int,open(0).read().split())
l=[]
for k,v in Counter(a).items():
	if v-1:
		l+=[k]
l.sort()
print(0 if len(l)<2 else l[-1]*l[-2])

Submission status: Wrong Answer

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)
if len(m) < 2:
  print(0)
else:
  m.sort(reverse=True)
  print(m[0]*m[1])

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(str,input().split(' ')))
C = collections.Counter(A)
L = sorted(C.items(),key=lambda x:x[0],reverse=True)
ans = []
count = 0
for X in L:
  if count == 2:
    break
  if X[1] >= 2:
    ans.append(X)
    count += 1
if count < 2:
  print(0)
  exit()
print(int(ans[0][0]) * int(ans[1][0]))

Submission status: Wrong Answer

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 d >= 2:
        side.append(k)

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

Submission status: Wrong Answer

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 d >= 2:
        side.append(k)

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

Submission status: Wrong Answer

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

ans = 0
firstLeng = 0
for leng, count in lengCount.items():
    if count >= 2:
        firstLeng = leng
        lengCount[leng] -= 2
        break
secondLeng = 0
for leng, count in lengCount.items():
    if count >= 2:
        secondLeng = leng
        break
print(firstLeng * secondLeng)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
d = {}
for i in range(n):
    if a[i] in d.keys():
        d[a[i]] += 1
    else:
        d[a[i]] = 1

a1 = 0
a2 = 0
for k in d:
    if a1 == 0:
        if d[k] >3:
            a1 = k
            a2 = k
        elif d[k] > 1:
            a1 = k
    elif a2 == 0:
        if d[k] > 1:
            a2 = k
    if a1*a2 > 0:
        break
print(a1*a2)

Submission status: Wrong Answer

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
if len(cand) >= 2:
    ans = cand[-1] * cand[-2]

print(ans)

Submission status: Wrong Answer

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) >= 2:
    ans = cand[-1] * cand[-2]

print(ans)

Submission status: Wrong Answer

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

L = []
for a in A:
  if A.count(a) >= 2 and not a in L:
    L.append(a)
print(L)
if len(L) < 2:
  print(0)
else:
  print(sorted(L, reverse=True)[0]*sorted(L, reverse=True)[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


usable = []
c = Counter(lst)
for k,v in c.items():
    if v >= 2:
        usable.append(k)

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

Submission status: Wrong Answer

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

height = 0
width = 0

for i in range(N-1):
    if A.count(A[i]) >= 2:
        height = A[i]
        continue

for i in range(N):
    if A[i] != height:
        if A.count(A[i]) >= 2:
            width = A[i]
            break

print(height*width)

Submission status: Wrong Answer

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

height = 0
width = 0

for i in range(N-1):
    if A.count(A[i]) >= 2:
        height = A[i]
        break

for i in range(N):
    if A[i] != height:
        if A.count(A[i]) >= 2:
            width = A[i]
            break

print(height*width)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = sorted(list(map(int,input().split())))[::-1]
#print(li)
li1 = []
ans = ""
for i in range(len(li)):
    if li.count(li[i])>=2 and li[i] not in li1:
        li1.append(li[i])
        if len(li1) == 2 :
            #print(li1)
            ans = (li1[0]*li1[1])
            break
        else:
            continue

if len(li1)==0:
    print(0)
print(ans)

Submission status: Wrong Answer

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

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

has_2more_line.sort(reverse=True)
ret = 0
if len(has_2more_line) >= 2:
    ret = has_2more_line[0] * has_2more_line[1]
print(ret)

Submission status: Wrong Answer

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) >= 2:
    print(A[0][0]*A[1][0])
else:
    print(0)

Submission status: Wrong Answer

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])
if len(A) >= 2:
    print(A[0][0]*A[1][0])
else:
    print(0)

Submission status: Wrong Answer

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: Wrong Answer

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

if len(set(a)) == n:
  print(0)
  exit()

a += [0, 0, 0]

l1, l2 = 0, 0
ind = -1

for i in range(n):
  if a[i] == a[i+3] and l1 != 0:
    print(a[i]*a[i])
    exit()
  elif a[i] == a[i+1] and ind != i-1: 
    if l1 == 0:
      l1 = a[i]
      ind = i
    else:
      l2 = a[i]
      print(l1 * l2)
      exit()

print(0)

Submission status: Wrong Answer

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

l1, l2 = 0, 0
ind = -1

for i in range(n):
  if a[i] == a[i+3] and l1 != 0:
    print(a[i]*a[i])
    exit()
  elif a[i] == a[i+1] and ind != i-1: 
    if l1 == 0:
      l1 = a[i]
      ind = i
    else:
      l2 = a[i]
      print(l1 * l2)
      exit()

print(0)

Submission status: Wrong Answer

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

l1, l2 = 0, 0
ind = -1

for i in range(n):
  if a[i] == a[i+3]:
    print(a[i]*a[i])
    exit()
  elif a[i] == a[i+1] and ind != i-1: 
    if l1 == 0:
      l1 = a[i]
      ind = i
    else:
      l2 = a[i]
      print(l1 * l2)
      exit()

print(0)

Submission status: Wrong Answer

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

l1, l2 = 0, 0

for i in range(n):
  if (a[i] == a[i+1] == a[i+2] == a[i+3]) and (l1 == 0):
    print(a[i] * 2)
    exit()  
  if a[i] == a[i+1]:
    if l1 == 0:
      l1 = a[i]
      l1_i = i
    elif l2 == 0 and l1_i != i-1:
      l2 = a[i]
      print(l1 * l2) 
      exit()

print(0)

Submission status: Wrong Answer

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

print(a)

l1, l2 = 0, 0

for i in range(n):
  if (a[i] == a[i+1] == a[i+2] == a[i+3]) and (l1 == 0):
    print(a[i] * 2)
    exit()  
  if a[i] == a[i+1]:
    if l1 == 0:
      l1 = a[i]
      l1_i = i
    elif l2 == 0 and l1_i != i-1:
      l2 = a[i]
      print(l1 * l2) 
      exit()

print(0)

Submission status: Wrong Answer

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 p >= 2:
        ans.append(i)

ans.sort(reverse=True)

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

Submission status: Wrong Answer

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 p > 2:
        ans.append(i)

ans.sort(reverse=True)

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

Submission status: Wrong Answer

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

ans = []

for i in range(n-1):
  if a[i] == a[i+1]:
    ans.append(a[i])
    if len(ans) == 3:
      break

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

Submission status: Wrong Answer

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

set_a = set(a)

if n - len(set_a) < 2:
  print(0)
  exit()

ans = []

while len(ans) < 2:
  if a.count(max(set_a)) >= 2:
    ans.append(max(set_a))
    set_a.remove(max(set_a))
  else:
    set_a.remove(max(set_a))

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

Submission status: Wrong Answer

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

seta = set(a)

for i in seta.copy():
  if a.count(i) < 2:
    seta.remove(i)

ans = sorted(seta)

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

Submission status: Wrong Answer

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:
    side1 = elem[0]
    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: Wrong Answer

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:
    side1 = 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: Wrong Answer

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: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    sort_A = sorted(A, reverse=True)
    set_A = set(sort_A)

    max_num = 0

    for a in set_A:
        if sort_A.count(a) >= 2:
            if max_num == 0:
                max_num = a
                if sort_A.count(a) >= 4:
                    print(a * a)
                    exit()
            else:
                print(max_num * a)
                exit()

    print(0)

main()

Submission status: Wrong Answer

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):
            a = k
            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: Wrong Answer

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 len(p) < 2:
    print(0)
else:
    p.sort()
    print(p[-1]*p[-2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
print(ans)
if len(ans) >= 2:
    print(ans[0]*ans[1])    
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flagBIG = 0
BIG = 0
SMALL = 0
for i in range(1,N):
    if A[i] == A[i-1] and flagBIG == 1 and A[i]!= BIG:
        SMALL = A[i]
        break
    if A[i] == A[i-1] and flagBIG == 0:
        BIG = A[i]
        flagBIG = 1
if BIG!= 0 and SMALL!=0:
    print(BIG*SMALL)
else:
    print(0)

Submission status: Wrong Answer

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

countBIG = 0
countSMALL = 0
BIG = 0
SMALL = 0
for i in range(N):
    if countBIG == 1:
        if BIG == A[i]:
            countBIG =2
            continue
        else:
            countBIG == 0
    if countBIG == 0:
        BIG = A[i]
        countBIG = 1
        
    if countSMALL == 1:
        if A[i] == SMALL:
            break
        else:
            countSMALL = 0
    if countBIG == 2:
        SMALL = A[i]
        countSMALL = 1
        
if BIG!= 0 and SMALL!=0:
    print(BIG*SMALL)
else:
    print(0)