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:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if len(ans_lis) == 1 and ans_lis[0][1] < 4:
    print(0)
    sys.exit()
elif len(ans_lis) == 1 and ans_lis[0][1] >= 4:
    print(ans_lis[0][0] ** 2)
elif len(ans_lis) >= 2:
    area_1 = ans_lis[0][0] * ans_lis[1][0]
    area_2 = 0
    if ans_lis[0][1] >= 4:
        area_2 = ans_lis[0][0] ** 2
    print(max(area_1, area_2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if len(ans_lis) == 1 and ans_lis[0][0] >= 4:
    print(ans_lis[0][0] ** 2)
    sys.exit()

if len(ans_lis) < 2:
    print(0)
    sys.exit()

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

if len(key_val_lis) < 2:
    print(0)
    sys.exit()

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])
print(ans_lis[0][0] * ans_lis[1][0])
"""
counter = list(sorted(Counter(A).items(), key=lambda x: (-x[1], -x[0])))
print(*counter)

if counter[0][1] >= 2:
    width = counter[0][0]
else:
    print(0)
    sys.exit()
if counter[1][1] >= 2:
    height = counter[1][0]
else:
    print(0)
    sys.exit()
print(height * width)
"""

Submission status: Wrong Answer

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

A_dic = dict()
for i in range(N):
    if A[i] in A_dic:
        A_dic[A[i]] += 1
    else:
        A_dic[A[i]] = 1
        
max_key = 0
sub_max_key = 0
for k, v in A_dic.items():
    if v <= 1:
        pass
    else:
        if k > max_key:
            sub_max_key = max_key
            max_key = k
        elif k > sub_max_key:
            sub_max_key = k
            
print(max_key * sub_max_key)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
s = sorted(Counter(a).items(), reverse= True)


temp4 = set([0])
temp2 = set([0])
for k, v in s:
	if v >= 4:
		temp4.add(k)
	elif v >= 2:
		temp2.add(k)


area4 = pow(max(temp4), 2)
area2 = 0
if len(temp2) >= 2:
	temp2 = sorted(temp2)
	area2 = temp2[-1] * temp2[-2]
