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:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)# ()にカウンターの対象のリストの変数名
    cl=list(c.items())
    cl.sort(key=lambda x:x[0],reverse=True)
    tyou=0
    tan=0
    for key,value in cl:
        if value==4:
            tyou=key
            tan=key
            break
        elif value>=2:
            if tyou==0:
                tyou=key
            else:
                tan=key
                break
    print(tyou*tan)
resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter
_, *lst = map(int, open(0).read().split())
stick = [i for i, j in Counter(lst).items() if j > 1]
if len(stick) > 1:
  stick.sort()
  print(stick[-1] * stick[-2])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
_, *lst = map(int, input().split())
stick = [i for i, j in Counter(lst).items() if j > 1]
if len(stick) > 1:
  stick.sort()
  print(stick[-1] * stick[-2])
else:
  print(0)

Submission status: Wrong Answer

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

import collections
C=collections.Counter(A).most_common()
D=[0]+[0]+sorted(a for a,b in C if b>=2)
print(D[-1]*D[-2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c = collections.Counter(a)
g = []
for i in range(len(b)):
    if c[b[i]] >= 2:
        g.append(b[i])
if len(g) <=1:
    print(0)
else:
    g = sorted(g,reverse = True)
    print(g[0]*g[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
m=[]
for key,value in A.items():
    if value>=2:
        m.append(key)
print(sorted(m)[-1]**2 if len(m)>=4 else sorted(m)[-1]*sorted(m)[-2] if len(m)>=2 else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
m=[]
for key,value in A.items():
    if value>=2:
        m.append(key)
print(sorted(m)[-1]*sorted(m)[-2] if len(m)>=2 else 0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a,reverse=True)
c=set(b)
d=sorted([i for i in c],reverse=True)
flag1=False
flag2=False
for i in d:
    if b.count(i)>=4:
        print(i**2)
        break
        exit()
    elif flag1==False and flag2==False and b.count(i)>=2:
        tmp1=i
        flag1=True
    elif flag1 and flag2==False and b.count(i)>=2:
        tmp2=i
        print(tmp1*tmp2)
        break
        exit()
if  flag2==False:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a,reverse=True)
c=set(b)
d=sorted([i for i in c],reverse=True)
flag1=False
flag2=False
for i in d:
    if b.count(i)>=4:
        print(i**2)
        break
        exit()
    elif flag1==False and flag2==False and b.count(i)>=2:
        tmp1=i
        flag1=True
    elif flag1 and flag2==False and b.count(i)>=2:
        tmp2=i
        print(tmp1*tmp2)
        break
        exit()
if flag1==False and flag2==False:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
A.sort()
teihen,takasa = 0,0
check = 0
A = Counter(A)

for i,j in A.items():
  if j >= 2:
    if check == 0:
      teihen = i
      check = 1
    else:
      takasa = i
      check = 0
  if j >= 4:
    teihen,takasa = i,i

print(teihen * takasa)

Submission status: Wrong Answer

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

for i,j in A.items():
  if j >= 2:
    if check == 0:
      teihen = i
      check = 1
    else:
      takasa = i
      check = 0
  if j >= 4:
    teihen,takasa = i,i

print(teihen * takasa)

Submission status: Wrong Answer

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

for i,j in A.items():
  if j >= 2:
    if check == 0:
      teihen = i
      check = 1
    else:
      takasa = i
      check = 0
  elif j >= 4:
    teihen,takasa = i,i

print(teihen * takasa)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split()))
count = {}
for a in L:
    if a not in count:
        count[a] = 1
    else:
        count[a] += 1
leng = sorted(set(count), reverse=True)
flag = 0
for i in leng:
    if count[i] >= 4:
        if flag == 0:
            print(i * 2)
            break
        else:
            print(l * i)
            break
    elif count[i] >= 2:
        if flag == 0:
            l = i
            flag = 1
        else:
            print(l * i)
            break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split()))
