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())
al = list(map(int, input().split()))

import collections

c = collections.Counter(al)
temp = list(reversed(list(set(al))))
x = 0
y = 0

for i in temp:
    if c[i]>=4:
        if x ==0:
            x = i
        if y ==0:
            y = i
    elif c[i] >=2:
        if x ==0:
            x =i
        elif y ==0:
            y = i
    if x*y != 0:
        print(x*y)
        exit()        
print(x*y)

Submission status: Wrong Answer

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

for i in a:
  if i not in dict:
    dict[i] = 1
  else:
    dict[i] += 1
  
dictlis = sorted(dict.items())
count = 0
ans = 1


for i in range(len(dictlis)):
  if dictlis[len(dictlis) -1 -i][1] >= 4 and count != 2: 
    print((dictlis[len(dictlis) -1 -i][0])**2)
    exit()
  elif  3>=dictlis[len(dictlis) -1 -i][1] >= 2:
    count += 1
    ans = dictlis[len(dictlis) -1 -i][0]*ans
    if count == 2:
      print(ans)
      exit()
      
print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    dupl_bars = [length for length, cnt in counter.items() if cnt > 1]
    dupl_bars.sort(reverse=True)
    if len(dupl_bars) > 1:
        print(dupl_bars[0] * dupl_bars[1])
    else:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

dic = {}
for i in s:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

dic2 = sorted(dic.items(),reverse=True)#[(4, 1), (3, 1), (2, 2), (1, 2)]

i = 0
tmp = 0
while i < len(dic2):
    if dic2[i][1] >= 4:
        print(dic2[i][0]**2)
        exit()
    if dic2[i][1] >= 2 and tmp == 0:
        tmp = dic2[i][0]
    elif dic2[i][1] >= 2 and tmp != 0:
        print(tmp*dic2[i][0])
        exit()
    i += 1
print(0)

Submission status: Wrong Answer

Solution code:
M = int(input())
A = list(map(int,input().split()))
B = [0]*(M+1)
C = [0]*2
D = [0]*2

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = [int(x) for x in input().split()]
c = collections.Counter(A)
cc = {k:v for k, v in c.items() if v>1}
if len(cc) > 1:
    ccc = sorted(list(cc.keys()))[-2:]
    print(ccc[0] * ccc[1])
elif len(cc)==1 and max(cc.values()) > 3:
    print(cc.popitem()[0] ** 2)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = [int(x) for x in input().split()]
c = collections.Counter(A)
cc = {k:v for k, v in c.items() if v>1}
if len(cc) > 1:
    ccc = sorted(list(cc.keys()))[-2:]
    print(ccc[0] * ccc[1])
elif len(cc)==1 and max(cc.values()) > 3:
    print(cc.popitem()[0] * 2)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = [int(x) for x in input().split()]
