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())
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[-2]
  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: Wrong Answer

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]
  elif li[-1] != li[-2] or  a != 0 and a == li[-1]:
    del li[-1]
  elif li[-1] == li[-2] and a != 0:
    b = li[-1]
    break
print(a * b)

Submission status: Wrong Answer

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
    else:
      second = i
      break    
    
print(first*second)

Submission status: Wrong Answer

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(), key=lambda x: x[0], reverse=True):
    if A[1] >= 4:
        print(A[0] ** 2)
        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: Wrong Answer

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

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 y >= 4:
        print(x**2)
        break
    elif y >= 2:
        if tmp != 0:
            print(tmp * x)
            break
        else:
            tmp = x
else:
    print(0)

Submission status: Wrong Answer

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 y >= 4:
        print(x**2)
        break
    elif y >= 2:
        if tmp != 0:
            print(tmp * x)
            break
        else:
            tmp = x
else:
    print(tmp)

Submission status: Wrong Answer

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 = []
    for length, count in rods_counter.items():
        if count >= 2:
            available_rods.append(length)
    available_rods.sort()

    if len(available_rods) < 2:
        return 0
    return available_rods[-1] * available_rods[-2]


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


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

Submission status: Wrong Answer

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

def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    counter = collections.Counter(A)

    w =0
    h =0
    for key,value in counter.items():
        if value >=2:
            w = key
            counter[key] -= 2
            break
    
    for key,value in counter.items():
        if value >=2:
            h = key
            break
    
    print(w*h)
    return


# Generated by 1.1.6 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:
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    counter = collections.Counter(A)

    w =0
    h =0
    for key,value in counter.items():
        if value >= 4:
            print(key*key)
            sys.exit
        elif value >=2:
            w = key
            counter[key] -= 2
            break
    
    for key,value in counter.items():
        if value >=2:
            h = key
            break
    
    print(w*h)

    return


# Generated by 1.1.6 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:
N=int(input())
A=list(map(int,input().split()))

s={}
for Ai in A:
    if Ai not in s:
        s[Ai]=1
    else:
        s[Ai]+=1

a,b=0,0
for k in s:
    if s[k]>=2:
        if k>a:
            a,b=k,a
        elif k>b:
            a,b=a,k

print(a*b)

Submission status: Wrong Answer

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

s={}
for Ai in A:
    if Ai not in s:
        s[Ai]=1
    else:
        s[Ai]+=1

l=[]
for k in s:
    if s[k]>=2:
        l.append(k)
l.sort()

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

Submission status: Wrong Answer

Solution code:
def resolve():
	n=int(input())
	a=list(map(int,input().split()))
	s=set(a)
	l=[i for i in s if a.count(i)>=2]
	if len(l)<2:
		print(0)
	elif a.count(max(l))>=4:
		print(max(l)**2)
	else:
		ll=l[::-1]
		print(ll[0]*ll[1])
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	n=int(input())
	a=list(map(int,input().split()))
	s=list(set(a))[::-1]
	l=[0]*3
	k=0
	for i in s:
		if a.count(i)>=4:
			l[k],l[k+1]=i,i
			k+=2
		elif a.count(i)>=2:
			l[k]=i
			k+=1
		if k>1:
			break
	print(l[0]*l[1])
resolve()

Submission status: Wrong Answer

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]>=2 and (k>a or k>b):
        if a>=b:
            b=k
        else:
            a=k
print(a*b)

Submission status: Wrong Answer

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]>=2 and k>a and k>b:
        if a>=b:
            b=k
        else:
            a=k
print(a*b)

Submission status: Wrong Answer

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]>=2:
        if a>=b:
            b=k
        else:
            a=k
print(a*b)

Submission status: Wrong Answer

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 >= 2:
    rect.append(k)
  if len(rect) >= 2:
    break
if len(rect) >= 2:
  print(rect[0] * rect[1])
else:
  print(0)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=sorted(set(a),reverse=True)
s=[]
#print(c)
#print(a)
for i in c:
    if 3>=a.count(i)>=2:
        s.append(i)
    elif a.count(i)>=4:
        s.append(i)
        s.append(i)
    if len(s)>=2:
        break