A = sorted(set(L), reverse=True)
flag = 0
for a in A:
    if L.count(a) >= 4:
        if flag == 0:
            print(a * 2)
            break
        else:
            print(l * a)
            break
    elif L.count(a) >= 2:
        if flag == 0:
            l = a
            flag = 1
        else:
            print(l * a)
            break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
import collections
c=collections.Counter(a)
values,counts=zip(*c.most_common())
lv=list(values)
lc=list(counts)
temp=[]
for i in range(0,len(lc)):
  if lc[i]>=2:
    temp.append(lv[i])
temp.sort(reverse=True)
if len(temp)>=2:
  ans=temp[0]*temp[1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
import collections
c=collections.Counter(a)
values,counts=zip(*c.most_common())
lv=list(values)
lc=list(counts)
temp=[]
for i in range(0,len(lc)):
  if lc[i]>=2:
    temp.append(lv[i])
temp.sort()
if len(temp)>=2:
  ans=temp[0]*temp[1]
print(ans)

Submission status: Wrong Answer

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

d = dict()
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

M = 0
N = 0
for x in d.items():
    if x[1] >= 2 and x[0] > M:
        N = M
        M = x[0]
    elif x[1] >= 2 and x[0] > N:
        N = x[0]

print(M*N)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n  = int(input())
#  = map(int, input().split())
l  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
c = collections.Counter(l)

cmc = c.most_common()

if cmc[0][1] == 1 or len(cmc) == 1:
    print(0)
else:
    cmc_ = [k for k, v in cmc if v >= 2]
    cmc_ = sorted(cmc_)[::-1]
    print(cmc_[0] * cmc_[1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
A = list(map(int, input().split()))

T = collections.Counter(A)

hen1 = 0 # 小さい
hen2 = 0 # 大きい
for h, c in T.items():
    if c >= 4:
        hen1 = h
        hen2 = h
    elif c >= 2:
        if hen1 >= hen2:
            hen2 = h
        else:
            hen1 = h
print(hen1*hen2)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
A=list(map(int,input().split()))
a=collections.Counter(A)
firstnum=0
secondnum=0
firstl=0
secondl=0
values,counts=zip(*a.most_common())
if len(values)==1 and counts[0]>=4:
  print(values[0]**2)
else:
  for i,j in a.items():
    if i>=firstl and j>=2:
      secondnum=firstnum
      firstnum=j
      secondl=firstl
      firstl=i
    elif secondl<=i<firstl and j>=2:
      secondnum=j
      secondl=i
  print(firstl*secondl)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
A=list(map(int,input().split()))
a=collections.Counter(A)
firstnum=0
secondnum=0
firstl=0
secondl=0
for i,j in a.items():
  if i>=firstl and j>=2:
    secondnum=firstnum
    firstnum=j
    secondl=firstl
    firstl=i
  elif secondl<=i<firstl and j>=2:
    secondnum=j
    secondl=i
print(firstl*secondl)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
A=list(map(int,input().split()))
a=collections.Counter(A)
firstnum=0
secondnum=0
firstl=0
secondl=0
for i,j in a.items():
  if i>=firstl and j%2>=0:
    secondnum=firstnum
    firstnum=j
    secondl=firstl
    firstl=i
  elif secondl<=i<firstl and j%2>=0:
    secondnum=j
    secondl=i
print(firstl*secondl)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))[::-1]
ans=[]
for i in range(n-1):
  if l[i]==l[i+1]:
    ans.append(l[i])
ans=sorted(list(set(ans)))
if len(ans)<2:
  print(0)
else:
  print(ans[-1]*ans[-2])

Submission status: Wrong Answer

Solution code:
# C - Make a Rectangle
# https://atcoder.jp/contests/arc081/tasks/arc081_a

from collections import Counter

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

C = sorted(list(Counter(A).items()), key=lambda x: -x[0])

print(C)

ans = 0
for k, v in C:
  if v >= 4:
    if ans == 0:
      print(k ** 2)
    else:
      print(ans * k)
    exit()
  else:
    if v >= 2:
      if ans == 0:
        ans = k
      else:
        print(ans * k)
        exit()

print(0)

Submission status: Wrong Answer

Solution code:
# C - Make a Rectangle
# https://atcoder.jp/contests/arc081/tasks/arc081_a

from collections import Counter

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

C = sorted(list(Counter(A).items()), reverse=True)

ans = 0
for k, v in C:
  if v >= 4:
    print(k ** 2)
    exit()
  else:
    if v >= 2:
      if ans == 0:
        ans = k
      else:
        print(ans * k)
        exit()

print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
x={}
edge=[0]*2
for i in a:
  if i in x:
    if x[i]==1:
      edge.append(i)
      x[i]=0
  else:
    x[i]=1
edge.sort(reverse=True)
print(edge[0]*edge[1])

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
import collections
n = ii()
A = iil()
d = collections.Counter(A)
fst = 0
sec = 0
for k,v in d.items():
    if v == 1:
        continue
    else:
        if k > fst:
            sec = fst
            fst = k
        elif k > sec:
            sec = k
print(fst*sec)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
cnt = sorted(cnt.items(), key = lambda x: x[0], reverse = True)
#cnt = sorted(cnt ,key = lambda x: x[1], reverse = True)

c = []
for i in range(len(cnt)):
    if cnt[i][1] == 2 or cnt[i][1] == 3:
        c.append(cnt[i][0])
    elif cnt[i][1] == 4:
        c.append(cnt[i][0])
        c.append(cnt[i][0])

c = sorted(c, reverse = True)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
cnt = sorted(cnt.items(), key = lambda x: x[0], reverse = True)
#cnt = sorted(cnt ,key = lambda x: x[1], reverse = True)

c = []
for i in range(len(cnt)):
    if cnt[i][1] == 2 or cnt[i][1] == 3:
        c.append(cnt[i][0])
    elif cnt[i][1] == 4:
        c.append(cnt[i][0])
        c.append(cnt[i][0])

c = sorted(c, reverse = True)

if len(c) >= 2:
    print(c[0] * c[1])
    exit()
else:
    print("0")
    exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
cnt = sorted(cnt.items(), key = lambda x: x[0], reverse = True)
#cnt = sorted(cnt ,key = lambda x: x[1], reverse = True)

c = []
for i in range(len(cnt)):
    if cnt[i][1] == 2 or cnt[i][1] == 3: 
        c.append(cnt[i][0])
    elif cnt[i][1] == 4:
        c.append(cnt[i][0])
        c.append(cnt[i][0])

    if len(c) >= 2:
        print(c[0] * c[1])
        exit()

print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=list(map(int ,input().split()))
D=Counter(A)
#print(D.items())
L=[]
for num, v in D.items():
    if v>=4:
        L.append((num,4))
    elif v>=2:
        L.append((num, 2))

L=sorted(L, reverse=True)
if len(L)==0:
    print(0)
    exit()
elif len(L)==1 and L[0][1]==2:
    print(0)
    exit()
ans=1
for i,t in enumerate(L):
    num,v=t
    if i==0:
        if v==4:
            ans=num*num
            break
        else:
            ans*=num
    elif i==1:
        ans+=num
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=list(map(int ,input().split()))
D=Counter(A)
#print(D.items())
L=[]
for num, v in D.items():
    if v>=4:
        L.append((num,4))
    elif v>=2:
        L.append((num, 2))

L=sorted(L, reverse=True)
if len(L)==0:
    print(0)
    exit()
elif len(L)==1 and L[0][1]==2:
    print(0)
    exit()
ans=0
for i,t in enumerate(L):
    num,v=t
    if v==4:
        ans=num*num
        break
    else:
        if ans==0:
            ans=1
        ans*=num
    if i==1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=list(map(int ,input().split()))
D=Counter(A)
#print(D.items())
L=[]
for num, v in D.items():
    if v>=4:
        L.append((num,4))
    elif v>=2:
        L.append((num, 2))

L=sorted(L, reverse=True)
ans=0
for i,t in enumerate(L):
    num,v=t
    if v==4:
        ans=num*num
        break
    else:
        if ans==0:
            ans=1
        ans*=num
    if i==1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


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

        A = Counter(A)
        d = sorted(A.items(), reverse=True)
        cnt = 0
        temp = 0
        for (k, v) in d:
            if 2 <= v < 4:
                cnt += 2
            if 4 <= v:
                cnt += 4
                temp = k

            if cnt >= 4:
                return k*temp
            else:
                temp = k
        return 0
    print(main())


resolve()

Submission status: Wrong Answer

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

a_set = list(set(a_list))
c = Counter(a_list)

if len(a_set) > n-2:
    print(0)
    exit()
else:
    a_list.sort(reverse=True)
    a_set.sort(reverse=True)
    candidate = []
    for i in a_set:
        cnt = c[i]
        
        if 2 <= cnt <= 3:
            candidate.append(i)
        elif cnt >= 4:
            candidate.append(i)
            candidate.append(i)
        if len(candidate) == 2:
            print(candidate[0] * candidate[1])
            exit()

Submission status: Wrong Answer

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

a_set = list(set(a_list))

if len(a_set) > n-2:
    print(0)
    exit()
else:
    a_list.sort(reverse=True)
    a_set.sort(reverse=True)
    candidate = []
    for i in a_set:
        cnt = 0
        for j in range(len(a_list)):
            if a_list[j] == i:
                cnt += 1
            else:
                break
        a_list = a_list[j:]
        if 2 <= cnt <= 3:
            candidate.append(i)
        elif cnt >= 4:
            candidate.append(i)
            candidate.append(i)
        if len(candidate) == 2:
            print(candidate[0] * candidate[1])
            exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)