c = collections.Counter(A)
cc = {k:v for k, v in c.items() if v>1}
ccc = sorted(list(cc.keys()))[-2:]
if len(ccc)==2:
    print(ccc[0] * ccc[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = [int(x) for x in input().split()]
c = collections.Counter(A)
cc = {k:v for k, v in c.items() if v>1}
ccc = sorted(list(cc.keys())[-2:])
if len(ccc)==2:
    print(ccc[0] * ccc[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = [int(x) for x in input().split()]
c = collections.Counter(A)
cc = {k:v for k, v in c.items() if v>1}
ccc = list(cc.keys())[-2:]
if len(ccc)==2:
    print(ccc[0] * ccc[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
c=Counter(A)
c=c.most_common()
c.sort(reverse=True,key=lambda x:x[0])
cnt=0
H=0
W=0
for i in range(len(c)):
    if cnt==0 and c[i][1]>=4:
        H,W=c[i][0],c[i][0]
        print()
        exit()
    elif cnt==0 and c[i][1]>=2:
        H=c[i][0]
        cnt+=1
    elif cnt==1 and c[i][1]>=2:
        W=c[i][0]
        print(H*W)
        exit()
print(H*W)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

N = I()
A = IL()
d = DD(int)
for a in A:
  d[a] += 1
  
d = [(d[k],k)for k in d]
d.sort(reverse=True)
ans = []
for a,k in d:
  if a>=2:
    ans.append(a)
  if len(ans)==2:
    break
if len(ans)==2:
  P(ans[0]*ans[1])
else:
  P(0)

Submission status: Wrong Answer

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

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

if len(d) < 2:
    print(0)
else:
    d = sorted(d,reverse=True)
    x = d[0]
    y = d[1]

    print(x*y)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a).most_common()

edge = sorted(key for key, val in c if val >= 2)
print(edge[-2] * edge[-1]) if len(edge) >= 2 else print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a).most_common()

edge = [key for key, val in c if val >= 2]
print(edge[-2] * edge[-1]) if len(edge) >= 2 else print(0)

Submission status: Wrong Answer

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

A_count = collections.Counter(A)

keys = sorted(list(A_count.keys()), reverse=True)

hen_list = []
flag = 0
for key in keys:
    if A_count[key] >= 4:
        hen_list.append(key)
        hen_list.append(key)
    elif A_count[key] >= 2:
        hen_list.append(key)
    if len(hen_list) == 2:
        flag = 1
        break
if flag == 1:
    print(hen_list[0] * hen_list[1])
else:
    print(0)

Submission status: Wrong Answer

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

A_count = collections.Counter(A)

keys = sorted(list(A_count.keys()), reverse=True)

hen_list = []
flag = 0
for key in keys:
    if A_count[key] >= 4:
        hen_list.append(key)
        hen_list.append(key)
    if A_count[key] >= 2:
        hen_list.append(key)
    if len(hen_list) == 2:
        flag = 1
        break
if flag == 1:
    print(hen_list[0] * hen_list[1])
else:
    print(0)

Submission status: Wrong Answer

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

A_count = collections.Counter(A)

keys = sorted(list(A_count.keys()), reverse=True)

hen_list = []
flag = 0
for key in keys:
    if A_count[key] >= 2:
        hen_list.append(key)
    if len(hen_list) == 2:
        flag = 1
        break
if flag == 1:
    print(hen_list[0] * hen_list[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 0
items = list(set(A))
count = [0]*len(items)
items.reverse()
for i in range(N):
    count[items.index(A[i])] += 1

for i in range(len(count)):
    if ans == 0:
        if count[i] >= 4:
            ans = items[i]**2
            break
        elif count[i] >= 2:
            ans = items[i]
    else:
        if count[i] >= 2:
            ans *= items[i]
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
A = list(map(int,input().split()))
cnt = 0
ans = 1
A.sort(reverse=True)

for i in A:
    count2 = 0
    if i == ans:
        continue
    for j in A:
        if i == j:
            count2 += 1
        if count2 == 2:
            ans *= i
            cnt += 1
            break
    if cnt == 2:
        print(ans)
        exit()
print(0)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
A = list(map(int,input().split()))
# max = 0
# comb = list(itertools.combinations(A,4))
# for i in range(len(comb)):
#     item = list(set(comb[i]))
#     if len(item) == 2:
#         if max < item[0]*item[1]:
#             max = item[0]*item[1]
ans = []
for i in A:
    count = 0
    if i in ans:
        continue
    for j in A:
        if i == j:
            count += 1
        if count == 2:
            ans.append(i)
            break
if len(ans) >= 2:
    ans.sort(reverse=True)
    print(ans[0]*ans[1])
else:
    print(0)

Submission status: Wrong Answer

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

if len(a) > len(A)-2:
    print(0)
    exit()

A.sort(reverse=True)
ans = []

for i in range(len(A)-1):
    if A[i] !=A[i+1]:
        continue
    else:
        ans.append(A[i])
        i += 1

z = list(set(ans))
z.reverse()
print(z[0]*z[1])

Submission status: Wrong Answer

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

if len(a) > len(A)-2:
    print(0)
    exit()

A.sort(reverse=True)
ans = []

for i in range(len(A)-1):
    if A[i] !=A[i+1]:
        continue
    else:
        ans.append(A[i])
        i += 1

z = list(set(A))
z.reverse()
print(z[0]*z[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
s = list(set(a))
s.sort(reverse=True)
citm = list(c.items())
citm.sort(reverse=True)
l = []
for i in range(len(s)):
    if len(l)>=2:
        break
    else:
        if citm[i][1]>=4:
            l.append(citm[i][0])
            l.append(citm[i][0])
        elif citm[i][1]>=2:
            l.append(citm[i][0])
if len(l)==2:
    print(l[0]*l[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
s = list(set(a))
s.sort(reverse=True)
l = len(s)
ans = 0
#print(c,s)
for i in range(l):
    #print(c[s[i]],s[i],i)
    j=i+1
    if c[s[i]]<2:
        pass
    else:
        if c[s[i+1]]<=2:
            for j in range(i+1,l):
                if c[s[j]]>=2:
                    break
        if c[s[i]]>=4:
            ans=max(ans,s[i]*2)
            break
        elif c[s[i]]>=2 and c[s[j]]>=2:
            ans=max(ans,s[i]*s[j])
            break
        else:
            pass
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
s = list(set(a))
s.sort(reverse=True)
ans = 0
for i in range(len(s)-1):
    if c[s[i]]>=4:
        ans=max(ans,s[i]*2)
        break
    elif c[s[i]]>=2 and c[s[i+1]]>=2:
        ans=max(ans,s[i]*s[i+1])
        break
    else:
        pass
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
c_key   = list(c.keys())
c_value = list(c.values())
new_c_key = []
new_c_value = []
for i in range(len(c_value)):
    if int(c_value[i]) >= 2:
        new_c_key.append(int(c_key[i]))
        new_c_value.append(int(c_value[i]))
if len(new_c_value) < 2:
    print(0)
    exit()
if new_c_value[-1] >= 4:
    print(new_c_key[-1]**2)
else:
    print(new_c_key[-1]*new_c_key[-2])

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    *c, = map(lambda x: tuple(x), b.items())
    c.sort(key=lambda x: x[0], reverse=True)

    ans = 1
    count = 0
    for (k, v) in c:
        if v >= 4 and ans == 1:
            ans = k ** 2
            break
        if v >= 2:
            ans *= k
            count += 1
        if count == 2:
            break
    if count < 2:
        print(0)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    *c, = map(lambda x: tuple(x), b.items())
    c.sort(key=lambda x: x[0], reverse=True)

    ans = 1
    count = 0
    for (k, v) in c:
        if v >= 2:
            ans *= k
            count += 1
        if count == 2:
            break
    if count < 2:
        print(0)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    k = list(b.keys())
    k.sort(reverse=True)
    ans = 1
    count = 0
    for key in k:
        if b.get(key) >= 2:
            ans *= key
            count += 1
        if count == 2:
            break
    if count < 2:
        print(0)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cnt = Counter(A)
rect = []

for i,j in zip(cnt.keys(),cnt.values()):
    if j >= 2:
        rect.append([i,j])

rect.sort(reverse=True)

ans = 0
flag = True
for i,j in rect:
    if j < 4:
        if ans != 0:
            ans *= i
            flag = False
            break
        ans = i
    else:
        ans = i**2
        flag = False
        break
    
print(0 if flag else ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cnt = Counter(A)
rect = []


for i,j in zip(cnt.keys(),cnt.values()):
    if j >= 2:
        rect.append([i,j])

ans = 0
rect.sort()
for i in reversed(range(len(rect))):
    if rect[i][1] < 4:
        if ans != 0:
            ans *= rect[i][0]
            break
        ans = rect[i][0]
    elif rect[i][1] >= 4:
        ans = rect[i][0]**2
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cnt = Counter(A)
rect = []


for i,j in zip(cnt.keys(),cnt.values()):
    if j >= 2:
        rect.append([i,j])

ans = 0
##print(rect)
for i in reversed(range(len(rect))):
    if rect[i][1] < 4:
        if ans != 0:
            ans *= rect[i][0]
            break
        ans = rect[i][0]
    elif rect[i][1] >= 4:
        ans = rect[i][0]**2
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
List_2=[]
List_4=[]
for i in range(n-1):
  if a[i] != a[i+1] and a.count(a[i])>=2:
    List_2.append(a[i])
  if a[i] != a[i+1] and a.count(a[i])>=4: 
    List_4.append(a[i])
if len(List_4) >0:
  if len(List_2)==1:
    print(List_4[0] **2)
  else:
    print(max([List_4[0] **2,List_2[0]*List_2[1]])) 
elif len(List_2)>=2:
  print(List_2[0]*List_2[1])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
List_2=[]
List_4=[]
for i in range(n-1):
  if a[i] != a[i+1] and a.count(a[i])>=2:
    List_2.append(a[i])
  if a[i] != a[i+1] and a.count(a[i])>=4: 
    List_4.append(a[i])
if len(List_4) >0:
  if len(List_2)==1:
    print(List_4[0] **2)
  else:
    print(max([List_4[0] **2,List_2[0]*List_2[1]])) 
elif len(List_2)>=2:
  print(List_2[0]*List_2[1])
if len(List_2) <= 1:
  print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = list(map(int,input().split()))
List_t = []
List_q = []
List.sort()
for x in range(N-1):
  if List[x]==List[x+1]:
    List_t.append(List[x])
for x in range(N-3):
  if List[x]==List[x+1]==List[x+2]==List[x+3]:
    List_q.append(List[x])

if len(List_q) == 0:
  if len(List_t)<=1:
    print(0)
  else:
    M = sorted(set(List_t))[-1]
    m = sorted(set(List_t))[-2]
    print(M*m)
else:
  M = sorted(set(List_q))[-1]
  print(M**2)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = list(map(int,input().split()))
List_t = []
List_q = []
List.sort()
for x in range(N-1):
  if List[x]==List[x+1]:
    List_t.append(List[x])
for x in range(N-3):
  if List[x]==List[x+1]==List[x+2]==List[x+3]:
    List_q.append(List[x])

if len(List_q) == 0:
  if len(List_t)==0:
    print(0)
  else:
    M = sorted(set(List_t))[-1]
    m = sorted(set(List_t))[-2]
    print(M*m)
else:
  M = sorted(set(List_q))[-1]
  print(M**2)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = list(map(int,input().split()))
List_ans = []
List.sort()
for x in range(N-1):
  if List[x]==List[x+1]:
    List_ans.append(List[x])

if len(List_ans) == 0:
  print(0)  
else:
  M = max(List_ans)
  m = sorted(set(List_ans))[-2]
  print(M*m)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x1=0
x2=0
count=Counter(a)
for i in count:
  if count[i]>=2:
    if x1<=i:
      x2=x1
      x1=i
    if x2 <= i <= x1:
      x2=i
print(x1*x2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x1=0
x2=0
count=Counter(a)
for i in count:
  if count[i]>=2:
    if x1<=i:
      x2=x1
      x1=i
    elif x2<=i:
      x2=i
print(x1*x2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x1=0
x2=0
count=Counter(a)
for i in count:
  if count[i]>=2:
    if x1<=i:
      x2=x1
      x1=i
    if x1>i and x2<=i:
      x2=i
print(x1*x2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x1=0
x2=0
count=Counter(a)
for i in count:
  if count[i]>=2:
    if x1<=i:
      x2=x1
      x1=i
    elif x1>i and x2<=i:
      x2=i
print(x1*x2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N = int(input())
# S = input()
# N, K = map(int, input().split())
A = list(map(int, input().split()))
from collections import Counter

def main():
    cnt = Counter(A).items()
    koho_2 = []
    koho_4 = []
    for k, v in cnt:
        if v >= 4:
            koho_4.append(k)
        elif v >= 2:
            koho_2.append(k)
    ans = [0]
    koho_2 = sorted(koho_2)[::-1]
    koho_4 = sorted(koho_4)[::-1]
    if len(koho_2) >= 2:
        ans.append(koho_2[0] * koho_2[1])
    if len(koho_4) >= 1:
        ans.append(koho_4[0] ** 2)
    print(max(ans))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	t = dict()
	for i in a:
		if t.get(i):
			t[i] += 1
		else:
			t[i] = 1
	a, b = 0, 0
	for k in t:
		if t[k] >= 4:
				a = max(a, t[k])
				b = max(b, t[k])
		elif t[k] >= 2:
			if k > a:
				b = a
				a = k
	print(a*b)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
li2 = [0,0]
li4 = [0]
for key,value in c.items():
    if value>=4:
        li4.append(key)
    elif value>=2:
        li2.append(key)
li2.sort()
li4.sort()
ans1 = li2[-1]*li2[-2]
ans2 = li4[-1]**2
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
li2 = [0,0]
li4 = [0]
for key,value in c.items():
    if value>=4:
        li4.append(key)
    elif value>=2:
        li2.append(key)
ans1 = li2[-1]*li2[-2]
ans2 = li4[-1]**2
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
p = list((map(int,input().split())))
x = collections.Counter(p)
y = [i[0] for i in x.items() if i[1]>=2]
z = [i[0] for i in x.items() if i[1]>=4]
y.sort(reverse=True)
y.append(0)
y.append(0)
z.append(0)
ans = y[0]*y[1]
ans1 = z[0]*z[0]
if ans1 > ans:
    ans =ans1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
p = list((map(int,input().split())))
x = collections.Counter(p)
y = [i[0] for i in x.items() if i[1]>=2]
y.sort(reverse=True)
y.append(0)
y.append(0)
ans = y[0]*y[1]
print(ans)

Submission status: Wrong Answer

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

mp = {}
for i in A:
    if i in mp:
        mp[i]+=1
    else:
        mp[i]=1

mp_sorted = sorted(mp.items(), key=lambda x: -x[0])
# print(mp_sorted)

x = 0
for k,v in mp_sorted:
    if v<2:
        continue;
    elif v>=4:
        print(k*k)
        exit()
    else:
        if x == 0:
            x=k
        else:
            print(k*x)
            exit()
else:
    print(0)

Submission status: Wrong Answer

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

mp = {}
for i in A:
    if i in mp:
        mp[i]+=1
    else:
        mp[i]=1

mp_sorted = sorted(mp.items(), key=lambda x: -x[0])
# print(mp_sorted)

x = 0
for k,v in mp_sorted:
    if v<2:
        continue;
    elif v>=4:
        print(k*k)
        exit()
    else:
        if x == 0:
            x=k
        else:
            print(k*x)
            exit()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    edge = defaultdict(int)

    for i in range(N):
        edge[A[i]] += 1

    edge = [ [k, v] for k, v in edge.items() if v >= 2 ]
    edge.sort(key = lambda x : x[0])

    if len(edge) >= 2 :
        print(max(edge[-1][0]*edge[-2][0], edge[-1][0]**2))

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    edge = defaultdict(int)

    for i in range(N):
        edge[A[i]] += 1
    edge = [ [k, v] for k, v in edge.items() if v >= 2 ]
    edge.sort(key = lambda x : x[0])

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    edge = defaultdict(int)

    for i in range(N):
        edge[A[i]] += 1
    edge = [ [k, v] for k, v in edge.items() if v >= 2 ]
    print(edge)
    edge.sort(key = lambda x : x[0])
    print(edge)

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    edge = defaultdict(int)

    for i in range(N):
        edge[A[i]] += 1
    edge = [ (k, v) for k, v in edge.items() if v >= 2 ]
    edge.sort(key = lambda x : x[0])

    if len(edge) >= 2:
        v1 = edge[-1]
        v2 = edge[-2]
        print(v1[0]*v2[0])
    elif len(edge) == 1:
        v1 = edge[-1]
        if v1[1] >= 4:
            print(v1[0]**2)
        else:
            print(0)
    else:
        print(0)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    edge = defaultdict(int)

    for i in range(N):
        edge[A[i]] += 1
    edge = [ (k, v) for k, v in edge.items() if v >= 2 ]
    edge.sort(key = lambda x : x[0])

    if len(edge) >= 2:
        v1 = edge[-1]
        v2 = edge[-2]
        print(v1[0]*v2[0])
    else:
        print(0)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
def slove(n, a):

    count = collections.Counter()
    a_list = [int(i) for i in a.split()]
    for i in a_list:
        count[i] += 1

    tmp = sorted([item for item in count.items() if item[1] >= 2])

    if len(tmp) == 0:
        return 0
    else:
        x = tmp.pop()[0]
        y = tmp.pop()[0]
        return x * y

if __name__ == "__main__":
    n = int(input())
    a_list = input()
    print(slove(n, a_list))

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    ac = Counter(a)
    acl = [i for i in ac if ac[i] >= 2]

    if len(acl) == 0:
        print(0)
    elif ac[acl[0]] >= 4:
        print(int(acl[0] * acl[0]))
    elif len(acl) <= 1:
        print(0)
    else:
        print(int(acl[0]*acl[1]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    ac = Counter(a)
    acl = [i for i in ac if ac[i] >= 2]

    if len(acl) == 0:
        print(0)
    elif ac[acl[0]] >= 4:
        print(int(acl[0] ** 2))
    elif len(acl) <= 1:
        print(0)
    else:
        print(int(acl[0]*acl[1]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
adic = {}
for i in range(n):
    if a[i] not in adic:
        adic[a[i]] = 0
    adic[a[i]] += 1
a_item = list(adic.items())

cnt2 = []
cnt4 = []
for i in range(len(a_item)):
    if 2 <= a_item[i][1] <= 3:
        cnt2.append(a_item[i][0])
    if 4 <= a_item[i][1]:
        cnt4.append(a_item[i][0])

ans = 0
if len(cnt2) <= 1 and len(cnt4) <= 0:
    print(0)
else:
    if len(cnt2) >= 2:
        ans = max(ans, cnt2[-1]*cnt2[-2])
    if cnt4:
        ans = max(ans, cnt4[-1]**2)
    
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
adic = {}
for i in range(n):
    if a[i] not in adic:
        adic[a[i]] = 0
    adic[a[i]] += 1
a_item = list(adic.items())
print(a_item)
cnt2 = []
cnt4 = []
for i in range(len(a_item)):
    if 2 <= a_item[i][1] <= 3:
        cnt2.append(a_item[i][0])
    if 4 <= a_item[i][1]:
        cnt4.append(a_item[i][0])

ans = 0
if len(cnt2) <= 1 and not(cnt4):
    print(0)
else:
    if len(cnt2) >= 2:
        ans = max(ans, cnt2[-1]*cnt2[-2])
    if cnt4:
        ans = max(ans, cnt4[-1]**2)
    
    print(ans)

Submission status: Wrong Answer

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


cnt2 = []
cnt4 = []
for i in range(len(a)):
    if 2 <= a[i][1] <= 3:
        cnt2.append(a[i][0])
    if a[i][1] >= 4:
        cnt4.append(a[i][0])
    '''
    cnts[a[i]] += 1
    if cnts[a[i]] == 2:
        cnt2.append(a[i])
    if cnts[a[i]] == 4:
        cnt2.remove(a[i])
        cnt4.append(a[i])
        '''
ans = 0
if len(cnt2) <= 1 and not(cnt4):
    print(0)
else:
    if len(cnt2) >= 2:
        ans = max(ans, cnt2[-1]*cnt2[-2])
    if cnt4:
        ans = max(ans, cnt4[-1]**2)
    
    print(ans)