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 collections
N=int(input())
A=[int(x) for x in input().split()]
C=collections.Counter(A)
C=list(C.items())
li=[]
for i,j in C:
  if j>=4:
    li.append(i)
    break
  if j>=2:
    li.append(i)
  if len(li)==2:
    break
if len(li)==0:
  print(0)
if len(li)==1:
  print(li[0]**2)
if len(li)==2:
  print(li[0]*li[1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(set(A),reverse=True)
li=[]
for aa in AA:
  if A.count(aa)>=4:
    print(aa**2)
    break
  if A.count(aa)>=2:
    li.append(aa)
  if len(li)==2:
    break
if len(li)==0:
  print(0)
if len(li)==2:
  print(li[0]*li[1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1

a, b = 0, 0
for k in sorted(D.keys(), reverse=True):
    v = D[k]

    if v >= 4:
        a = k
        b = k
        break

    if v >= 2:
        if a == 0:
            a = k
        else:
            b = k
            break

print(a * b)

Submission status: Wrong Answer

Solution code:
from collections import*
n,*a=map(int,open(0).read().split())
d=defaultdict(int)
l=[]
for i in a:
    if d[i]==1:l.append(i)
    d[i]+=1
if len(l)>1:
    *_,a,b=sorted(l)
    print(a*b)
else:
    print(0)

Submission status: Wrong Answer

Solution code:

def C():
    n = int(input())
    a = sorted(list(map(int,input().split())),reverse=True)
    i=0
    print(a)
    longer = 0
    shorter = 0
    while i < len(a)-1:
        print(i,a[i])
        if a[i] == a[i+1]:
            if longer == 0:
                longer = a[i]
                i+=1
            elif shorter == 0:
                shorter = a[i]
                i+=1
        i+=1
    print(longer*shorter)
C()

Submission status: Wrong Answer

Solution code:
# ABC071-C　
N = int(input())
A_list = list(map(int, input().split()))

A_set = set(A_list)
A_set = sorted(A_set, reverse=True)

side_list = [0, 0]

for i in range(len(A_set)):   # 大きい順に取っていき，リストで個数を確認する
    if len(side_list) >= 4:
        break
    count = A_list.count(A_set[i])    # リストの個数を確認
    if count == 2 or count == 3:
        side_list.append(A_set[i])
    if count >= 4:
        side_list.append(A_set[i])
        side_list.append(A_set[i])
        
side_list.sort(reverse = True)
print(side_list)
print(side_list[0] * side_list[1])

Submission status: Wrong Answer

Solution code:
# ABC071-C
N = int(input())
A_list = list(map(int, input().split()))

A_set = set(A_list)
A_set = sorted(A_set, reverse=True)

seihokei_ans = 0   
rec_ans = 0
ans_rectangle_list = []   # 長方形を作る辺を入れる
rec_counter = 0   # 大きい辺を入れる回数，二回入れば良い
seihokei_counter = 0

for i in range(len(A_set)):   # 大きい順に取っていき，リストで個数を確認する
    if rec_counter == 2 and seihokei_counter == 1:
        break
        
    count = A_list.count(A_set[i])    # リストの個数を確認
    
    if rec_counter < 2:
        if count  == 2 or count == 3:   # 対辺を作れる時
            ans_rectangle_list.append(A_set[i])
            rec_counter += 1
            
    if seihokei_counter == 0 and count >= 4:   # 4辺全てを作れる
        seihokei_ans = A_set[i] ** 2
        seihokei_counter += 1
        
if rec_counter == 2:
    rec_ans += ans_rectangle_list[0] * ans_rectangle_list[1]

if rec_ans >= seihokei_ans:
    print(rec_ans)
else:
    print(seihokei_ans)

Submission status: Wrong Answer

Solution code:
# ABC071-C
N = int(input())
A_list = sorted(list(map(int, input().split())), reverse = True)

A_set = set(A_list)
A_set = sorted(A_set, reverse=True)

seihokei_ans = 0   
rec_ans = 0
ans_rectangle_list = []   # 長方形を作る辺を入れる
rec_counter = 0   # 大きい辺を入れる回数，二回入れば良い
seihokei_counter = 0

for i in range(len(A_set)):   # 大きい順に取っていき，リストで個数を確認する
    if rec_counter == 2 and seihokei_counter == 1:
        break
    count = A_list.count(A_set[i])    # リストの個数を確認
    if rec_counter <= 2:
        if count  == 2 or count == 3:   # 対辺を作れる時
            ans_rectangle_list.append(A_set[i])
            rec_counter += 1
    if seihokei_counter == 0 and count >= 4:   # 4辺全てを作れる
        seihokei_ans = A_set[i] ** 2
        seihokei_counter += 1
        
if rec_counter == 2:
    rec_ans = ans_rectangle_list[0] * ans_rectangle_list[1]

if rec_ans >= seihokei_ans:
    print(rec_ans)
else:
    print(seihokei_ans)

Submission status: Wrong Answer

Solution code:
# ABC071-C
N = int(input())
A_list = sorted(list(map(int, input().split())), reverse = True)

A_set = set(A_list)
A_set = sorted(A_set, reverse=True)

seihokei_ans = 0   
rec_ans = 0
ans_rectangle_list = []   # 長方形を作る辺を入れる
rec_counter = 0   # 大きい辺を入れる回数，二回入れば良い
seihokei_counter = 0

for i in range(len(A_set)):   # 大きい順に取っていき，リストで個数を確認する
    if rec_counter == 2 and seihokei_counter == 1:
        break
    count = A_list.count(A_set[i])    # リストの個数を確認
    if rec_counter <= 2:
        if count  == 2 or count == 3:   # 対辺を作れる時
            ans_rectangle_list.append(A_set[i])
            rec_counter += 1
    if seihokei_counter == 0 and count >= 4:   # 4辺全てを作れる
        seihokei_ans = A_set[i] ** 2
        
if rec_counter == 2:
    rec_ans = ans_rectangle_list[0] * ans_rectangle_list[1]

if rec_ans >= seihokei_ans:
    print(rec_ans)
else:
    print(seihokei_ans)

Submission status: Wrong Answer

Solution code:
# ABC071-C
N = int(input())
A_list = sorted(list(map(int, input().split())), reverse = True)

A_set = set(A_list)
A_set = sorted(A_set, reverse=True)

seihokei_ans = 0   
rec_ans = 0
ans_rectangle_list = []   # 長方形を作る辺を入れる
rec_counter = 0   # 大きい辺を入れる回数，二回入れば良い
seihokei_counter = 0

for i in range(len(A_set)):   # 大きい順に取っていき，リストで個数を確認する
    if rec_counter == 2 and seihokei_counter == 1:
        break
    count = A_list.count(A_set[i])    # リストの個数を確認
    if rec_counter <= 2:
        if count  == 2 or count == 3:   # 対辺を作れる時
            ans_rectangle_list.append(A_set[i])
            rec_counter += 1
    elif seihokei_counter == 0 and count >= 4:   # 4辺全てを作れる
        ans = A_set[i] ** 2
        
if rec_counter == 2:
    rec_ans = ans_rectangle_list[0] * ans_rectangle_list[1]

if rec_ans >= seihokei_ans:
    print(rec_ans)
else:
    print(seihokei_ans)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

a = list(sorted([a for a, c in Counter(A).items() if c >= 2]))
if len(a) >= 2:
    print(a[-1] * a[-2])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
d = {}
for c in a:d[c]=d.get(c,0)+1
l = []
for k in d.keys():
    if d[k]>=2:l.append(k)

if len(l)>=2:
    l1 = sorted(l,reverse = True)
    print(l1[0]*l1[1])
else:print(0)

Submission status: Wrong Answer

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

dict={}

for i in range(n):
    if not a[i] in dict:
        dict[a[i]]=0
    dict[a[i]]+=1


a=sorted(dict.items(), key=lambda x:x[0])
one=0
two=0
for i in range(len(a)):
    if one==0 and a[i][1]>1:
        one=a[i][0]
    elif a[i][1]>1:
        two=one
        one=a[i][0]
print(one*two)

Submission status: Wrong Answer

Solution code:
def print_ans(s):
  """
  Parameters
  --------------
  >>> print_ans([3,1, 2, 4, 2, 1])
  2
  >>> print_ans([1,2,3,4]) 
  0
  >>> print_ans([3,3,3,3,4,4,4,5,5,5])
  20
  """
  b = list(set(s)) # make unique list (no duplication)
  b.sort() # want to take max 
  ans = 1
  t = 0 # if t == 2, break
  while True:
    #print(len(b))
    if s.count(b[-1]) >= 4:
      ans = b[-1]**2
      break
    elif s.count(b[-1]) >= 2:
      ans *= b[-1]
      t += 1
      if t == 2:
        break
    if len(b) == 1:
      ans = 0
      break
    b.pop(-1) # skip b[-1]
      
  print(ans)

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


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)

longest=0
for length, n in d_sorted:
    if n>=4:
        print(length**2)
        exit()
    elif n>=2 and longest!=0:
        print(longest*length)
        exit()
    elif n>=2 and longest==0:
        longest=max(length,longest)
print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)

longest=0
for length, n in d_sorted:
    if n>=4:
        print(int(length**2))
        exit()
    elif n>=2 and longest!=0:
        print(int(longest*length))
        exit()
    elif n>=2 and longest==0:
        longest=length
print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)

longest=0
for length, n in d_sorted:
    if n>=4:
        print(length**2)
        exit()
    elif n>=2 and longest!=0:
        print(longest*length)
        exit()
    elif n>=2 and longest==0:
        longest=length
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
lines = []
for num in set(a):
    if(a.count(num) >= 2):
        lines.append(num)
lines = sorted(lines, reverse=True)
if(len(lines) >= 2):
    print(lines[0] * lines[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    c = 0
    d = []
    for i in range(N - 1):
        if len(d) == 2:
            break
        if A[i] == A[i + 1] and c != A[i]:
            d.append(A[i + 1])
            c = A[i]
    if 2 > len(d):
        print(0)
    else:
        print(d[0] * d[1])


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
tmp = input().split(" ")

als = []


for t in tmp:
    als.append(int(t))

als.sort(reverse = True)

rec_w = 0
prev = 0
for a in als:
    if rec_w:
        #2つ目の辺を探す
        if a == prev:
            print(a*rec_w)
            exit()
        else:
            prev = a
    else:
        if a == prev:
            rec_w = a
            prev = 0
        else:
            prev = a

Submission status: Wrong Answer

Solution code:
n = input()

num_list = [ int(v) for v in input().split() ]
count_list = [ [num_list.count(i),i] for i in sorted(set(num_list),reverse = True)]

a, b = -1, -1
for i in count_list:
	if i[0] >= 4 and a == -1:
		print(i[1]**2)
		break
	elif i[0] >= 2:
		if a == -1:
			a = i[1]
		else:
			b = i[1]
			print(a*b)
			break

Submission status: Wrong Answer

Solution code:
n = int(input())

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

length = sorted(length)
length.append(0)

temp = length[0]
c = 1

unique_n = []

for i in range(n):
    if temp == length[i+1]:
        c += 1
    
    else:
        if c >= 2:
            unique_n.append(length[i-1])
        
        c = 1
        temp = length[i+1]

if len(unique_n) <= 1:
    print(0)

else:
    print(unique_n[-1]*unique_n[-2])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
res = [e for e in set(A) if A.count(e) > 1]
if res == []:
    print("0")
elif A.count(max(A)) >= 4:
    print(max(A)**2)
else:
    print(res[-1] * res[-2])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
res = [e for e in set(A) if A.count(e) > 1]
if res == []:
    print("0")
else:
    print(res[-1] * res[-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac = Counter(a)

cur_a = 0
res = 0
for a,c in ac.items():
	if c < 2:
		break
	else:
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)
		if c >= 4:
			res = max(res,a*a)

print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac = Counter(a)

cur_a = 0
res = 0
for a,c in ac.items():
	if c < 2:
		break
	elif c >= 4:
		res = max(res,a*a)
	else:
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)

print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac = Counter(a)

cur_a = 0
cur_c = 0
res = 0
for a,c in ac.items():
	if c < 2:
		break
	if c >= 4:
		res = max(res,a*a)
	if cur_c == c:
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)
	else:
		cur_a = a
		cur_c = c

print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac = Counter(a)

cur_a = 0
cur_c = 0
res = 0
for a,c in ac.items():
	if c < 2:
		break
	if cur_c == c:
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)
	else:
		cur_a = a
		cur_c = c

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())