hen = []

for i,j in zip(c.keys(),c.values()):
    if 2 <= j <= 3:
        hen.append([i,2])
    elif j >= 4:
        hen.append([i,4])


hen.sort(reverse=True)

##print(hen)
ans = 0
finished = False
choosen = False

for i,j in hen:
    if j == 2:
        if choosen:
            ans *= i
            finished = True
            break
        else:
            ans = i
            choosen = True
    else:
        if choosen:
            ans += i
            finished = True
            break
        else:
            ans = i**2
            finished = True
            break

print(ans if finished else 0)

Submission status: Wrong Answer

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

a_set = list(set(a_list))
if len(a_set) > n-2:
    print(0)
    exit()
else:
    a_set.sort(reverse=True)
    candidate = []
    for i in a_set:
        cnt = 0
        for j in range(len(a_list)):
            if a_list[j] == i:
                cnt += 1
            else:
                break
        a_list = a_list[j:]
        if cnt >= 2:
            candidate.append(i)
            if len(candidate) == 2:
                print(candidate[0] * candidate[1])
                exit()
        else:
            continue

Submission status: Wrong Answer

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

a_set = list(set(a_list))
if len(a_set) > n-2:
    print(0)
    exit()
else:
    a_set.sort(reverse=True)
    candidate = []
    for i in a_set:
        if a_list.count(i) >= 2:
            candidate.append(i)
        if len(candidate) == 2:
            print(candidate[0] * candidate[1])
            exit()

