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:
#!/usr/bin/env python
# coding: utf-8

# In[35]:


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


# In[36]:


A_sorted = sorted(set(A), reverse=True)
mylist = []
s1 = 0
s2 = 0
for a in A_sorted:
    cnt = A.count(a)
    if cnt >= 4:
        s1 = a*a
    elif cnt >= 2:
        mylist.append(a)
    if len(mylist) == 2:
        s2 = mylist[0]*mylist[1]
        print(max(s1,s2))
        break
else:
    print(0)


# In[ ]:

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()

d = Counter(readChars())

d = [i for i in sorted(d.items(), reverse=True) if i[1]>=2]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()
if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()

#d = Counter(readInts())
d = defaultdict(int)
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>=2]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()
if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>=2]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()
if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))
	if int(d[0][0])*int(d[1][0])==0:
		raise Exception

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>1]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()

if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>1]

try:
	if d[0][1]>=4:
		print(int(d[0][0])**2)
	else:
		print(int(d[0][0])*int(d[1][0]))
	exit()
except:
	print(0)

print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>1]

try:
	if d[0][1]>=4:
		print(int(d[0][0])**2)
	else:
		print(int(d[0][0])*int(d[1][0]))
except:
	print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>1]

try:
	if d[0][1]>=4:
		print(int(d[0][0])*2)
	else:
		print(int(d[0][0])*int(d[1][0]))
except:
	print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = collections.Counter(list(map(int,input().split())))
p = sorted([i for i in a.items() if i[1]>=2])
if len(p)<2:
    print(0)