#print(s)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=sorted(set(a),reverse=True)
s=[]
#print(c)
#print(a)
for i in c:
    if 3>=a.count(i)>=2:
        s.append(i)
    elif a.count(i)>=4:
        s.append(i)
        s.append(i)
    if len(s)>=2:
        break
#print(s)

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

Submission status: Wrong Answer

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]:
        print(a[i]*a[i+1])
        break
    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+4
else:
    if len(l)<=1:
        print(0)
    else:
        l.sort()
        l=l[::-1]
        print(l[0]*l[1])

Submission status: Wrong Answer

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]:
        print(a[i]*a[i+1])
        break
    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+4
else:
    if len(l)<=1:
        print(0)
    else:
        print(l[0]*l[1])

Submission status: Wrong Answer

Solution code:
import collections

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

# 2ペア以上ある棒のうち長い方から4本取ればよい

A_count = collections.Counter(A)
A_count = A_count.most_common()[::-1]
pairs = [A_count[idx] for idx in range(len(list(A_count))) if A_count[idx][1] >= 2]

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

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0

if len(C)==1:
    C = list(C.items())
    ans = (C[0][0])**2
    print(ans)
    exit()
else:
    # if C.most_common()[1][1]<2:
    #     print(ans)
    # else:
    C = list(C.items())
    C.sort(key=itemgetter(0,1),reverse=True)
    if C[1][1]<2:
        print(ans)
    else:
        for c in C:
            if c[1]>=4:
                first = c[0]
                second = c[0]
                break
            elif 2<=c[1]<4:
                if first == 0:
                    first = c[0]
                    continue
                else:
                    second = c[0]
                    break
        ans = first*second
        print(ans)

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0

if len(C)==1:
    C = list(C.items())
    ans = (C[0][0])**2
    print(ans)
    exit()
else:
    if C.most_common()[1][1]<2:
        print(ans)
    else:
        C = list(C.items())
        C.sort(key=itemgetter(0,1),reverse=True)
        for c in C:
            if c[1]>=4:
                first = c[0]
                second = c[0]
                break
            elif 2<=c[1]<4:
                if first == 0:
                    first = c[0]
                    continue
                else:
                    second = c[0]
                    break
        ans = first*second
        print(ans)

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0

if len(C)==1:
    C = list(C.items())
    ans = (C[0][0])**2
    print(ans)
    exit()
else:
    if C.most_common()[1][1]<2:
        print(ans)
    else:
        C = list(C.items())
        C.sort(key=itemgetter(0,1),reverse=True)
        for c in C:
            if c[1]>=4:
                first = c[0]
                second = c[0]
                break
            elif c[1]>=2:
                if first == 0:
                    first = c[0]
                    continue
                else:
                    second = c[0]
                    break
        ans = first*second
        print(ans)

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0

C = list(C.items())
C.sort(key=itemgetter(0,1),reverse=True)
for c in C:
    if c[1]>=4:
        first = c[0]
        second = c[0]
        break
    elif c[1]>=2:
        if first == 0:
            first = c[0]
            continue
        else:
            second = c[0]
            break
ans = first*second
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0

C = list(C.items())
C.sort(key=itemgetter(0,1),reverse=True)
for c in C:
    if c[1]>=4:
        first = c[0]
        second = c[0]
        break
    elif c[1]>=2:
        if first == 0:
            first = c[0]
            continue
        else:
            second = c[0]
            break
    else:
        ans = 0
        print(ans)
        exit()
ans = first*second
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0

C = list(C.items())
C.sort(key=itemgetter(0,1),reverse=True)
for c in C:
    if c[1]>=4:
        first = c[0]
        second = c[0]
        break
    elif c[1]>=2:
        if first == 0:
            first = c[0]
            continue
        else:
            second = c[0]
            break
    else:
        ans = 0
        print(ans)
        break
ans = first*second
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0
if len(C)==1:
    C = list(C.items())
    ans = (C[0][0])**2
    print(ans)
    exit()