pile_list = sorted([ int(v) for v in input().split() ])

single_list = []
double_list = []

for i in range(n-1):
	if pile_list[i] == pile_list[i+1]:
		double_list.append(pile_list[i])


ans = list(set(double_list))
if len(ans) < 2:
	print(0)

elif len(list(set(double_list[-3:]))) == 1:
	print(ans[-1]**2)

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

Submission status: Wrong Answer

Solution code:
n = int(input())

pile_list = sorted([ int(v) for v in input().split() ])

single_list = []
double_list = []

for i in range(n-1):
	if pile_list[i] == pile_list[i+1]:
		double_list.append(pile_list[i])


ans = list(set(double_list))
if len(ans) < 2:
	print(0)

elif len(list(set(double_list[-4:]))) == 1:
	print(ans[-1]**2)

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

Submission status: Wrong Answer

Solution code:

n = int(input())

pile_list = sorted([ int(v) for v in input().split() ])

single_list = []
double_list = []

for i in range(n-1):
	if pile_list[i] == pile_list[i+1]:
		double_list.append(pile_list[i])


ans = list(set(double_list))
if len(ans) < 2:
	print(-1)
else:
	print(ans[-1]*ans[-2])

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())
n = readi()
t = readl()
s = defaultdict(int)
for i in t:
    s[i] += 1