Submission status: Wrong Answer

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

a_set = list(set(a_list))
a_set.sort(reverse=True)
candidate = []
for i in a_set:
    if a_list.count(i) >= 2:
        candidate.append(i)
    if len(candidate) == 2:
        print(candidate[0] * candidate[1])
        exit()
print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# import bisect
# 
from collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

        AA=Counter(A)
        # from collections import OrderedDict
        #d = OrderedDict(sorted(AA.items(), key=lambda x: x[0],reverse=True))
        d=sorted(AA.items(),reverse=True)
        cnt=0
        temp=0
        for (k,v) in d:
            if 2<=v<4:
                cnt+=2
            if 4<=v:
                cnt+=4
                temp=v

            if cnt>=4:
                return k*temp
            else: temp=k
        return 0
    print(main())



    
resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)

hen = []

for i,j in zip(c.keys(),c.values()):
    if 2 <= j <= 3:
        hen.append([i,2])
    elif j >= 4:
        hen.append([i,4])


hen.sort(reverse=True)


ans = 0
finished = False
choosen = False

for i,j in hen:
    if j == 2:
        if not choosen:
            ans = i
            choosen = True
        else:
            ans *= i
            finished = True
            break
    else:
        if not choosen:
            ans = i**2
            finished = True
            break
        else:
            ans *= i
            finised = True
            break