else:
    print(p[-1][0]*p[-2][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

acnt = Counter(A)

b = [k for k, v in acnt.items() if v >= 2]

if len(b) < 2:
    print(0)
else:
    b.sort()
    print(b[-1]*b[-2])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())
A = map(int, input().split())
C = defaultdict(int)
for a in A:
    C[a] += 1
C = sorted(C.items(), key=lambda x: x[1])
rods = []
for k, v in C:
    if v >= 4:
        rods.append(k)
        rods.append(k)
        break
    if v >= 2:
        rods.append(k)
    if len(rods) == 2:
        break
if len(rods) >= 2:
    ans = rods[0]*rods[1]
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = Counter(list(map(int, input().split())))
A = sorted(A.most_common(), reverse=True)
rods = []
for a in A:
    if a[1] >= 4:
        rods.append(a[0])
        rods.append(a[0])
        break
    if a[1] >= 2:
        rods.append(a[0])
    if len(rods) == 2:
        break
if len(rods) == 2:
    ans = rods[0]*rods[1]
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = Counter(list(map(int, input().split())))
A = sorted(A.most_common(), reverse=True)
rods = []
for a in A:
    if a[1] >= 2:
        rods.append(a[0])
    if len(rods) == 2:
        break
if len(rods) == 2:
    ans = rods[0]*rods[1]
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

from collections import Counter
c = Counter(As)

area = 0
for n, c in sorted(c.most_common())[::-1]:
    if c<2:
        break
    elif c>=4:
        area = max(area*n, n**2)
        break
    else:
        if area:
            area = area*n
            break
        else:
            area = n

print(area)

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = list(IL())
    sa = set(a)
    stick = []
    for rep in sa:
        if 2<=a.count(rep): stick.append(rep)
    if len(stick)<2:  print(0)
    else:
        stick.sort()
        print(stick[-1]*stick[-2])
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

Solution code:
import math
import collections
import fractions
import itertools

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    box = []
    for i in c:
        if c[i] >= 2:
            box.append(i)
    if len(box) < 2:
        print(0)
    else:
        box.sort(reverse=True)
        print(box[0]*box[1])
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
b.reverse()
c=[]
for i in b:
  if a.count(i)>=4:
    c+=[i]
    c+=[i]
    break
  elif a.count(i)>=2:
    c+=[i]
    if len(c)>=2:
      break
if len(c)>=2:
  print(c[0]*c[1])  
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
b.reverse()
c=[]
for i in b:
  if a.count(i)>=4:
    print(i**2)
  elif a.count(i)>=2:
    c+=[i]
    if len(c)==2:
      print(c[0]*c[1])
      break

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
b=reversed(b)
c=[]
for i in b:
  if a.count(i)>=2:
    c+=[i]
    if len(c)==2:
      break
if len(c)<=1:
  print(0)
else:
  print(c[0]*c[1])

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

a = collections.Counter(list(map(int,input().split())))
#a = sorted(a.items(), key=lambda x: -x[0],reverse=True)
#for k, v in sorted(a.items(), key=lambda x: -x[0]):pass
a = sorted(a.items(), key=lambda x:x[0],reverse=True)

#print(a)

cnt = 0
num = []
n = 0
for i,v in a:
    if 4 <= v:
        n = max(n,(i*i))
    elif 2 <= v:
        num.append(i)
        cnt += 1
    if 2 == cnt:
        break
if cnt == 2:
    print(max(num[0]*num[1],n))
else:
    print(n)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

a = collections.Counter(list(map(int,input().split())))
#a = sorted(a.items(), key=lambda x: -x[0],reverse=True)
#for k, v in sorted(a.items(), key=lambda x: -x[0]):pass
a = sorted(a.items(), key=lambda x:x[0],reverse=True)

#print(a)

cnt = 0
num = []
n = 0
for i,v in a:
    if 4 <= v:
        n = max(n,(i*i))
    elif 2 <= v:
        num.append(i)
        cnt += 1
    if 2 == cnt:
        break
if cnt == 2:
    print(max(num[0]*num[1],n))
elif 0 < n:
    print(n)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

a = collections.Counter(list(map(int,input().split())))
#a = sorted(a.items(), key=lambda x: -x[0],reverse=True)
#for k, v in sorted(a.items(), key=lambda x: -x[0]):pass
a = sorted(a.items(), key=lambda x:x[0],reverse=True)

#print(a)

cnt = 0
num = []
n = 0
for i,v in a:
    if 4 <= v:
        n = max(n,(i*i))
    elif 2 <= v:
        num.append(i)
        cnt += 1
    if 2 == cnt:
        break
if cnt == 2:
    print(max(num[0]*num[1],n))
elif 0 < n:
    print(num)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

a = collections.Counter(list(map(int,input().split())))
#a = sorted(a.items(), key=lambda x: -x[0],reverse=True)
#for k, v in sorted(a.items(), key=lambda x: -x[0]):pass
a = sorted(a.items(), key=lambda x:x[0],reverse=True)

#print(a)

cnt = 0
num = []
n = 0
for i,v in a:
    if 4 <= v:
        n = max(n,(i*i))
    elif 2 <= v:
        num.append(i)
        cnt += 1
    if 2 == cnt:
        break

if cnt == 2:
    print(max(num[0]*num[1],n))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

a = collections.Counter(list(map(int,input().split())))
#a = sorted(a.items(), key=lambda x: -x[0],reverse=True)
#for k, v in sorted(a.items(), key=lambda x: -x[0]):pass
a = sorted(a.items(), key=lambda x:x[0],reverse=True)

#print(a)

cnt = 0
num = []
for i,v in a:
    if 4 <= v:
        print(i*i)
        exit()
    elif 2 <= v:
        num.append(i)
        cnt += 1
    if 2 == cnt:
        break

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

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

a = collections.Counter(list(map(int,input().split())))
#a = sorted(a.items(), key=lambda x: -x[0],reverse=True)
#for k, v in sorted(a.items(), key=lambda x: -x[0]):pass
a = sorted(a.items(), key=lambda x:x[0],reverse=True)

#print(a)

cnt = 0
num = []
for i,v in a:
    if 4 <= v:
        print(v*v)
        exit()
    elif 2 <= v:
        num.append(i)
        cnt += 1
    if 2 == cnt:
        break

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc081/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))

# まずは使える辺の長さを抽出
from collections import Counter
A_cnt = Counter(A)
candi = {k for k, v in A_cnt.items() if v > 1}
if len(candi) < 2:
    print(0)
    exit()
A_ls = sorted(candi, reverse=True)
print(A_ls[0] * A_ls[1])

Submission status: Wrong Answer

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

A.sort()

A_set = list(set(A))
dic = {}

for i in range(len(A_set)):
    dic.setdefault(A_set[i],0)

for i in range(len(A)):
    dic[A[i]] += 1

ans = []

for k, v in dic.items():
    if v >= 4:
        ans = []
        for _ in range(2):
            ans.append(k)
    elif v >= 2:
        if len(ans) == 2:
            del ans[0]
        ans.append(k)

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

Submission status: Wrong Answer

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

A.sort()

A_set = list(set(A))
dic = {}

for i in range(len(A_set)):
    dic.setdefault(A_set[i],0)

for i in range(len(A)):
    dic[A[i]] += 1

ans = []

for k, v in dic.items():
    if v >= 4:
        ans = []
        for _ in range(2):
            ans.append(k)
    elif v >= 2:
        if len(ans) >= 2:
            del ans[0]
        ans.append(k)

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1

    key = list(d.keys())
    key.sort(reverse=True)
    cnt = 0
    ans = 0
    for i in key:
        if d[i] >= 2:
            if cnt == 0:
                ans = i
            elif cnt == 1:
                ans *= i
                print(ans)
                exit()
            cnt += 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)