t1 = 0
t2 = 0
for i in sorted(s.items(),reverse=True,key=lambda x:x[0]):
    if t1 == 0:
        if i[1] >= 2:
            t1 = i[0]
    elif t2 == 0:
        if i[1] >= 2:
            t2 = i[0]
            break
print(t1 * t2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A).most_common()
B.sort(key= lambda x : -x[0])
L=[]
for i in B:
    if i[1]>=4:
        L.append(i[0])
        L.append(i[0])
    elif i[1]>=2:
        L.append(i[0])
    if len(L)==2:
        break
print(L[0]*L[1] if len(L)==2 else 0)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A).most_common()
B.sort(key= lambda x : -x[0])
L=[]
for i in B:
    if i[1]>=2:
        L.append(i[0])
    if len(L)==2:
        break
print(L[0]*L[1] if len(L)==2 else 0)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
L=[]
for i in A:
    if A.count(i)>=2 and i not in L:
        L.append(i)
    if len(L)==2:
        break
print(L[0]*L[1] if len(L)==2 else 0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
from collections import defaultdict
d=defaultdict(int)
for i in a:
    d[i]+=1
a=sorted(list(d.items()),key=lambda x:x[0])
p=0
ans=0
#print(a)
while a:
    c=a.pop()
    if c[1]<2:
        continue
    if c[1]>=4:
        ans=c[0]**2
        break
    elif c[1]>=2:
        if p==0:
            p=c[0]
        else:
            ans=p*c[0]
            break
            
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(s) for s in input().split()]