print(ans if finished else 0)

Submission status: Wrong Answer

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

cnt = {}
for i, Ai in enumerate(A):
    key = str(Ai)
    cnt.setdefault(key, 0)
    cnt[key] += 1

keys = sorted(cnt.keys())[::-1]

a = b = 0
for key in keys:
    # print("#", key, cnt[key])
    if cnt[key] >= 2:
        cnt[key] -= 2
        a = max(a, int(key))
        break
    
for key in keys:
    # print("#", key, cnt[key])
    if cnt[key] >= 2:
        cnt[key] -= 2
        b = max(b, int(key))
        break

print(a * b)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
ans = []
N = 0
b = ""
for i in a:
  if b == "":
    b = i
    N += 1
  elif b == i:
    N += 1
  else:
    if N >= 4:
      print(b**2)
      exit()
    elif N >= 2:
      ans.append(b)
    b,N = i, 1
  if len(ans) == 2: break
if N >= 2: ans.append(b)
print(ans[0]*ans[1] if ans else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a_c = sorted(Counter(a_input).items(),key=lambda x:x[0],reverse=True)

max_len=0
next_len=0
ans=0
for a in a_c:
    if a[1]<2:
        continue
    max_len = max(max_len,a[0])
    if a[1]>=4:
        ans = a[0]**2
    if max_len>a[0]:
        next_len = max(next_len,a[0])
print(max(ans,max_len*next_len))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)

hen = []

for i,j in zip(c.keys(),c.values()):
    hen.append([i,j])

hen.sort(reverse=True)


used = 0
ans = []

for i,j in hen:
    if j < 2:
        continue
    elif 2 <= j < 4:
        used += 2
        ans.append(i)
        if used >= 4:
            break
    else:
        if used != 0:
            ans.append(i)
            break
        else:
            ans.append([i,i])
            break
try:
    print(ans[1]*ans[0])
except:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Ac = sorted([i for i in c.keys() if c[i] >= 2])

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

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(A)
max_1 = 0
max_2 = 0
for k, v in c.items():
    if v >= 2:
        if k > max_1:
            max_1, max_2 = k, max_1
        elif k > max_2:
            max_2 = k