e = sorted([k for k, v in c.items() if v>1])[::-1]

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

Submission status: Wrong Answer

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

c = Counter(A)
check = 0
for i in range(N):
    if (c[A[i]] > 1):
        check += 1
if (check <= 1):
    print(0)
    exit()

L = []
for i, v in c.items():
    if (v > 1):
        L.append(i)

L.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
cnt_A = Counter(A)
# print(cnt_A)

kouho = []

ans = 0

for key in cnt_A:
    if cnt_A[key] >= 2:
        kouho.append(key)
    elif cnt_A[key] >= 4:
        ans = max(ans, key ** 2)

if len(kouho) < 2:
    print(ans)
    exit()

kouho.sort()
ans = max(ans, kouho[-1] * kouho[-2])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
c = dict(c)
c = sorted(c.items(), key=lambda x:x[0], reverse=True)
h = 0
w = 0
for i in range(len(c)):
  if c[i][1] >= 2 and h == 0:
    h = c[i][0]
  elif c[i][1] >= 2 and w == 0:
    w = c[i][0]
ans = h * w
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
w=[x for x in set(a) if a.count(x) > 1]
w.append(0)
w.append(0)
mw=max(w)
w.sort(reverse=True)
wl=Counter(w)
if wl[mw]>=4:
    mh=mw
else:
    mh=w[1]
print(mh*mw)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dic = {}
cnt = 0

for x in A:
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1

dic = sorted(dic.items(), reverse=True)

ans = 0
for i in range(len(dic)):
    if dic[i][1] >= 4:
        ans = dic[i][0]**2
        break
    elif dic[i][1] >= 2:
        if cnt == 1:
          ans = t*dic[i][0]
          break 
        if cnt == 0:
            t = dic[i][0]
            cnt = 1
print(ans)

Submission status: Wrong Answer

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

dic = {}
cnt = 0

for x in A:
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1

dic = sorted(dic.items(), reverse=True)

ans = 0
for i in range(len(dic)):
    if dic[i][1] >= 2:
        if cnt == 1:
          ans = t*dic[i][0]
          break 
        if cnt == 0:
            t = dic[i][0]
            cnt = 1
print(ans)

Submission status: Wrong Answer

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

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

ans = 0 
d = {}
for i in a:
    if i not in d:
        d[i] = 1 
    else:
        d[i] += 1

d = sorted(d.items(), key=lambda x:x[0], reverse=True)
area = 1 
cnt = 0 
allone = True
for i in d:
    if 1 < i[1] < 4:
        allone = False
        if cnt == 2:
            break
        area *= i[0]
        cnt += 1
    elif i[1] >= 4:
        if cnt == 0:
            area = i[0]*i[0]
            break
        else:
            if cnt == 2:
                break
            area *= i[0]
            cnt += 1

if allone:
    print(0)
else:
    print(area)

Submission status: Wrong Answer

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

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

ans = 0 
d = {}
for i in a:
    if i not in d:
        d[i] = 1 
    else:
        d[i] += 1

d = sorted(d.items(), key=lambda x:x[0], reverse=True)
area = 1 
cnt = 0 
allone = True
for i in d:
    if 1 < i[1] < 4:
        allone = False
        if cnt == 2:
            break
        area *= i[0]
        cnt += 1
    elif i[1] > 4:
        if cnt == 0:
            area = i[0]*i[0]
            break
        else:
            if cnt == 2:
                break
            area *= i[0]
            cnt += 1

if allone:
    print(0)
else:
    print(area)

Submission status: Wrong Answer

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

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

ans = 0 
d = {}
for i in a:
    if i not in d:
        d[i] = 1 
    else:
        d[i] += 1

d = sorted(d.items(), key=lambda x:x[0], reverse=True)
area = 1 
cnt = 0 
allone = True
for i in d:
    if i[1]>1:
        allone = False
        if cnt == 2:
            break
        else:
            area *= i[0]
            cnt += 1

if allone:
    print(0)
else:
    print(area)

Submission status: Wrong Answer

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

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

ans = 0 
d = {}
for i in a:
    if i not in d:
        d[i] = 1 
    else:
        d[i] += 1

d = sorted(d.items(), key=lambda x:x[0], reverse=True)
area = 1 
cnt = 0 
for i in d:
    if i[1]>1:
        if cnt == 2:
            break
        else:
            area *= i[0]
            cnt += 1

if area == 1:
    print(0)
else:
    print(area)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = map(int, input().split())
