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:
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 01:19:32 2020

@author: shinba
"""
import collections

n = int(input())

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

data = collections.Counter(A)

I = sorted(data.items(),reverse = True)

s = 1
cnt = 0 

for i,j in I:
    if j >= 2:
        s *= i
        cnt += 1
    if cnt == 2:
        print(s)
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#!python3

def LI():
    return list(map(int, input().split()))

# input
N = int(input())
A = LI()


def main():
    d = {}
    for a in A:
        d[a] = d[a] + 1 if a in d else 1
    
    l = []
    for k, v in d.items():
        if v >= 2:
            l.append(k)
    
    l.sort(reverse=True)
    ans = 0 if len(l) < 2 else l[0] * l[1]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()
    a = na()

    c = collections.Counter(a)

    e = sorted(c.items(),reverse=True)
    ans_e=[]
    cnt=0
    for k,v in e:
        if cnt == 2:
            break
        if v>1:
            ans_e.append(k)
            cnt+=1

    if cnt == 2:
        print(ans_e[0]*ans_e[1])
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)


ans = [0, 0]
for i, j in c.items():
    if j >= 2:
        ans.append(i)

ans.sort()    

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

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
p = list(map(int,input().split()))
cnt = collections.Counter(p)

maxs = []
for k, v in cnt.items():
  if v > 1:
    maxs.append(k)
    
if len(maxs) > 1:
  maxs.sort()
  print(maxs[-1] * maxs[-2])

else:
  print(0)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
p = list(map(int,input().split()))
cnt = collections.Counter(p)

maxs = []
for k, v in cnt.items():
  if v > 1:
    maxs.append(k)
    
if maxs:
  maxs.sort()
  print(maxs[-1] * maxs[-2])

else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter


N = int(input())
c = Counter(map(int, input().split()))
usables = sorted([k for k, v in c.items() if v >= 2])
if len(usables) <= 1:
    print(0)
else:
    print(usables[-1] * usables[-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter


N = int(input())
c = Counter(list(map(int, input().split())))
usables = [k for k, v in c.items() if v >= 2]
if len(usables) <= 1:
    print(0)
else:
    print(usables[-1] * usables[-2])

Submission status: Wrong Answer

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

li.sort(reverse=True)

check = -1
flag = 0
ans = []

for i in li:
    if len(ans) == 2:
        break
    
    if flag == 0:
        check = i
        flag = 1
        continue
    
    if check == i:
        ans.append(i)
        flag = 0
    else:
        flag = 0
        check = i

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

Submission status: Wrong Answer

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

li.sort(reverse=True)

check = -1
flag = 0
ans = []

for i in li:
    if len(ans) == 2:
        break
    
    if flag == 0:
        check = i
        flag = 1
        continue
    
    if check == i:
        ans.append(i)
        flag = 0
    else:
        flag = 0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,(input().split())))
from collections import Counter
c = Counter(a)
L = []
LL = []
for k in c.keys():
    if c[k] >= 2:
        L.append(k)
    if c[k] >= 4:
        LL.append(k)
if LL:
    print((max(LL)**2))
else:
    if len(L) < 2:
        print(0)
    else:
        L.sort(reverse=True)
        print(L[0]*L[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,(input().split())))
from collections import Counter
c = Counter(a)
L = []
for k in c.keys():
    if c[k] >= 2:
        L.append(k)
if len(L) < 2:
    print(0)
else:
    L.sort(reverse=True)
    print(L[0]*L[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
ls = list(map(int,input().split()))
import collections
c = collections.Counter(ls)
unique_ls = list(reversed(sorted(([i[0] for i in c.items() if i[1] >= 2]))))

rectan_a = 0
rectan_b =0

for i in range(len(unique_ls)):
  if ls.count(unique_ls[i]) >=4:
    rectan_a = unique_ls[i]
    rectan_b = unique_ls[i]
    break
  elif (ls.count(unique_ls[i]) == 2) or (ls.count(unique_ls[i]) == 3):
    if rectan_a ==0:
      rectan_a = unique_ls[i]
    else:
      rectan_b = unique_ls[i]
      break
  else:
    pass
print(rectan_a * rectan_b)

Submission status: Wrong Answer

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

unique_ls = list(reversed(sorted(list(set(ls)))))

rectan_a = 0
rectan_b = 0

for i in range(len(unique_ls)):
  if ls.count(unique_ls[i]) >=4:
    rectan_a = unique_ls[i]
    rectan_b = unique_ls[i]
    break
  elif (ls.count(unique_ls[i]) == 2) or (ls.count(unique_ls[i]) == 3):
    if rectan_a ==0:
      rectan_a = unique_ls[i]
    else:
      rectan_b = unique_ls[i]
      break
  else:
    pass
print(rectan_a * rectan_b)

Submission status: Wrong Answer

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

unique_ls = list(reversed(list(set(ls))))

rectan_a = 0
rectan_b =0

for i in range(len(unique_ls)):
  if ls.count(unique_ls[i]) >=4:
    rectan_a = unique_ls[i]
    rectan_b = unique_ls[i]
    break
  elif (ls.count(unique_ls[i]) == 2) or (ls.count(unique_ls[i]) == 3):
    if rectan_a ==0:
      rectan_a = unique_ls[i]
    else:
      rectan_b = unique_ls[i]
      break
  else:
    pass
print(rectan_a * rectan_b)

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)

cnt = Counter(arrA)
ans = 0
lis = sorted(list(cnt.items()))
n = len(lis)

shrt = 0
lng = 0
for i in range(n):
    if shrt == 0 and lis[i][1]>=2:
        shrt = lis[i][0]
    elif lis[i][1]>=2:
        lng = lis[i][0]
        ans = max(ans,lng*shrt)
        shrt = lng
    else:
        pass





print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import Counter

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

k = 0
area = 1
for a,b in c.items():
    if b >1:
        area *= a
        k += 1
    if k > 1:
        print(area)
        exit()
print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import Counter

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

k = 0
area = 1
for a,b in c.items():
    if b >1:
        area *= a
        k += 1
    if k > 1:
        print(area)
        exit()
print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
L=sorted(set(A))[::-1]
#print(L)
flag=0
C=[]
for i in L:
  if A.count(i)>=4:
    print(i**2)
    flag=1
    break
  elif A.count(i)>=2:
    C.append(i)
    if len(C)>=2:
      break
  
#print(C)

if len(C)<2 and flag==0:
  print(0)
elif len(C)>=2 and flag==0:
  print(C[0]*C[1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
L=sorted(set(A))[::-1]
#print(L)
C=[]
for i in L:
  if A.count(i)>=2:
    C.append(i)
    if len(C)>=2:
      break

C=sorted(C)[::-1]    
#print(C)

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
L=sorted(set(A))
C=[]
for i in L:
  if A.count(i)>=2:
    C.append(i)
C=sorted(C)[::-1]    

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

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

for a in As:
    d[a] += 1

cnt = 0
ans = []
for k in sorted(list(d.keys()),reverse=True):
    if d[k] > 1:
        cnt+=1
        ans.append(k)
    if cnt == 2:break
# print(ans)
if len(ans) < 2:
    ans = []
    for k in sorted(list(d.keys()),reverse=True):
        if d[k] > 1:
            cnt+=1
            ans.append(k)
        if cnt == 4:break
    if len(ans) == 1:
        print(ans[0]**2)
    else:
        print(0)
else:
    print(ans[1]*ans[0])

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

for a in As:
    d[a] += 1

cnt = 0
ans = []
for k in sorted(list(d.keys()),reverse=True):
    if d[k] > 1:
        cnt+=1
        ans.append(k)
    if cnt == 2:break
# print(ans)
if len(ans) < 2:
    print(0)
else:
    print(ans[1]*ans[0])

Submission status: Wrong Answer

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

import collections
c = collections.Counter(a_li)

mc = c.most_common()
# [('a', 4), ('c', 2), ('b', 1)]

if len(mc) == 1 and mc[0][1]<=3:
    print(0)
    exit()
if len(mc) == 1 and mc[0][1]>3:
    print(mc[0]**2)
    exit()
all_li = []
for m in mc:
    if m[1]>=2:
        all_li.append(m[0])
if len(all_li) <= 1:
    print(0)
    exit()
all_li.sort(reverse=True)
#print(all_li)
print(all_li[0]*all_li[1])

Submission status: Wrong Answer

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

import collections
c = collections.Counter(a_li)

mc = c.most_common()
# [('a', 4), ('c', 2), ('b', 1)]

if len(mc) == 1:
    print(0)
    exit()
all_li = []
for m in mc:
    if m[1]>=2:
        all_li.append(m[0])
if len(all_li) <= 1:
    print(0)
    exit()
all_li.sort(reverse=True)
print(all_li[0]*all_li[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
ans = Counter(a)
b = sorted(ans)
ans1 = []
for i in b[::-1]:
    if ans[i]==2:
        ans1.append(i)
    elif ans[i]>=4:
        ans1.append(i)
        ans1.append(i)
        
if len(ans1)>=2:
    sqr = ans1[0]*ans1[1]
    print(sqr)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
ans = Counter(a)
b = sorted(ans)
ans1 = []
for i in b[::-1]:
    if ans[i] > 1:
        ans1.append(i)
        
if len(ans1)>=2:
    sqr = ans1[0]*ans1[1]
    print(sqr)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import*
a, b = sorted(int(i[0]) for i in Counter(open(0).read().split()[1:]+[0,-1]*2).items() if i[1] > 1)[:-3:-1]
print(a*b)

Submission status: Wrong Answer

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

a.sort(reverse=True)
c = 0
v = []
for i in range(n-1):
    if a[i] != a[i+1]:
        c += 1
        if c >= 2:
            v.append([a[i],c])
        c = 0
    else:
        c += 1
if a.count(a[-1]) >=2 :
    v.append([a[-1],a.count(a[-1])])
if len(v) == 0:
    print(0)
elif len(v) >= 2:
    print(v[0][0]*v[1][0])
else:
    print(v[0][0]**2)

Submission status: Wrong Answer

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

a.sort(reverse=True)
c = 0
v = []
for i in range(n-1):
    if a[i] != a[i+1]:
        c += 1
        if c >= 2:
            v.append([a[i],c])
        c = 0
    else:
        c += 1
v.append([a[-1],a.count(a[-1])])
if len(v) < 2:
    print(0)
else:
    print(v[0][0]*v[1][0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
ans_lis = []
count = 1
before = A[0]
for i in range(1,N):
  tmp = A[i]
  if tmp == before:
    count += 1
  else:
    if count == 2 or count == 3:
      ans_lis.append(before)
    elif count >= 4 and len(ans_lis) == 0:
      ans_lis.append(before)
      ans_lis.append(before)
    elif count >= 4 and len(ans_lis) != 0:
      ans_lis.append(before)
    count = 1
  if len(ans_lis) == 2:
    break
  before = tmp
if len(ans_lis) < 2:
  print(0)
else:
  print(ans_lis[0] * ans_lis[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
ans_lis = []
count = 1
before = A[0]
for i in range(1,N):
  tmp = A[i]
  if tmp == before:
    count += 1
  else:
    if count == 2 or count == 3:
      ans_lis.append(before)
    elif count >= 4 and len(ans_lis) == 0:
      ans_lis.append(before)
      ans_lis.append(before)
    count = 1
  if len(ans_lis) == 2:
    break
  before = tmp
if len(ans_lis) < 2:
  print(0)
else:
  print(ans_lis[0] * ans_lis[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
ans_lis = []
count = 1
before = A[0]
for i in range(1,N):
  tmp = A[i]
  if tmp == before:
    count += 1
  else:
    if count == 2 or count == 3:
      ans_lis.append(tmp)
    elif count >= 4 and len(ans_lis) == 0:
      ans_lis.append(tmp)
      ans_lis.append(tmp)
    count = 0
  if len(ans_lis) == 2:
    break
  before = tmp
if len(ans_lis) < 2:
  print(0)
else:
  print(ans_lis[0] * ans_lis[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
ans_lis = []
count = 1
before = A[0]
for i in range(1,N):
  tmp = A[i]
  if tmp == before:
    count += 1
  else:
    if count == 2 or count == 3:
      ans_lis.append(tmp)
    elif count == 4 and len(ans_lis) == 0:
      ans_lis.append(tmp)
      ans_lis.append(tmp)
    count = 0
  if len(ans_lis) == 2:
    break
  before = tmp
if len(ans_lis) < 2:
  print(0)
else:
  print(ans_lis[0] * ans_lis[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
bef=a[0]
ren=1
c=0 #二個以上の組が何個あるか
hen1=0
hen2=0
for i in range(1,n):
    if bef==a[i]:
        ren+=1
    else:
        if 2<=ren:
            if c==0:
                c+=1
                hen1=bef
            else:
                c+=1
                hen2=bef
                break
        bef=a[i]
        ren=1
if c==1 and 2<=ren:
    hen2=bef
print(hen1*hen2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
bef=a[0]
ren=1
c=0 #二個以上の組が何個あるか
hen1=0
hen2=0
for i in range(1,n):
    if bef==a[i]:
        ren+=1
    else:
        if 2<=ren:
            if c==0:
                c+=1
                hen1=bef
            else:
                hen2=bef
                break
        bef=a[i]
        ren=1
if c==1 and 2<=ren:
    hen2=bef
print(hen1*hen2)

Submission status: Wrong Answer

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

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

A = [[k, v] for k, v in cnt.items()]
A.sort(reverse=True)

h = 0
w = 0
for k, v in A:
    if v >= 4:
        h = k
        w = k
        break
    elif v >= 2 and h > 0:
        w = k
        break
    elif v >= 2 and h == 0:
        h = k

print(h * w)

Submission status: Wrong Answer

Solution code:
from collections import Counter
m1,m2=0,0
N=int(input())
A=Counter(list(map(int,input().split())))
key=sorted(A.keys(),reverse=True)
for i in key:
  if A[i]>1 and m1==0:
    m1=i
  elif m1!=0 and A[i]>1:
    print(m1*i)
    exit()
print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
m1,m2=0,0
N=int(input())
A=Counter(list(map(int,input().split())))
key=sorted(A.keys(),reverse=True)
for i in key:
  if A[i]>1 and m1==0:
    m1=A[i]
  if m1!=0 and A[i]>1:
    print(m1*A[i])
    exit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int, input().split()))
d = [x for x, y in collections.Counter(A).items() if y > 1]
if len(d) < 2:
    print(0)
else:
    d.sort(reverse=True)
    print(d[0]*d[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
c=collections.Counter(a)
t=list(c.items())
t.sort(reverse=True)
if t[0][1]>=4:
  print(t[0][0]**2)
elif t[1][1]>=2:
  print(t[0][0]*t[1][0])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import collections
def main():

    n = int(input())
    a = list(map(int,input().split()))
    # a.sort(reverse=True)
    c = collections.Counter(a)
    cl = c.most_common()
    # cl.sort(reverse = True)
    cnt = 1
    lst = []
    now = a[0]
    ans = 0
    for i, cc in enumerate(cl):
        if cc[1] == 4:
            ans = max(ans,cc[0]**2)

        if cc[1] >= 2:
            lst.append(cc[0])
        # if len(lst) == 2:
        #     print(lst[0] * lst[1])
        #     return
    if len(lst) >= 2:
        lst.sort(reverse=True)
        ans = max(ans, lst[0] * lst[1])

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

Submission status: Wrong Answer

Solution code:
import collections
def main():

    n = int(input())
    a = list(map(int,input().split()))
    # a.sort(reverse=True)
    c = collections.Counter(a)
    cl = c.most_common()
    cl.sort(reverse = True)
    cnt = 1
    lst = []
    now = a[0]
    for i, cc in enumerate(cl):
        if cc[1] == 4:
            print(cc[0]**2)
            return
        if cc[1] >= 2:
            lst.append(cc[0])
        if len(lst) == 2:
            print(lst[0] * lst[1])
            return

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

Submission status: Wrong Answer

Solution code:
# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    N=int(input())
    A=sorted(list(map(int,input().split())),reverse=True)
    temp=-1
    maxans=0
    AA=Counter(A)
    for (i,j) in AA.items():
        if j>=4:
            maxans=max(i**2,maxans)
        if j>=2:
            if temp>=0:
                maxans=max(maxans,temp*i)
            temp=i
    print(maxans)




resolve()

Submission status: Wrong Answer

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

A.sort(reverse=True)
tmp = 0
tate = 0
yoko = 0
cnt = 0
for i in A:
    if tmp == i and cnt == 0:
        tate = i
        cnt += 1
        tmp = 0
        continue
    if tmp == i and cnt == 1:
        yoko = i
        cnt += 1
        break
    tmp = i
print(tate*yoko)

Submission status: Wrong Answer

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

A.sort(reverse=True)
tmp = 0
tate = 0
yoko = 0
cnt = 0
for i in A:
    if tmp == i and cnt == 0:
        tate = i
        cnt += 1
        tmp = 0
        continue
    if tmp == i and cnt == 1:
        yoko = i
        cnt += 1
    if cnt == 2:
        break
    tmp = i
print(tate*yoko)

Submission status: Wrong Answer

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

d = {}
m = set()
for i in l:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1
        if d[i] > 1:
            m.add(i)
a = sorted(m, reverse=True)[:2]
if len(a) == 0:
    print(0)
    exit()
elif len(a) == 1 and d[a[0]] < 4:
    print(0)
    exit()
if d[a[0]] > 3:
    print(i*i)
    exit()
print(a[0]*a[1])

Submission status: Wrong Answer

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

d = {}
m = set()
for i in l:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1
        if d[i] > 2:
            m.add(i)
a = sorted(m, reverse=True)[:2]
if len(a) == 0:
    print(0)
    exit()
elif len(a) == 1 and d[a[0]] < 4:
    print(0)
    exit()
if d[a[0]] > 3:
    print(i*i)
    exit()
print(a[0]*a[1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c = collections.Counter(A)

area = []
for key in c.keys():
    if(c[key] > 1):
        if(c[key]//2 == 1):
            area.append(key)
            if(len(area) == 2):
                print(area[0]*area[1])
                break
        else:
            area.append(key)
            if(len(area) > 1):
                print(max(key*key, area[0]*area[1]))
                break
            else:
                print(key*key)
                break
else:
    print(0)

Submission status: Wrong Answer

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

c = collections.Counter(A)

area = []
for key in c.keys():
    if(c[key] >= 2):
        if(c[key] == 2 or c[key] == 3):
            area.append(key)
            if(len(area) == 2):
                print(area[0]*area[1])
                break
        else:
            print(key*key)
            break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# import bisect
from collections import Counter
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

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

    AA=Counter(A).most_common()

    ls=[]
    for i in range(len(AA)):
        if AA[i][1]>=2:
            ls.append(AA[i])
        else:
            break

    #ls=sorted(ls, key=lambda x: x[1])

    try:
        ans=ls[-1][0]*ls[-2][0]
        for i in reversed(range(len(ls))):
            if ls[i][1]>=4:
                ans=max(ans,ls[i][0]**2)
        print(ans)
    except:
        print(0)



resolve()

Submission status: Wrong Answer

Solution code:
# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

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

    AA=Counter(A).most_common()

    ls=[]
    for i in range(len(AA)):
        if AA[i][1]>=2:
            ls.append(AA[i][0])

    ls.sort()
    try:
        print(ls[-1]*ls[-2])
    except:
        print(0)



resolve()

Submission status: Wrong Answer

Solution code:
import collections as c

n = int(input())
co = c.Counter(list(map(int, input().split())))
cm = sorted(co.items(), key=lambda x:x[0], reverse=True)
a = 0
b = 0
for v,m in cm:
  if m >= 4:
    a = b = v
    break
  elif m >= 2 and a == 0:
    a = v
  elif m >= 2 and a != 0:
    b = v
    break
print(a*b)

Submission status: Wrong Answer

Solution code:
import collections as c

n = int(input())
co = c.Counter(list(map(int, input().split())))
cm = co.most_common()
a = 0
b = 0
for v,m in cm:
  if m >= 4:
    a = b = v
    break
  elif m >= 2 and a == 0:
    a = v
  elif m >= 2 and a != 0:
    b = v
    break
print(a*b)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
s = list(set(l))
s.sort(reverse=True)
a = 0
b = 0
for i in range(len(s)):
  if l.count(s[i]) >= 4:
    a = b = s[i]
    break
  elif l.count(s[i]) >= 2 and a == 0:
    a = s[i]
  elif l.count(s[i]) >= 2 and a != 0:
    b = s[i]
    break
print(a*b)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Aset = list(set(A))
Aset.reverse()
a, b = 0, 0
L = []
cnt = 1
for i in range(1, N):
    if A[i] == A[i-1]:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
L.append(cnt)
idx = 0
for i in range(len(Aset)):
    if L[i] >= 4:
        a, b = Aset[i], Aset[i]
        break
    elif L[i] >= 2:
        a = Aset[i]
        idx = i + 1
        break
if b <= 0:
    for i in range(idx, len(Aset)):
        if L[i] >= 2:
            b = Aset[i]
            break
print(a * b)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Aset = list(set(A))
Aset.reverse()
a, b = 0, 0
L = []
cnt = 1
for i in range(1, N):
    if A[i] == A[i-1]:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
L.append(cnt)
idx = 0
for i in range(len(Aset)):
    if L[i] >= 4:
        a, b = Aset[i], Aset[i]
        break
    elif L[i] >= 2:
        a = Aset[i]
        idx = i + 1
        break
for i in range(idx, len(Aset)):
    if L[i] >= 2:
        b = Aset[i]
        break
print(a * b)

Submission status: Wrong Answer

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
h = {}
for x in a:
    if x not in h:
        h[x] = 0
    h[x] += 1
b = []
for x in h:
    if h[x]>=2:
        b.append(x)
if len(b)>=1 and h[b[-1]]>=4:
    print(b[-1]*b[-1])
elif len(b)<2:
    print(0)
else:
    print(b[-1]*b[-2])

Submission status: Wrong Answer

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
h = {}
for x in a:
    if x not in h:
        h[x] = 0
    h[x] += 1
b = []
for x in h:
    if h[x]>=2:
        b.append(x)
if len(b)<2:
    print(0)
else:
    print(b[-1]*b[-2])

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(A)

x = 0
y = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v >= 2:
        if x == 0:
            x = k
        elif y == 0:
            y = k

print(x*y)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
from collections import Counter
c=Counter(a)
li=[]
for i in c.keys():
    if c[i]>=2:
        li.append(i)
if len(li)>=2:
    print(li[0]*li[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
from collections import Counter
c=Counter(a)
li=[]
for i in c.keys():
    if c[i]>=2:
        li.append(i)
if len(li)>=2:
    print(li[0]*li[1])
else:
    print(0)

Submission status: Wrong Answer

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

L = sum([[1] for a, c in cnt.items()], [])
L.sort()

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

Submission status: Wrong Answer

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

L = sum([[] for a, c in cnt.items()], [])
L.sort()

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

Submission status: Wrong Answer

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

L = sum([[a] * (c // 2) for a, c in cnt.items()], [])

print(-1)

Submission status: Wrong Answer

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

for i in a:
    d[i] += 1
ans = []

for v, c in d.items():
    if c >= 2:
        ans.append(v)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A=list(map(int,input().split()))
c=dict(Counter(A))
#print(c)
e=[]

for i in c:
  if c[i]>1:
    e.append(i)
    
e.sort(reverse=True)
if len(e)>=2:
  print(e[0]*e[1])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import collections
 
n = int(input())
lens = list(map(int,input().split()))
lens = collections.Counter(lens)
lens = sorted(lens.items(), key=lambda x:x[0])
cnt = 0
for j in lens:
  if j[1] >= 4 and cnt == 0:
    print(j[0]**2)
    break
  elif j[1] >= 2 and cnt == 0:
    cnt = j[0]
  elif j[1] >= 2 and cnt != 0:
    print(cnt * j[0])

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
lens = list(map(int,input().split()))
lens = collections.Counter(lens)
lens = sorted(lens.items(), key=lambda x:x[0])
cnt = 0
for j in lens:
  if j[1] >= 4 and cnt != 0:
    print(j[0]*2)
    break
  elif j[1] >= 2 and cnt == 0:
    cnt = j[0]
  elif j[1] >= 2 and cnt != 0:
    print(cnt * j[0])
    break
else:
  print(0)