def main():
    e = {}
    for n in A:
        if not n in e.keys():
            e[n] = 0
        e[n] += 1

    se = sorted([k for k, v in e.items() if v > 1], reverse=True)
    ans = se[0] * se[1] if len(se) >= 2 else 0
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from bisect import bisect_left, bisect_right


def count(seq, element):
    "Return number of occurrences of item"
    i = bisect_left(seq, element)
    j = bisect_right(seq, element)
    return seq[i:j].count(element)


def solve(N: int, A: "List[int]"):
    flag = 0
    ans = 1
    seta = sorted(list(set(A)))
    sa = sorted(A)
    for a in reversed(seta):
        if count(sa, a) == 4:
            if flag == 1:
                ans *= a
                print(ans)
                return
            ans = a * a
            print(ans)
            return
        elif count(sa, a) >= 2:
            flag += 1
            ans *= a
            if flag == 2:
                print(ans)
                return
    print(0)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from bisect import bisect_left, bisect_right


def count(seq, element):
    "Return number of occurrences of item"
    i = bisect_left(seq, element)
    j = bisect_right(seq, element)
    return seq[i:j].count(element)


def solve(N: int, A: "List[int]"):
    flag = 0
    ans = 1
    seta = sorted(list(set(A)))
    sa = sorted(A)
    for a in reversed(seta):
        if count(sa, a) == 4:
            print(a*a)
            return
        elif count(sa, a) >= 2:
            flag += 1
            ans *= a
            if flag == 2:
                print(ans)
                return
    print(0)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, *a = map(int, open(0).read().split())