c = collections.Counter(l)
c = sorted(c.items(), key=lambda c:c[0], reverse=True)

ans = 1
cnt = 0

for key,val in c:
  if val>=2:
    ans*=key
    cnt+=1
  if cnt == 2:
    break
else:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ma1 = 0
ma2 = 0
A = list(map(int,input().split()))
a = sorted(A,reverse = True)

hold = 0
count = 0

for i in a:
  if i == hold:
    count += 1
  else:
    if count > 3 and ma1 == 0:
      ma1 = hold
      ma2 = hold
    elif count > 1:
      if ma1 == 0:
        ma1 = hold
      elif ma2 == 0:
        ma2 = hold
    hold = i
    count = 1
    if ma1 != 0 and ma2 != 0:
      break
    

print(ma1*ma2)

Submission status: Wrong Answer

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

c = sorted(b.items(), reverse = True)
z = [0] * 2
j = 0
for keys,values in c:
    if values < 2:continue
    z[j] = keys
    j += 1
    if j == 2:break

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
dum = [0]*n
a_li = list(map(int,input().split()))
a_counter = Counter(a_li)
a_most = a_counter.most_common()
count = 0
for i,j in a_most:
    if j >= 2:
        dum[count] = i
    count += 1
dum.sort(reverse=1)
if a_counter[dum[0]] >= 4:
    print(dum[0]*2)
else:
    print(dum[0]*dum[1])

Submission status: Wrong Answer

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

c=collections.Counter(a)
d={}
for i in c:
    if c[i]>1:
        d.setdefault(i,c[i])