else:
    if C.most_common()[1][1]<2:
        print(ans)
    else:
        C = list(C.items())
        C.sort(key=itemgetter(0,1),reverse=True)
        for c in C:
            if c[1]>=4:
                first = c[0]
                second = c[0]
                break
            elif c[1]>=2:
                if first == 0:
                    first = c[0]
                    continue
                else:
                    second = c[0]
                    break
        ans = first*second
        print(ans)

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0
if len(C)==1:
    C = list(C.items())
    ans = (C[0][0])**2
    print(ans)
    exit()
else:
    if C.most_common()[1][1]<2:
        print(ans)
    else:
        C = list(C.items())
        C.sort(key=itemgetter(0,1),reverse=True)
        for c in C:
            if c[1]>=2:
                if first == 0:
                    first = c[0]
                    continue
                else:
                    second = c[0]
                    break
        ans = first*second
        print(ans)

Submission status: Wrong Answer

Solution code:
# ABC071 C - Make a Rectangle
from collections import Counter
from operator import itemgetter

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

C = Counter(A)
ans = 0
first = 0
second = 0
if C.most_common()[1][1]<2:
    print(ans)
else:
    C = list(C.items())
    C.sort(key=itemgetter(0,1),reverse=True)
    for c in C:
        if c[1]>=2:
            if first == 0:
                first = c[0]
                continue
            else:
                second = c[0]
                break
    ans = first*second
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=set(a)
s=[]
#print(c)
#print(a)
for i in c:
    if a.count(i)>=2:
        s.append(i)
#print(s)
if len(s)>=2:
    print(s[-1]*s[-2])
else:
    print(0)

Submission status: Wrong Answer

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

l.sort(reverse=True)
l.append(-1)
f=1
ma1=0
for i in range(n):
    if l[i]==l[i+1]:
        f+=1
    else:
        if f>=4 and ma1==0:
            print(l[i]**2)
            exit()
        elif f>=2 and ma1!=0:
            print(l[i]*ma1)
            exit()
        elif f>=2 and ma1==0:
            ma1=l[i]
print(0)

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
if len(a) - len(aSet) >= 2:
    for i in range(len(aSet)):
        aCnt = a.count(aSet[i])
        if aCnt >= 4:
            rectangle = aSet[i] * 2
            break
        elif aCnt >= 2:
            if recStock > 0:
                recSquare = aSet[i] * recStock
            else:
                recStock = aSet[i]
print(recSquare)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd
N = int(input())
A = list(map(int, input().split()))

D = dd(int)
for a in A:
  D[a] += 1
a = 0
b = 0

for k, v in D.items():
  if v != 1:
    if k > b:
      b = k
    if b > a:
      b, a = a, b
print (a*b)

Submission status: Wrong Answer

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

b, c, d = 0, 0, 0
for i, v in a.items():
    if v >= 2:
        if b < i:
            b, c = i, b
    if v >= 4:
        d = max(d, i)
print(max(b*c, d*d))

Submission status: Wrong Answer

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

b, c = [0], [0]
for i, v in a.items():
    if v >= 2:
        b.append(i)
    if v >= 4:
        c.append(i)
if b[-1] == 0:
    print(0)
else:
    print(max(b[-1]*b[-2], max(c)**2))

Submission status: Wrong Answer

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

b, c, d = 0, 0, 0
for i, v in a.items():
    if v >= 2:
        b, c = max(b, i), b
    if v >= 4:
        d = max(d, i)
print(max(b*c, d*d))

Submission status: Wrong Answer

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

b, c = 0, 0

for i, v in a.items():
    if v >= 2:
        b, c = max(b, i), b
print(b*c)

Submission status: Wrong Answer

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

b, c = 0, 0

for i, v in a.items():
    if v >= 2:
        b, c = c, max(b, i)
print(b*c)

Submission status: Wrong Answer

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

A.sort(reverse=True)
print(A)

setbar=[]
known=set()

for a in A:
    if a in known:
        setbar.append(a)
        known.remove(a)
    else:
        known.add(a)
    if len(setbar) >= 2:
        break

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

Submission status: Wrong Answer

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

arr=[]
for k,v in A.items():
    if v>1:
        arr.append(k)