print(max_1*max_2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Ac = sorted([i for i in c.keys() if c[i] >= 2])

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

Ac = [i for i in c.keys() if c[i] >= 2]

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Ac = sorted([i for i in Counter(A).keys() if Counter(A)[i] >= 2])[::-1]

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

Submission status: Wrong Answer

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

cnt = {}
for i, Ai in enumerate(A):
    key = str(Ai)
    cnt.setdefault(key, 0)
    cnt[key] += 1
    
cnt['0'] = 4

keys = list(reversed(sorted(cnt.keys())))

for key_a in keys:
    # print("#", key_a, cnt[key_a])
    if cnt[key_a] >= 2:
        cnt[key_a] -= 2
        break
    
for key_b in keys:
    # print("#", key_b, cnt[key_b])
    if cnt[key_b] >= 2:
        cnt[key_b] -= 2
        break

print(int(key_a) * int(key_b))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
    dic[A[i]] += 1
rec = False
ans = 0
for k,v in dic.items():
    #print(k,v)
    if v // 2 >= 1 and not rec:
        if v//4 >= 1:
            ans = k**2
            break
        else:
            po = k
            rec = True
    elif rec:
        if v // 2 >=1:
            ans = po * k
            break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    l = Counter(a)
    sq = []
    for i,j in l.items():
        if j >= 2:
            sq.append(i)

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

print(solve())

Submission status: Wrong Answer

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

# Counterを大きい順に
C = sorted(Counter(A).items(), reverse = True)

edge = []
for k,v in C:
    if len(edge) >=2:
        break
    if v >= 2:
        edge.append(k)
if len(edge) <= 1:
    print(0)
    exit()
print(edge[0] * edge[1])

Submission status: Wrong Answer

Solution code:
import collections
A=int(input())
l_after=[]
l=list(map(int,input().split()))
l=collections.Counter(l).most_common()
for i in range(len(l)):
   if l[i][1] > 1:
      l_after.append(l[i][0])
l_after.sort(reverse=True)
if len(l_after) < 2:
   print(0)
   exit()
print(l_after[0]*l_after[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(reversed(sorted(a)))
l = []
for i in range(n):
    if i <= n - 3 and len(set(a[i:i + 4])) == 1:
        l.append(a[i])
        l.append(a[i])
        i += 3
    elif i <= n - 2 and len(set(a[i:i + 3])) == 1:
        l.append(a[i])
        i += 2
    elif i <= n - 1 and len(set(a[i:i + 2])) == 1:
        l.append(a[i])
        i += 1
l = list(reversed(sorted(l)))
try:
    print(l[0] * l[2])
except:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
import collections

n = int(input())
a = collections.Counter(list(map(int, sys.stdin.readline().split())))

q = [0, 0]
for i in a:
    if a[i] >= 4:
        q = [i, i]
    elif a[i] >= 2:
        q[0] = i
        q.sort()

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

Submission status: Wrong Answer

Solution code:
import sys
import collections

n = int(input())
a = collections.Counter(list(map(int, sys.stdin.readline().split())))

q = [0, 0]
for i in a:
    if a[i] >= 4:
        q.append(i)
    if a[i] >= 2:
        q.append(i)

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

Submission status: Wrong Answer

Solution code:
import sys
import collections

n = int(input())
a = collections.Counter(list(map(int, sys.stdin.readline().split())))

f, t= [], []
for i in a:
    if a[i] >= 4:
        f.append(i)
    if a[i] >= 2:
        t.append(i)
fa, ta = 0, 0
if len(f) >= 1:
    fa = f[-1]**2
if len(t) >= 2:
    ta = t[-1]*t[-2]
print(max(ta, fa))

Submission status: Wrong Answer

Solution code:
import sys
import collections

n = int(input())
a = collections.Counter(list(map(int, sys.stdin.readline().split())))
chk = []
for i in a:
    if a[i] >= 2:
        chk.append([i, a[i]])
if len(chk) < 1:
    print(0)
else:
    if chk[-1][1] >= 4:
        print(chk[-1][0]*chk[-1][0])
        exit()
    print(chk[-1][0]*chk[-2][0])

Submission status: Wrong Answer

Solution code:
import sys
import collections

n = int(input())
a = collections.Counter(list(map(int, sys.stdin.readline().split())))
chk = []
for i in a:
    if a[i] >= 2:
        chk.append([i, a[i]])
if len(chk) < 1:
    print(0)
else:
    if chk[0][1] >= 4:
        print(chk[-1][0]*chk[-1][0])
        exit()
    print(chk[-1][0]*chk[-2][0])

Submission status: Wrong Answer

Solution code:
import sys
import collections

n = int(input())
a = collections.Counter(list(map(int, sys.stdin.readline().split())))
chk = []

for i in a:
    if a[i] >= 2:
        chk.append([i, a[i]])

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

Submission status: Wrong Answer

Solution code:
import sys
import collections

n = int(input())
a = collections.Counter(list(map(int, sys.stdin.readline().split())))
chk = []
for i in a:
    if a[i] >= 2:
        chk.append(i)
chk.sort(reverse=True)
if len(chk) >= 2:
    print(chk[0]*chk[1])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

p = []
l = []
for k, v in A.items():
    if v >= 4:
        p.append(k)
    if v >= 2:
        l.append(k)

ans = 0
if len(p) >= 1:
    p.sort()
    ans = l[-1]**2
if len(l) >= 2:
    l.sort()
    ans = max(l[-1] * l[-2], ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

l = []

for k, v in A.items():
    if v >= 2:
        l.append(k)

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