e=sorted(d,reverse=True)
if len(e)>1:
    print(e[0]*e[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
count_4 = [i[0] for i in c.items() if i[1] >= 4]
if len(count_4) >= 1:
  max_4 = count_4[-1]
else:
  max_4 = 0
count_2 = [i[0] for i in c.items() if i[1] >= 2]
if len(count_2) >= 2:
  max_2_0 = count_2[-1]
  max_2_1 = count_2[-2]
else:
  max_2_0 = 0
  max_2_1 = 0
print(max(max_4**2, max_2_0*max_2_1))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=0
w=0
c=0
for i in range(n-1,0,-1):
    if a[i]==a[i-1] and l==0:
        l=a[i]
        a[i]=0
        a[i-1]=0
    elif a[i]==a[i-1] and w==0:
        w=a[i]
        print(l*w)
        break

Submission status: Wrong Answer

Solution code:
import collections

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

key=list(set(a))
value=[c[i] for i in key]
rkey=list(reversed(key))
rvalue=list(reversed(value))

for i in range(len(rvalue)):
  if rvalue[i]>=4:
    print(rkey[i]**2)
    exit()
  elif rvalue[i]>=2:
    width=rkey[i]
    rvalue.pop(i)
    rkey.pop(i)
    break
else:
  print("0")
  exit()
for i in range(len(rvalue)):
  if rvalue[i]>=2:
    height=rkey[i]
    break
else:
  print("0")
  exit()
print(width*height)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

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

key=list(set(a))
value=[c[i] for i in key]
rkey=list(reversed(key))
rvalue=list(reversed(value))

for i in range(len(rvalue)):
  if rvalue[i]>=4:
    print(rkey[i]**2)
    exit()
  elif rvalue[i]>=2:
    width=rkey[i]
    rvalue.pop(i)
    rkey.pop(i)
    break
else:
  print("0")
  exit()
for i in range(len(rvalue)):
  if rvalue[i]>=2:
    height=rkey[i]
    break
else:
  print("0")
  exit()
print(width*height)

Submission status: Wrong Answer

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

from collections import Counter
c=Counter(a)

ans_1=0
ans_2=0
for key in c:
    if c[key]>=4 and key>ans_1:
        ans_1,ans_2=key,key
    elif c[key]>=4 and key>ans_2:
        ans_2=key
    elif c[key]>=2 and key>ans_2:
        ans_1,ans_2=key,ans_1

print(ans_1*ans_2)

Submission status: Wrong Answer

Solution code:
import collections

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

key=list(set(a))
value=[c[i] for i in key]
rkey=list(reversed(key))
rvalue=list(reversed(value))

for i in range(len(rvalue)):
  if rvalue[i]>=2:
    width=rkey[i]
    rvalue.pop(i)
    rkey.pop(i)
    break
else:
  print("0")
  exit()
for i in range(len(rvalue)):
  if rvalue[i]>=2:
    height=rkey[i]
    break
else:
  print("0")
  exit()
print(width*height)

Submission status: Wrong Answer

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

from collections import Counter
c=Counter(a)

ans_1=0
ans_2=0
for key in c:
    if c[key]>=2 and key>ans_1:
        ans_1,ans_2=key,ans_1
    if c[key]>=4 and key>ans_2:
        ans_2=key

print(ans_1*ans_2)

Submission status: Wrong Answer

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

from collections import Counter
c=Counter(a)

ans_1=0
ans_2=0
for key in c:
    if c[key]>=2 and key>ans_1:
        ans_1,ans_2=key,ans_1

print(ans_1*ans_2)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
arr = list(map(int, input().split()))
a_set = sorted(set(arr), reverse=True)
a_dict = defaultdict(int)
for num in arr:
    a_dict[num] += 1
a, b = 0, 0
for num in a_set:
    if a_dict[num] > 3:
        a, b = num, num
        break
    elif a_dict[num] > 1 and a == 0:
        a = num
    elif a_dict[num] > 1:
        b = num
        break

print(a * b)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
arr = list(map(int, input().split()))
a_set = sorted(set(arr), reverse=True)
a_dict = defaultdict(int)
for num in arr:
    a_dict[num] += 1
a, b = 0, 0
for num in a_set:
    if a_dict[num] > 1 and a == 0:
        a = num
    elif a_dict[num] > 1:
        b = num
        break

print(a * b)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


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

lengthNumberDict = defaultdict(int)
for a in A:
    lengthNumberDict[a] += 1

lengthNumberList = [a for a in list(lengthNumberDict.items()) if a[1] >= 2]
lengthNumberList = sorted(lengthNumberList, key=lambda x: x[0], reverse=True)

if len(lengthNumberList) <= 1:
    print(0)
    quit()


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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

acnt = Counter(a)
num = [0,0]
for i in acnt:
    if acnt[i] >= 4:
        num.append(i)
    if acnt[i] >= 2:
        num.append(i)
print(num[-1] * num[-2])

Submission status: Wrong Answer

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

seta = set(a)

counta = {a : 0 for a in seta}

for i in a:
    if i in seta:
        counta[i] += 1

lines = [i for i in counta.keys() if counta[i] >= 2]

if len(lines) > 1:
    countsameValue = 0
    a = max(lines)
    secondmax = 0
    for l in lines:
        if (l == a):
            countsameValue += 1
        if (l == a and countsameValue > 1):
            secondmax = a
            break
        elif(l != a):
            secondmax = max(secondmax, l)

    print(a * secondmax)
elif len(lines) == 1 and counta[lines[0]] >= 4:
    print(lines[0] ** 2)
else:
    print(0)

Submission status: Wrong Answer

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

seta = set(a)

counta = {a : 0 for a in seta}

for i in a:
    if i in seta:
        counta[i] += 1

lines = [i for i in counta.keys() if counta[i] >= 2]

if len(lines) > 1:
    a = max(lines)
    secondmax = 0
    for l in lines:
        if (l != a):
            secondmax = max(secondmax, l)

    print(a * secondmax)
elif len(lines) == 1 and counta[lines[0]] >= 4:
    print(lines[0] ** 2)
else:
    print(0)

Submission status: Wrong Answer

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

seta = set(a)

counta = {a : 0 for a in seta}

for i in a:
    if i in seta:
        counta[i] += 1

lines = [i for i in counta.keys() if counta[i] >= 2]

if len(lines) > 1:
    a = max(lines)
    secondmax = 0
    for l in lines:
        if (l != a):
            secondmax = max(secondmax, l)

    print(a * secondmax)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

C = list(Counter(A).items())
C.sort(reverse=True)

a = 0
b = 0
for c in C:
    if c[1] > 1 and a == 0 and b == 0:
        a = c[0]
    elif c[1] > 1 and a != 0 and b == 0:
        b = c[0]
        break

print(a * b)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

C = list(Counter(A).items())
C.sort(reverse=True)

a = 0
b = 0
for c in C:
    if c[1] > 1 and a == 0:
        a = c[0]
    elif c[1] > 1 and b == 0:
        b = c[0]

print(a * b)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(list(map(int,input().split())))
A = sorted(A.items(),reverse=True)
check = 0
for key,value in A:
    if value >= 4 and check == 0:
        print(key * 2)
        break
    elif value >= 2 and check == 0:
        tmp = key
        check += 1
    elif value >= 2 and check == 1:
        print(tmp * key)
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
A = Counter(A)
check = 0
for key,value in A.items():
    if value >= 4 and check == 0:
        print(key * 2)
        break
    elif value >= 2 and check == 0:
        tmp = key
        check += 1
    elif value >= 2 and check == 1:
        print(tmp * key)
        break
else:
    print(0)

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()