c = Counter(a).most_common()
c = sorted([[i, j // 2] for i, j in c], reverse=True)
ans = 1
cnt = 0
for i in range(len(c)):
    a, v = c[i]
    if v > 0:
        ans *= a
        cnt += 1
        if cnt == 2:
            break
            
print(ans if cnt == 2 else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc071/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))
A.sort()
tmp = [0,0]
for i in range(len(A)-1):
    if A[i] == A[i+1] and not A[i] in tmp:
        tmp.append(A[i])
ans = tmp[-1]*tmp[-2]
if tmp.count(tmp[-1]) >=4:
        ans = max(ans,tmp[-1]*tmp[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc071/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))
A.sort()
tmp = [0,0]
for i in range(len(A)-1):
    if A[i] == A[i+1] and not A[i] in tmp:
        tmp.append(A[i])
ans = tmp[-1]*tmp[-2]
for j in range(1,len(tmp)):
    if tmp.count(tmp[-j]) >=4:
        ans = max(ans,tmp[-j]*tmp[-j])
print(ans)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc071/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))
A.sort()
tmp = [0,0]
for i in range(len(A)-1):
    if A[i] == A[i+1] and not A[i] in tmp:
        tmp.append(A[i])
tmp.sort()
print(tmp[-1]*tmp[-2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
c=sorted([n for n in collections.Counter(map(int, input().split())).items() if n[1] > 1], reverse=True)
print(c[0][0] * c[1][0] if len(c) > 1 else 0)

Submission status: Wrong Answer

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

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

#print(asum)

kouho = 0
for a in sorted(asum)[::-1]:
	if 4 <= asum[a]:
		if kouho:
			print(kouho * a)
		else:
			print(a * a)
		break
	elif 2 <= asum[a]:
		if kouho:
			print(kouho * a)
			break
		else:
			kouho = a
else:
	print(0)

Submission status: Wrong Answer

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

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

#print(asum)

kouho = 0
for a in sorted(asum)[::-1]:
	if 4 <= asum[a]:
		print(a * a)
		break
	elif 2 <= asum[a]:
		if kouho:
			print(kouho * a)
			break
		else:
			kouho = a
else:
	print(0)

Submission status: Wrong Answer

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

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

#print(asum)

kouho = 0
for a in sorted(asum)[::-1]:
	if 4 <= asum[a]:
		print(a * a)
		break
	if 2 <= asum[a]:
		if kouho:
			print(kouho * a)
			break
		else:
			kouho = a
else:
	print(0)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import collections
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = list(int(_) for _ in input().split())
    d = collections.defaultdict(int)
    for i in range(N):
        d[a[i]]+=1

    e_1 = 0
    e_2 = 0
    for d_i in sorted(d.items(),key=lambda x:-x[0]):
        if d_i[1] >= 4:
            e_1 = d_i[0]
            e_2 = d_i[0]
            break
        elif d_i[1] >= 2 and e_1 == 0:
            e_1 = d_i[0]
        elif d_i[1] >= 2 and e_2 == 0:
            e_2 = d_i[0]
            break
    print(e_1 * e_2)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
c=list(Counter(A).most_common())
c.sort(key=lambda x:x[0],reverse=True)
w=0
h=0
print(c)
for a,b in c:
    if(b>=4):
        if(w==0):
            w=a
            h=a
            break
        else:
            h=a
            break
    if(b>1):
        if(w==0):
            w=a
        else:
            h=a
            break
print(w*h)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
c=list(Counter(A).most_common())
c.sort(key=lambda x:x[0],reverse=True)
w=0
h=0
for a,b in c:
    if(b>1):
        if(w==0):
            w=a
        else:
            h=a
            break
print(int(w*h))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


N = int(input())
A = [int(i) for i in input().split()]

A.sort()
len_dic = {}
for a in A:
    if a in len_dic.keys():
        len_dic[a] += 1

    else:
        len_dic[a] = 1

ans = [0,0]
for k, v in sorted(len_dic.items(),key=lambda x:-x[0]):
    if v >= 4 and ans[0] == 0:
        ans = [k,k]
    elif v >= 2:
        if ans[0]==0:
            ans[0] = k
        elif ans[1] == 0:
            ans[1] = k
    else:
        break

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

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


N = int(input())
A = [int(i) for i in input().split()]

A.sort()
len_dic = {}
for a in A:
    if a in len_dic.keys():
        len_dic[a] += 1

    else:
        len_dic[a] = 1

ans = [0,0]
for k, v in sorted(len_dic.items(),key=lambda x:-x[0]):
    if v >= 4:
        ans = [k,k]
    elif v >= 2:
        if ans[0]==0:
            ans[0] = k
        elif ans[1] == 0:
            ans[1] = k
        else:
            break

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

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


N = int(input())
A = [int(i) for i in input().split()]

len_dic = {}
for a in A:
    if a in len_dic.keys():
        len_dic[a] += 1

    else:
        len_dic[a] = 1

ans = [0,0]
for k, v in sorted(len_dic.items(),key=lambda x:-x[0]):
    if v >= 2:
        if ans[0]==0:
            ans[0] = k
        elif ans[1] == 0:
            ans[1] = k
        else:
            break

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

Submission status: Wrong Answer

Solution code:
n  = int(input())

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

nums = {}
for i in a:
  if i in nums:
    nums[i] += 1
  else:
    nums[i] = 1
    
nums_list_sorted = sorted(nums.items(), reverse=True)

a = 0
b = 0
for i in range(len(nums_list_sorted)):
  if nums_list_sorted[i][1] >= 2:
    if a == 0:
      a = nums_list_sorted[i][0]
      #del nums_list_sorted[i]
    else:
      b = nums_list_sorted[i][0]
    if a != 0 and b != 0: 
      break

print(a*b)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=[]
for a in set(A):
  if A.count(a)>1:
    B.append(a)
B.sort()
print(0 if len(B)<2 else B[-1]*B[-2])

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))+[0]
arr=sorted(arr, reverse=True)
ans1=0
ans2=0
ans3=0
count=1
for i in range(n):
  if arr[i]!=arr[i+1]:
    if count>=4:
      if ans3==0:
        ans3=arr[i]
    elif count>=2:
      if ans1==0:
        ans1=arr[i]
      elif ans2==0:
        ans2=arr[i]
    count=1
  else:
    count+=1