if len(arr)<=1:
    print(0)
else:
    arr_s=sorted(arr,reverse=True)
    print(arr_s[0]*arr_s[1])

Submission status: Wrong Answer

Solution code:
N=int(input())
d={}

for i in input().split():
	x=int(i)
	if x not in d:d[x]=1
	else:d[x]+=1

cnt=0
ans=1
for t in sorted(d.items(),reverse=True):
	if t[1]>=2:
		ans*=t[0]
		cnt+=1
	if cnt>=2:
		break

print(ans if cnt>=2 else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(l)
sides = [[x, y] for x, y in c.items() if y >= 2]
if sides == []:
    ans = 0
elif sides[-1][1] >= 4:
    ans = sides[-1][0]*2
else:
    ans = sides[-1][0]*sides[-2][0]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(l)
sides = [[x, y] for x, y in c.items() if y >= 2]
if sides == []:
    ans = 0
elif sides[-1][1] == 4:
    ans = sides[-1][0]*2
else:
    ans = sides[-1][0]*sides[-2][0]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a = Counter(a)
ary = [0,0]
for i in a:
    if a[i] >= 4:
        ary.append(i)
        ary.append(i)
    elif a[i] >= 2:
        ary.append(i)
print(ary.pop()*ary.pop())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
li = list(map(int, input().split()))
counter = Counter(li)
dic = {}
for key, val in counter.items():
    if val >= 2:
        dic[key] = val

if len(dic) == 0:
    print(0)
elif len(dic) == 1:
    key, val = dic.popitem()
    if val >= 4:
        print(key*key)
    if val <= 3:
        print(0)
elif len(dic) >= 2:
    sort = sorted(dic.items(), key=lambda x:x[0], reverse=True)
    v1 = sort[0][0]
    v2 = sort[1][0]
    print(v1*v2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=sorted([int(i) for i in input().split()])
cnt=Counter(a)
key=sorted(list(cnt.keys()))[::-1]
one=two=0
for i in key:
    if cnt[i]>=4:
        one=two=i
        break
    elif cnt[i]>=2:
        if one==0:
            one=i
        else:
            two=i
            break
print(one*two)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=sorted([int(i) for i in input().split()])
cnt=Counter(a)
key=sorted(list(cnt.keys()))[::-1]
one=two=0
for i in key:
    if cnt[i]>=4:
        one=two=i
    elif cnt[i]>=2:
        if one==0:
            one=i
        else:
            two=i
            break
print(one*two)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort(reverse=True)
cout = 0
for i in range(1, len(A)):
    if A[i] == A[i - 1]:
        cout = i
        break
for i in range(cout + 2, len(A)):
    if A[i] == A[i - 1]:
        print(A[cout] * A[i])
        break
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort(reverse=True)
cout = 0
for i in range(1, len(A)):
    if A[i] == A[i - 1]:
        cout = i
        break
for i in range(cout + 2, len(A)):
    if A[i] == A[i - 1]:
        print(A[cout] * A[i])
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort(reverse=True)
cout = 0
for i in range(1, len(A)):
    if A[i] == A[i - 1]:
        cout = i
        break
for i in range(cout + 1, len(A)):
    if A[i] == A[i - 1]:
        print(A[cout] * A[i])
        break

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 range(len(aSet)):
    aCnt = a.count(aSet[i])
    if aCnt >= 4:
        rectangle = aSet[i] * 2
        break
    elif aCnt >= 2:
        if recStock > 0:
            recSquare = aSet[i] * recStock
        else:
            recStock = aSet[i]
print(recSquare)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

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

from collections import Counter

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

pair = [0, 0]
c = Counter(a)
for num, cnt in c.items():
    pair.append(num * (cnt // 2))

pair.sort(reverse=True)

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

Submission status: Wrong Answer

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

from collections import Counter

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

c = Counter(a)
li = sorted(c.items(), key=lambda x: x[0], reverse=True)

cands = []
for num, cnt in li:
    if cnt >= 2:
        cands.append(num)

cands += [0, 0]
ans = cands[0] * cands[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import math
def prime_factor(n):
    factors = []
    for i in range(2,int(math.sqrt(n))+1):
        while n%i==0:
            factors.append(i)
            n = n//i
    if n!=1:
        factors.append(n)
    return factors

N = int(input())
P = [0 for i in range(N+1)]
mod = 10**9+7
for i in range(2,N+1):
    A = prime_factor(i)
    for j in A:
        P[j] += 1
ans = 1
for k in P:
    ans = ans*(k+1)%mod
print(ans)

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)
h, w = 0, 0
for k, v in sca:
  if v >= 4:
    h = max(h, k)
    w = max(w, k)
  elif v >= 2:
    if h == 0:
      h = max(h, k)
    else:
      w = max(w, k)
  if h != 0 and w != 0:
    print(h*w)
    exit()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        d[ai] += 1
    f = sorted([k for k, v in d.items() if v >= 2], reverse=True)
    print(f[0] * f[1] if len(f) >= 2 else 0)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

e=[]
a.sort()
for i in range(len(a)-1):
  if a[i] == a[i+1]:
    e.append(a[i])
    if len(e) == 2:
      break
e.sort(reverse=True)

c4 = 0
for i in e:
  if a.count(i)>=4:
    c4=i
    break

if c4 == 0 and len(e)<2:
  print(0)
elif c4 == 0 and len(e)>=2:
  print(e[0]*e[1])
elif c4 > 0 and len(e)<2:
  print(c4**2)
else:
  print(max(c4**2,e[0]*e[1]))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
import collections
def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = collections.defaultdict(int)
    for a in A:
        d[a] += 1
    for k,v in list(d.items()):
        if v < 2:
            d.pop(k)
    d = sorted(d.items(), key=lambda x: x[0], reverse=True)
    if len(d) == 1 and d[0][1] >= 4:
        print(d[0][0]**2)
    elif len(d) >= 2:
        print(d[0][0]*d[1][0])
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

dic = {}
for i in A:
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
two = []
four = []
for j, k in dic.items():
	if k>=4:
		four.append(j)
	elif k>=2:
		two.append(j)
two.sort(reverse=True)
four.sort(reverse=True)
if len(four) == 0:
	if len(two) <= 1:
		print(0)
	else:
		print(two[0]*two[1])	
else:
	if len(two) <= 1:
		print(four[0]**2)
	else:	
		print(max(two[0]*two[1], four[0]**2))

Submission status: Wrong Answer

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

e=[]
a.sort()
for i in range(len(a)-1):
  if a[i] == a[i+1]:
    e.append(a[i])
e.sort(reverse=True)

c4 = 0
for i in e:
  if a.count(i)>=4:
    c4=i
    break

if c4 == 0 and len(e)<2:
  print(0)
elif c4 == 0 and len(e)>=2:
  print(e[0]*e[1])
elif c4 > 0 and len(e)<2:
  print(c4**2)
else:
  print(max(c4**2,e[0]*e[1]))

Submission status: Wrong Answer

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


a = sorted(a, reverse=True)
count = 0
edge = []
i = 0
for i in range(n-1):
    if a[i] == a[i+1]:
        count = count + 1
        edge.append(a[i])
        i = i + 1
        if count == 2:
            break

s = edge[0]*edge[1] if count == 2 else 0
print(s)

Submission status: Wrong Answer

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






t = [x for x in set(s) if s.count(x) > 1]

t.sort(reverse=True)


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

Submission status: Wrong Answer

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

s.sort(reverse=True)




t = [x for x in set(s) if s.count(x) > 1]

t.sort(reverse=True)


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

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

c = collections.Counter(A)

C = c.most_common(2)

if C[0][1] <= 2 & C[1][1]:
    print(C[0][0] * C[1][0])
else:
    print(0)

Submission status: Wrong Answer

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

a = sorted(a, reverse=True)

count = 0
same = 1
edge = []

for i in range(1, n):
    if a[i] == a[i-1]:
        same = same + 1
        if same == 2:
            count = count + 1
            edge.append(a[i])
            if count == 2:
                break
        same = 0
    else:
        same = 1

s = edge[0]*edge[1] if count == 2 else 0
print(s)