print(max(area4, area2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = set()
t = set()

for a in A:
	if a in s:
		t.add(a)
	else:
		s.add(a)

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

Submission status: Wrong Answer

Solution code:
import collections
dd = collections.defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
candidate = []
for i in range(n):
    dd[str(a[i])] += 1
for k in dd.keys():
    if dd[k] >= 2:
        candidate.append(int(k))
candidate.sort(reverse=True)
if len(candidate) < 2:
    print(0)
else:
    print(candidate[0] * candidate[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
l = [int(i) for i in input().split()]
c = sorted(Counter(l).most_common(),key = lambda x : -x[0])

edge = []
for i in c:
    if i[1] == 4:
        edge.append(i[0])
        break
    elif i[1] >= 2:
        edge.append(i[0])
        if len(edge) == 2:
            break
    else:
        pass
    
print(edge[0]**2 if len(edge) == 1 else edge[0]*edge[1] if edge else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=list(Counter(a).items())
c.sort(reverse=True)
ans=0
for a,b in c:
    if(b>=4):
        print(a*a)
        exit()
    elif(b>=2):
        if(ans!=0):
            print(ans*a)
            exit()
        else:
            ans=a
print(0)

Submission status: Wrong Answer

Solution code:
import collections

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

over_two = collections.Counter(A)
Over = []

for key, val in over_two.items():
    if val <= 1:
        pass
    else:
        Over.append(key)

if len(Over) <= 1:
    ans = 0
else:
    Over = sorted(Over, reverse=True)
    ans = Over[0] * Over[1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
a=[int(i) for i in input().split()]
first_count=set()
second_count=set()
for i in a:
    if(i in first_count):
        if(i not in second_count):
            second_count.add(i)
    else:
        first_count.add(i)
if(len(second_count)<2):
    print(0)
    exit()        
max1=max(second_count)
second_count.remove(max1)
max2=max(second_count)
print(max1*max2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=list(Counter(a).items())
c.sort(reverse=True)
hen=0
ans=[0]
for a,b in c:
  if b>=4:
    ans.append(a**2)
  elif b>=2:
    if hen==0:
      hen=a
    else:
      ans.append(hen*a)
      break
  else:
    continue
print(max(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=list(Counter(a).items())
c.sort(reverse=True)
hen=0
for a,b in c:
  if b>=4:
    print(a**2)
    break
  elif b>=2:
    if hen==0:
      hen=a
    else:
      print(hen*a)
      break
  else:
    continue
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from operator import itemgetter
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

C = Counter(A).most_common()
C = sorted(C, key=itemgetter(0), reverse=True)

x, y = 0, 0
for c in C:
	if c[1] >= 4:
		x, y = c[0], c[0]
	elif c[1] >= 2:
		if x != 0: y = c[0]
		else: x = c[0]
	if x!=0 and y!=0: break

#print(x, y)
print(x*y)

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v >= 4:
        if w == 0:
            w = h = k
        else:
            h = k
            break
    elif v >= 2:
        if w == 0:
            w = k
        elif h == 0:
            h = k
            break
print(w*h)

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v >= 4:
        if w == 0:
            w = h = k
        else:
            h = k
            break
    if v >= 2:
        if w == 0:
            w = k
        elif h == 0:
            h = k
            break
print(w*h)

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(A)
w = 0
h = 0
print(sorted(c.items(), key=lambda x: -x[0]))
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v >= 4:
        if w == 0:
            w = h = k
        else:
            h = k
            break
    if v >= 2:
        if w == 0:
            w = k
        elif h == 0:
            h = k
            break
print(w*h)

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v >= 2:
        if w == 0:
            w = k
        elif h == 0:
            h = k
            break
print(w*h)

Submission status: Wrong Answer

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

from collections import defaultdict
dic = defaultdict(int)

for a in al:
    dic[a] += 1


a = [k for k, v in dic.items() if v >= 2]

a = sorted(a)

if len(a) < 2:
    print(0)
    import sys
    sys.exit()
print(a[-1] * a[-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))[::-1]
    D = Counter(A)

    B = []
    for a, b in D.items():
        if b >= 4:
            B.append(a)
            B.append(a)
        elif b >= 2:
            B.append(a)

    B.append(0)
    B.append(0)

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


main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

tmp = []
for elt, cnt in A.most_common()[::-1]:
    if 1 >= cnt:
        continue
    if cnt >= 4:
        tmp.append(elt)
        tmp.append(elt)
        break
    if cnt >= 2:
        tmp.append(elt)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

tmp = []
for elt, cnt in A.most_common()[::-1]:
    if cnt >= 4 and len(tmp) == 0:
        tmp.append(elt)
        tmp.append(elt)
        break
    if cnt >= 2:
        tmp.append(elt)
    if len(tmp) >= 2:
        break

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = [elt for elt, cnt in Counter(list(map(int, input().split()))).most_common() if cnt >= 2]

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = [e for e, c in Counter(list(map(int, input().split()))).most_common() if c >= 2]

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

Submission status: Wrong Answer

Solution code:
import collections

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

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

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

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = list(map(int,input().split()))
c = dict(collections.Counter(a))
d = []
for num,v in c.items():
  if v>=2:
    d.append(num)

d.sort()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

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



main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

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



main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
a=0
li=[]
temp=l[0]
c=1
for i in range(n):
    if(l.count(l[i])%2==0):
        li.append(l[i])
    else:
        if(l[i]!=temp):
            c=0
        if(c!=0):
            li.append(l[i])
        c=1
        temp=l[i]

li.sort(reverse=True)
if(len(li)>=4):
    a=li[0]*li[2]
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
l = []
for i in range(n-1):
    if a[i] == a[i+1] and a[i] not in l:
        l.append(a[i])
        
print(l[0]*l[1] if l else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
from collections import Counter
c = Counter(a)
#print(c.most_common())
if c.most_common()[0][1] >= 4:
    print((c.most_common()[0][1])**2)
elif c.most_common()[0][1] == 1:
    print(0)
elif c.most_common()[1][1] >= 2:
    print(c.most_common()[0][1]*c.most_common()[1][1])
else:print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
from collections import Counter
c = Counter(a)
#print(c.most_common())
if c.most_common()[0][1] >= 4:
    print((c.most_common()[1][1])**2)
elif c.most_common()[0][1] == 1:
    print(0)
elif c.most_common()[1][1] >= 2:
    print(c.most_common()[0][1]*c.most_common()[1][1])
else:print(0)

Submission status: Wrong Answer

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

rec_hen = 0
a_set = sorted(set(a), reverse=True)
for ai in a_set:
  ac = a.count(ai)
  if ac >= 4:
    print(ai * ai)
    exit(0)
  if ac >= 2:
    if rec_hen != 0:
      print(rec_hen * ai)
      exit(0)
    rec_hen = ai

print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[int(i) for i in input().split()]
l=[]
for i in li:
  if li.count(i)%2==0:
    l.append(i)
l.sort()
if len(l)>=4:
  print(l[-1]*l[-3])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[int(i) for i in input().split()]
l=[]
for i in li:
  if li.count(i)==2:
    l.append(i)
l.sort()
if len(l)>=4:
  print(l[-1]*l[-3])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[int(i) for i in input().split()]
l=[]
for i in li:
  if li.count(i)==2:
    l.append(i)
l.sort()
if len(l)>=4:
  print(l[0]*l[2])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[int(i) for i in input().split()]
l=[]
for i in li:
  if li.count(i)==2:
    l.append(i)
l.sort()
print(l)
if len(l)>=4:
  print(l[0]*l[2])
else:
  print(0)

Submission status: Wrong Answer

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


def c(lst, x):
    return lst.count(x)


l1 = []
l2 = []
for i in range(N):
    if(int(A[i]) not in l1):
        l1.append(int(A[i]))
        count = c(A, A[i])
        if(count % 2 == 0):
            ct=int(count/2)
            for j in range(ct):
                l2.append(int(A[i]))
if(not l2):
    l2.append(0)
    l2.append(0)
l = max(l2)
b = sorted(l2)[-2]
print(l*b)

Submission status: Wrong Answer

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


def c(lst, x):
    return lst.count(x)


l1 = []
l2 = []
for i in range(N):
    if(int(A[i]) not in l1):
        l1.append(int(A[i]))
        count = c(A, A[i])
        if(count >= 2):
            l2.append(int(A[i]))
if(not l2):
    l2.append(0)
    l2.append(0)
l = max(l2)
b = sorted(l2)[-2]
print(l*b)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
s=list(set(l))
c = dict(Counter(l))
a=0
l=0
b=0
s.sort()
s.reverse()
for i in s:
    if c[i] >= 4 and i>a:
        a=i
    elif c[i] >= 2 and i>l:
        l=i
    elif c[i] >= 2 and i>b and l!=b:
        b=i
print(max(l*b,a*a))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
s=list(set(l))
c = dict(Counter(l))
a=0
l=0
b=0
s.sort()
s.reverse()
for i in s:
    if c[i] >= 4 and i>a:
        a=i
    elif c[i] >= 2 and i>l:
        l=i
    elif c[i] >= 2 and i>b:
        b=i
print(max(l*b,a*a))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
s=list(set(l))
c = dict(Counter(l))
a=0
l=0
b=0
s.reverse()
for i in s:
    if c[i] >= 4 and i>a:
        a=i
    elif c[i] >= 2 and i>l:
        l=i
    elif c[i] >= 2 and i>b:
        b=i
print(max(l*b,a*a))

Submission status: Wrong Answer

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

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

print(d)

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

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

Submission status: Wrong Answer

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

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

print(d)

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
s=list(set(l))
c = dict(Counter(l))
a=0
l=0
b=0
s.reverse()
for i in s:
    if c[i] >= 4 and a==0:
        a=i
    elif c[i] >= 2 and l==0:
        l=i
    elif c[i] >= 2 and b==0:
        b=i
print(max(l*b,a*a))

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
cnt = 0
ans = 1
for i in sorted(set(L),reverse=True):
  if L.count(i)>=4 and cnt==0:
    print(i*i)
    exit()
  elif 2<=L.count(i)<=4:
    ans *= i
    cnt += 1
    if cnt == 2:
      break
print(0 if cnt<2 else ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
cnt = 0
ans = 1
for i in sorted(set(L),reverse=True):
  if L.count(i)>=4:
    print(i*i)
    exit()
  elif 2<=L.count(i)<4:
    ans *= i
    cnt += 1
    if cnt == 2:
      break
print(0 if cnt<2 else ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
a = []
for l in L:
  if L.count(l) >= 4 and a==[]:
    print(l*l)
    exit()
  elif L.count(l)>=2 and l not in a:
    print(l)
    a.append(l)
    if len(a) == 2:
      break
print(0 if a==[] else a[0]*a[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
a = []
print([l*l for l in L if L.count(l)>=4 and a==[]]) 
for l in L:
  if L.count(l) >= 4 and a==[]:
    print(l*l)
    exit()
  if L.count(l)>=2 and l not in a:
    print(l)
    a.append(l)
    if len(a) == 2:
      break
if a==[]:
  print(0)
else:
  print(a[0]*a[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
a = []
for l in L:
  if L.count(l) == 4 and a==[]:
    print(l*l)
    exit()
  if L.count(l)>=2 and l not in a:
    a.append(l)
    if len(a) == 2:
      break
if a==[]:
  print(0)
else:
  print(a[0]*a[1])

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

    if 4 <= n and n <= 10**5:
        
        for i in a:
            if 1 > i or i > 10**9 or type(i) != int:
                return

        j = [x for x in a if a.count(x) > 1]
        j.sort(reverse = True)

        if len(j) < 4:
            print(0)
            return

        print(j[0]*j[2])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    if 4 <= n and n <= 10**5:
        
        for i in a:
            if not (1 <= i and i <= 10**9 and type(i) == int):
                return

        j = [x for x in a if a.count(x) > 1]
        j.sort(reverse = True)

        if len(j) < 4:
            print(0)
            return

        print(j[0]*j[2])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    if 4 <= n and n <= 10**5:        
        for i in a:
            if not (1 <= i and i <= 10**9 and isinstance(i, int)):
                return

        j = [x for x in a if a.count(x) > 1]
        j.sort(reverse = True)

        if len(j) < 4:
            print(0)
            return

        print(j[0]*j[2])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    if not (4 <= n and n <= 10**5):        
        for i in a:
            if not (1 <= i and i <= 10**9 and isinstance(i, int)):
                return

        j = [x for x in a if a.count(x) > 1]
        j.sort(reverse = True)

        if len(j) < 4:
            print(0)
            return

        print(j[0]*j[2])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    if not (4 <= n and n <= 10**5):
        return
    for i in a:
        if not (1 <= i and i <= 10**9 and isinstance(i, int)):
            return

    j = [x for x in a if a.count(x) > 1]
    j.sort(reverse = True)

    if len(j) < 4:
        print(0)
        return

    print(j[0]*j[2])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


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

    if not (4 <= n and n <= 10**5 and isinstance(n, int)):
        return
    for i in a:
        if not (1 <= i and i <= 10**9 and isinstance(i, int)):
            return

    j = [x for x in a if a.count(x) > 1]
    j.sort(reverse = True)

    if len(j) < 4:
        print(0)
        return

    print(j[0]*j[2])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    if not (4 <= n and n <= 10**5 and isinstance(n, int)):
        return
    for i in a:
        if not (1 <= i and i <= 10**9 and isinstance(i, int)):
            return

    j = [x for x in a if a.count(x) > 1]
    j.sort(reverse = True)

    if len(j) < 4:
        print(0)
        return

    print(j[0]*j[2])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections as c
d=c.Counter(a)
d=list(d.items())
d=sorted(d,reverse=True)
x,y=0,0
for i in d:
    if x==0 and i[1]>=2:
        x=i[0]
        continue
    if y==0 and i[1]>=2:
        y=i[0]
        break
print(x*y)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

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

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

print(mae*ato)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input().split())
q=1
j=0
for i in range(n-1,-1,-1):
  if a.count(str(i))>=4:
    print(i*i)
    exit()
  elif a.count(str(i))>=2 and j<2:
    q*=i
    j+=1
  else:
    pass
print(q)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L = []
for s in S:
    if A.count(s) > 1:
        L.append(s)
    if len(L) == 2:
        print(L[0]*L[1])
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
c=list(b.items())
d=[]
e=[]
for i in range(len(c)):
  if c[i][1]>3:
    d.append(int(c[i][0]))
  elif c[i][1]>1:
    e.append(int(c[i][0]))
d.sort(reverse=True)
e.sort(reverse=True)
if len(d)<1 and len(e)<2:
  print(0)
else:
  if len(d)==0:
    print(e[0]*e[1])
  elif len(e)<2:
    print(d[0]**2)
  elif len(d)>0 and len(e)>1:
    print(max((d[0])**2,e[0]*e[1]))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
c=list(b.items())
d=[]
for i in range(len(c)):
  if c[i][1]>1:
    d.append(int(c[i][0]))
d.sort(reverse=True)
if len(d)<2:
  print(0)
else:
  print(d[0]*d[1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
c=list(b.items())
d=[]
for i in range(len(c)):
  if c[i][1]>1:
    d.append(c[i][0])
d.sort(reverse=True)
if len(d)<2:
  print(0)
else:
  print(d[0]*d[1])