print(max(ans1*ans2,ans3**2))

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))+[0]
arr=sorted(arr, reverse=True)
ans1=0
ans2=0
count=1
for i in range(n):
  if arr[i]!=arr[i+1]:
    if count>=2:
      if ans1==0:
        ans1=arr[i]
      elif ans2==0:
        ans2=arr[i]
    count=1
  else:
    count+=1
print(ans1*ans2)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))+[0]
arr=sorted(arr, reverse=True)
ans1=0
ans2=0
count=1
for i in range(n):
  if arr[i]!=arr[i+1]:
    if count>=2:
      if ans1==0:
        ans1=arr[i]
      else:
        ans2=arr[i]
    count=1
  else:
    count+=1
print(ans1*ans2)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

sides = list(bars.keys())
sides.sort(reverse=True)
ans = 0
rect = []
for side in sides:
    if bars[side] >= 4:
        ans = side * side
        break
    elif bars[side] >= 2:
        rect.append(side)
        if len(rect) == 2:
            ans = rect[0] * rect[1]
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = [int(n) for n in input().split()]

l = collections.Counter(a)
bars = filter(lambda x: l[x] >= 2 , l)
bars = sorted(bars, reverse=True)

if len(list(bars)) <= 1:
    s = 0
else:
    s = bars[0] * bars[1]

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = list(map(int, input().split()))
for num in set(nums):
    nums.pop(nums.index(num))
nums = sorted(set(nums), reverse=True)
print(nums[0]*nums[1] if len(nums) else 0)