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:
_ = input()
a = [int(x) for x in input().split()]

a = sorted(set(a))
a.reverse()
ans = 1
cnt = 0
for i in a:
    c = a.count(i)
    if 4 <= c:
        print(i ** 2)
        break
    elif 2 <= c:
        if cnt == 0:
            ans *= i
            cnt += 1
        else:
            print(ans * i)
            break
else:
    print(0)

Submission status: Wrong Answer

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

a.sort(reverse = True)
ans = 0
b = a.copy()
b = list(set(b))
b.sort(reverse = True)
c = [0]*len(b)
j = 0
c[j] = 1
for i in range(1,n):
    if a[i-1] == a[i]:
        c[j] +=1
    else:
        j+=1
        c[j] +=1
for i in range(len(b)):
    if c[i] >= 4:    
        ans = b[i]*b[i]
    elif c[i] >= 2:
        for j in range(i+1,len(b)):
            if c[j] >= 2:
                ans = b[i]*b[j]
                break
        break
print(ans)

Submission status: Wrong Answer

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

a.sort(reverse = True)
ans = 0
b = a.copy()
b = list(set(b))
b.sort(reverse = True)
c = [0]*len(b)
j = 0
c[j] = 1
for i in range(1,n):
    if a[i-1] == a[i]:
        c[j] +=1
    else:
        j+=1
        c[j] +=1
for i in range(len(b)):
    if c[i] >= 4:    
        ans = b[i]*b[i]
    elif c[i] >= 2:
        for j in range(i+c[i]-1,len(b)):
            if c[j] >= 2:
                ans = b[i]*b[j]
                break
print(ans)

Submission status: Wrong Answer

Solution code:

def keisan(a):
    a.sort(reverse = True)
    ans = 0
    for i in range(0,n,2):
        if a.count(a[i]) >= 4:
            ans = a[i]*a[i]
            break
        elif a.count(a[i]) >=2:
            for j in range(1+i+a.count(a[i]),n,2):
                if a[j-1] == a[j]:
                    ans = a[i]*a[j]
                    break
            break
    print(ans)

n = int(input())
in_=list(map(int,input().split()))
keisan(in_)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
ans = 0
check = 0
i = 0
while i < n:
    
    if a.count(a[i]) >= 4:
        ans = a[i]*a[i]
        break
    elif a.count(a[i]) >=2 and check == 0:
        ans += a[i]
        check =1
        i += a.count(a[i])
    elif a.count(a[i]) >=2 and check == 1:
        ans *= a[i]
        break
    else:
        i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    data = A[i]
    if data in dic:  dic[data] += 1
    else:  dic[data] = 1
temp1, temp2 = 0, 0
for i in sorted(dic.keys())[::-1]:
    if dic[i] >= 2:
        if temp1 == 0:  temp1 = i
        else:
            temp2 = i
            break
ans = temp1 * temp2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
a = [list(x) for x in a.items() if x[1]>=2]
a.sort(reverse=True, key=lambda x: (x[0], x[1]))
count = 0
base = 4
for l, c in a:
    if c>=base:
        print(l*l)
        exit()
    elif count == 1:
        print(l*l1)
        exit()
    else:
        l1 = l
        count += 1
print(0)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
a = deque(a)
count = 0
l = [0]*2
l[0] = a.popleft()
while a:
    lk = a.popleft()
    if l[count]==lk:
        count += 1
        if count >= 2:
            print(l[0]*l[1])
            exit()
    if a:
        l[count] = a.popleft()
    else:
        break

print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
a = [list(x) for x in a.items() if x[1]>=2]
a.sort(reverse=True, key=lambda x: (x[0], x[1]))
count = 0
if len(a)>=1:
    ans = 1
    for i in range(len(a)):
        if count >= 2:
            break
        if a[i][1]>=2:
            a[i][1] -= 2
            count +=1
            ans *= a[i][0]
    if not count>=2:
        print(0)
    else:
        print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
ans = [i[0] for i in c.items() if i[1] >= 2]
ans = [i[0] for i in c.items() if i[1] >= 4]
ans.extend([0,0])
ans.sort(reverse=True)
print(ans[0]*ans[1])

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
ans = [i[0] for i in c.items() if i[1] >= 2]
ans.extend([0,0])
ans.sort(reverse=True)
print(ans[0]*ans[1])

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    As = list(map(int, input().split()))
    As_set = sorted(set(As), reverse=True)
    m = len(As_set)
    ans = 0
    cnts = [As.count(A) for A in As_set]
    for i in range(m-1):
        bf = As_set[i]
        af = As_set[i+1]
        bf_count = cnts[i]
        af_count = cnts[i+1]
        if bf_count >= 4:
            ans = max(ans, bf*2)
        if af_count >= 4:
            ans = max(ans, af*2)
        if af_count >= 2 and bf_count >= 2:
            ans = max(ans, af*bf)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    As = list(map(int, input().split()))
    As_set = sorted(set(As), reverse=True)
    m = len(As_set)
    ans = 0
    for i in range(m-1):
        bf = As_set[i]
        af = As_set[i+1]
        bf_count = As.count(bf)
        af_count = As.count(af)
        if bf_count >= 4:
            ans = max(ans, bf*2)
        if af_count >= 4:
            ans = max(ans, af*2)
        if af_count >= 2 and bf_count >= 2:
            ans = max(ans, af*bf)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    As = list(map(int, input().split()))
    As_set = sorted(set(As), reverse=True)
    m = len(As_set)
    ans = 0
    for i in range(m-1):
        bf = As_set[i]
        af = As_set[i+1]
        bf_count = As.count(bf)
        af_count = As.count(af)
        if bf_count >= 4:
            ans = max(ans, bf*2)
        if af_count >= 4:
            ans = max(ans, af*2)
        if af_count >= 2 and bf_count >= 2:
            ans = max(ans, af*bf)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

l = []
d = dict()
for v in a:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
        
    if d[v] == 2:
        l.append(v)

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

Submission status: Wrong Answer

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

l = []
d = dict()
for v in a:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
        
    if d[v] == 2:
        l.append(v)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sorted(A, reverse=True)
w, h = 0, 0

cnt = 0
tmp = 0
l = S[0]
for i in range(N):
  if S[i] != l:
    if cnt == 0:
      if tmp > 3:
        w, h = l, l
        break
      elif tmp > 1:
        w = l
        tmp = 1
        l = S[i]
        cnt += 1
      else:
        tmp = 1
        l = S[i]
    else:
      h = l
      break
  else:
    tmp += 1
    if i == N-1:
      if cnt == 0:
      	if tmp > 3:
          w, h = l, l
      else:
        h = l
ans = w * h
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sorted(A, reverse=True)
w, h = 0, 0

cnt = 0
tmp = 0
l = S[0]
for i in range(N):
  if S[i] != l:
    if cnt == 0:
      if tmp > 3:
        w, h = l, l
        break
      elif tmp > 1:
        w = l
        tmp = 1
        l = S[i]
        cnt += 1
      else:
        tmp = 1
        l = S[i]
    else:
      h = l
      break
  else:
    tmp += 1
    if i == N-1:
      h = l
ans = w * h
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sorted(set(A), reverse=True)
w, h = 0, 0

cnt = 0
for i in range(len(S)):
  if A.count(S[i]) > 1:
    if cnt == 0:
      w = S[i]
      cnt += 1
    else:
      h = S[i]
      cnt += 1
  if cnt == 2:
    break
ans = w * h
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
C = sorted(C.items(), reverse=True)
print(C)
a, b = 0, 0
for k, v in C:
    if a == 0 and v >= 4:
        print(k * k)
        sys.exit()
    if v >= 2:
        if a == 0:
            a = k
        elif b == 0:
            print(a * k)
            sys.exit()
print(0)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
C = sorted(C.items(), reverse=True)
a, b = 0, 0
for k, v in C:
    if v >= 4:
        print(k * k)
        sys.exit()
    if v >= 2:
        if a == 0:
            a = k
        elif b == 0:
            print(a * k)
            sys.exit()
print(0)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
C = sorted(C.items(), key=lambda x:x[1])
a, b = 0, 0
for k, v in C:
    if v >= 4:
        print(k * k)
        sys.exit()
    if v >= 2:
        if a == 0:
            a = k
        elif b == 0:
            print(a * k)
            sys.exit()
print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a)
d = dict(sorted(c.items(), key=lambda x:x[0], reverse=True))

x = 0
y = 0
for k, v in d.items():
   if v >= 2:
      if x == 0:
         x = k
      elif y == 0:
         y = k
         break

ans = x * y
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = list(map(int,input().split())) + [0]
A = list(Counter(A).items())
A  = sorted(A,key=itemgetter(1),reverse = True)
A  = sorted(A,key=itemgetter(0),reverse = True)
#print(A)
ans = 0
for i in range(len(A)):
    if A[i][1] > 1:
        if A[i][1] > 3 :
            ans = max(ans,A[i][0]*2)
        if A[i][1] > 1 and A[i+1][1] > 1:
            ans = max(ans ,A[i][0]*A[i+1][0])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = list(map(int,input().split()))
A = list(Counter(A).items())
A  = sorted(A,key=itemgetter(1),reverse = True)
A  = sorted(A,key=itemgetter(0),reverse = True)
#print(A)
ans = 0
for i in range(len(A)-1):
    if A[i][1] > 1:
        if A[i][1] > 3 :
            ans = max(ans,A[i][0]*2)
        if A[i][1] > 1 and A[i+1][1] > 1:
            ans = max(ans ,A[i][0]*A[i+1][0])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = list(map(int,input().split()))
A = list(Counter(A).items())
A  = sorted(A,key=itemgetter(0),reverse = True)
A  = sorted(A,key=itemgetter(1),reverse = True)
#print(A)
ans = 0
for i in range(len(A)-1):
    if A[i][1] > 1:
        if A[i][1] > 3 :
            ans = max(ans,A[i][0]*2)
        if A[i][1] > 1 and A[i+1][1]>1:
            ans = max(ans ,A[i][0]*A[i+1][0])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = list(map(int,input().split()))
A = list(Counter(A).items())
A  = sorted(A,key=itemgetter(0),reverse = True)
A  = sorted(A,key=itemgetter(1),reverse = True)
#print(A)
ans = 0
for i in range(len(A)-1):
    if A[i][1] > 1:
        if A[i][1] > 3 :
            ans = max(ans,A[i][0]*2)
        elif A[i][1] > 1 and A[i+1][1]>1:
            ans = max(ans ,A[i][0]*A[i+1][0])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split(' ')))
x=0
y=0
a.sort()
a.reverse()
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        x=a[i]
        p=i+1
        break
if x!=0:
    for i in range(p,len(a)-1):
        if a[i]==a[i+1]:
            y=a[i]
            break
print(x*y)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split(' ')))
x=0
y=0
a.sort()
a.reverse()
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        x=a[i]
        break
if x!=0:
    for i in range(len(a)-1):
        if a[i]!=x and a[i]==a[i+1]:
            y=a[i]
            break
print(x*y)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
b=[]
d=defaultdict(int)
for i in range(n):
    d[a[i]]+=1

for i,j in d.items():
    if j>=2:
        b.append(i)

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
A.append(0)
i=0
ans=1
d=0
while i<N:
  b=A[i]
  c=0
  while i<N and b==A[i]:
    i+=1
    c+=1
  if 2<=c<=3:
    d+=1
    ans*=b
    if d==2:
      break
  elif 4<=c:
    ans*=b*b
    d=2
    break
if d!=2:
  print(0)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
A.append(0)
i=0
ans=1
d=0
while i<N:
  b=A[i]
  c=0
  while i<N and b==A[i]:
    i+=1
    c+=1
  if 2<=c<=3:
    d+=1
    ans*=b
  elif 4<=c:
    ans*=b*b
    d=2
    break
  if d==2:
    break
if d!=2:
  print(0)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
A.append(0)
i=0
ans=1
d=0
while i<N:
  b=A[i]
  c=0
  while i<N and b==A[i]:
    i+=1
    c+=1
  if 2<=c:
    d+=1
    ans*=b
  if d==2:
    break
if d!=2:
  print(0)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
*A, = map(int, input().split())
c = Counter(A)
ac = [(k, v) for k, v in c.items()]
ac.sort()
ac.reverse()

ans = 0
for k, v in ac:
    if v >= 4:
        ans = k*k
        break
    elif v >= 2:
        if ans == 0:
            ans = -k
        else:
            ans *= -k
            break
print(max(ans, 0))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
*A, = map(int, input().split())
c = Counter(A)
ac = [(k, v) for k, v in c.items()]
ac.sort()
ac.reverse()

ans = 0
for k, v in ac:
    if v >= 2:
        if ans == 0:
            ans = -k
        else:
            ans *= -k
            break
print(max(ans, 0))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *l = map(int, read().split())

c = Counter(l)
sides = sorted([[x, y] for x, y in c.items() if y >= 2])
ans = 0
if len(sides) == 1:
    if sides[-1][1] >= 4:
        ans = sides[-1][0] * 2
elif len(sides) >= 2:
    if sides[-1][1] >= 4:
        ans = sides[-1][0] * 2
    else:
        ans = sides[-1][0]*sides[-2][0]

print(ans)

Submission status: Wrong Answer

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

A.sort()
b = set(A)
b = list(b)
b.reverse()


ans = []
count = 0

for i in b:
    if A.count(i) >= 4:
        print(i * 2)
    elif A.count(i) >= 2:
        count += 1
        ans.append(i)
        if count == 2:
            print(ans[0]*ans[1])
            exit()

print(0)

Submission status: Wrong Answer

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

A.sort()
b = set(A)
b = list(b)
b.reverse()


ans = []
count = 0

for i in b:
    if A.count(i) >= 2:
        count += 1
        ans.append(i)
        if count == 2:
            print(ans[0]*ans[1])
            exit()

print(0)

Submission status: Wrong Answer

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

A.sort()
b = set(A)
b = list(b)
a = [i for i in b if A.count(i) >= 2]

if len(a) <= 1:
    print(0)
else:
    a = set(a)
    a = list(a)
    a.reverse()
    print(a[0]*a[1])

Submission status: Wrong Answer

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

c = collections.Counter(a_lst)
cand = [k for k, v in c.items() if v >= 2]
cand = sorted(cand)
if len(cand) >= 2:
  print(cand[-2] * cand[-1])
else:
  print(0)

Submission status: Wrong Answer

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

b= defaultdict(int)
ans = []
for i in range(n):
    b[a[i]] += 1
    if b[a[i]] == 2:
       ans.append(a[i])
ans = sorted(ans,reverse=True)
if len(ans) <= 1:
    print(0)
    exit()
print(ans[0]*ans[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ch = [0]*2
i = 0
j = 0
ans = 1
a.sort()
a = a[::-1]
while True:
    if a[i] == a[i+1]:
        ch[0] = a[i]
        break
    else:
        i += 1
    if i == n-1:
        ans = 0
        break

while True:
    if ans == 0:
        break
    if a[i+j] == a[i+j+1] and a[i+j] != ch[0]:
        ch[1] = a[i+j]
        break
    else:
        j += 1
    if i+j == n-1:
        ans = 0

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

Submission status: Wrong Answer

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

import collections

c = sorted(collections.Counter(a).items(), reverse=True)

leng_1 = 0
for leng,count in c:
  if count >=4:
    print(leng**2)
    exit()
  elif count >=2:
    if leng_1 != 0:
      print(leng_1*leng)
      exit()
    else:
      leng_1 = leng
print(0)

Submission status: Wrong Answer

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

import collections

c = sorted(collections.Counter(a).items(), reverse=True)

leng_1 = 0
for leng,count in c:
  if count >=4:
    print(leng**2)
  elif count >=2:
    if leng_1 != 0:
      print(leng_1*leng)
      exit()
    else:
      leng_1 = leng
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
square = []
c = 0
now = a[0]
result = 0
for i in a[1:]:
    if c % 2 == 0:
        if now == i:
            square.append(i)
            if len(square) == 2:
                result = square[0] * square[1]
                break
    now = i
    c += 1
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
square = []
now = a[:1]
result = 0
for i in a[1:]:
    if now == i:
        square.append(i)
        if len(square) == 2:
            result = square[0] * square[1]
            break
    now = i
print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort()
S.reverse()

dic={}
for i in range(N):
    tmp=S[i]
    if tmp in dic:
        dic[tmp]+=1
    else:    
        dic[tmp]=1
kouho1=0
keys = [k for k, v in dic.items() if v >= 4]
keys.sort()
keys.reverse()
for i in keys:
    kouho1=i*2

kouho2=0
keys = [k for k, v in dic.items() if v >= 2]
keys.sort()
keys.reverse()
if len(keys)>=2:
    kouho2=keys[0]*keys[1]

print(max(kouho1,kouho2))

Submission status: Wrong Answer

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

S.sort()
S.reverse()

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
T = [[0 for j in range(4)] for i in range(N)]

dic={}
for i in range(N):
    tmp=S[i]
    if tmp in dic:
        dic[tmp]+=1
    else:    
        dic[tmp]=1
kouho1=0
keys = [k for k, v in dic.items() if v >= 4]
keys.sort()
keys.reverse()
for i in keys:
    kouho1=i*4

kouho2=0
keys = [k for k, v in dic.items() if v >= 2]
keys.sort()
keys.reverse()
if len(keys)>=2:
    kouho2=keys[0]*keys[1]

print(max(kouho1,kouho2))

Submission status: Wrong Answer

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

S.sort()
S.reverse()

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
T = [[0 for j in range(4)] for i in range(N)]

'''
S4=0
S4count=0
S2_1=0
S2_1count=0
S2_2=0
S2_2count=0

tmp=[0]*4

tmp[0]=S[0]
'''
dic={}
for i in range(N):
    tmp=S[i]
    if tmp in dic:
        dic[tmp]+=1
    else:    
        dic[tmp]=1
kouho1=0
keys = [k for k, v in dic.items() if v >= 4]
for i in keys:
    kouho1=i*4

kouho2=0
keys = [k for k, v in dic.items() if v >= 2]
if len(keys)>=2:
    kouho2=keys[0]*keys[1]

    
#keys.sort()
print(max(kouho1,kouho2))
# ['key1', 'key2']
# ['key1', 'key2']

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
c=collections.Counter(list(map(int,input().split())))
p=-1
for x in sorted(c.keys())[::-1]:
    if p==-1 and c[x]>=2:p=x
    elif p!=-1 and c[x]>=2:
        print(p*x)
        break
else:print(0)

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
ls = list(map(int,input().split()))
c =collections.Counter(ls)
d = list(c)
p = []
if c[d[0]] < 2:
    print(0)
    sys.exit()
if c[d[1]] < 2:
    if c[d[0]] < 4:
        print(0)
        sys.exit()
for i in range(len(d)):
    if c[d[i]] >1:
        p.append(d[i])
mx1 = max(p)
p.remove(mx1)
mx2 = max(p)
print(mx1 * mx2)

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
ls = list(map(int,input().split()))
c =collections.Counter(ls)
d = list(c)
p = []
if c[d[0]] < 2:
    print(0)
    sys.exit()
if c[d[1]] < 2:
    print(0)
    sys.exit()
for i in range(len(d)):
    if c[d[i]] >1:
        p.append(d[i])
mx1 = max(p)
p.remove(mx1)
mx2 = max(p)
print(mx1 * mx2)

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
ls = list(map(int,input().split()))
c =collections.Counter(ls)
d = list(c)
p = []
if c[d[1]] < 2:
    print(0)
    sys.exit()
for i in range(len(d)):
    if c[d[i]] >1:
        p.append(d[i])
mx1 = max(p)
p.remove(mx1)
mx2 = max(p)
print(mx1 * mx2)

Submission status: Wrong Answer

Solution code:
import collections

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

CNT_A = collections.Counter(A_s).most_common()
sorted_A = sorted(CNT_A, reverse=True)

verticle = []
ans = 0


for i in range(len(CNT_A)):
    key = sorted_A[i][0]
    value = sorted_A[i][1]
    
    if (value > 1):
        verticle.append(key)
    
    if (len(verticle) >= 2):
        ans = verticle[0] * verticle[1]
        break


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
kouho = set([])
for i in c.most_common():
	if i[1] >= 2:
		kouho.add(i[0])
kouholist = list(kouho)
kouholist = sorted(kouholist)[::-1]
if len(kouholist) >= 2:
	print(kouholist[0]*kouholist[1])
else:
	print(0)

Submission status: Wrong Answer

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

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

b = collections.Counter(a)
l = []

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

if not l:
    print(0)
else:
    l = sorted(l,reverse = True)
    print(l[0][0]*l[1][0])

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A, reverse = True)
  flag = True
  num = 0
  ans = 1
  for i in range(N-1):
    if A[i] == A[i+1] and flag:
      ans *= A[i]
      num += 1
      if num == 2:
        break
      flag = False
    elif not flag:
      flag = True
  print(ans)
main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
C=Counter(a)
#print(C)
l=[]
for k,v in C.items():
    #print(k,v)
    if v>=4:
        l.append(k)
        l.append(k)
    elif v==2 or v==3:
        l.append(k)
    if len(l)>=2:
        break
#print(l)
if len(l)<2:
    print(0)
else:
    print(l[0]*l[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
C=Counter(a)
l=[]
for k,v in C.items():
    if v>=4:
        l.append(k)
        l.append(k)
    elif v==2 or v==3:
        l.append(k)
    if len(l)>=2:
        break
if len(l)==0:
    print(0)
else:
    print(l[0]*l[1])

Submission status: Wrong Answer

Solution code:
def find_max_rectangle(pair):
  """
  Args:
    pair (list)
  Returns:
    area (int)
  """
  if pair:
    M = max(pair)
    second_max = -1
    for num in pair:
      if num != M and second_max < num:
        second_max = num
    return M * second_max
  else:
    return 0



n = int(input())
L = list(map(int, input().split()))
L.sort()
pair = []
prev = None
while L:
  popped = L.pop()
  if prev == popped:
    pair.append(prev)
    prev = None
  else:
    prev = popped

print(find_max_rectangle(pair))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 長さと個数の辞書
length_num = Counter(A)
# 長い順からの長さのリスト
lengths = sorted(list(length_num.keys()), reverse=True)

ans = 0
sides = []

# 長い辺の順にループ
for l in lengths:
  if length_num[l] >= 4:
    ans = max(ans, l * l)
  if length_num[l] >= 2:
    sides.append(l)
  if len(sides) == 2:
    ans = sides[0] * sides[1]
    break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 長さと個数の辞書
length_num = Counter(A)
# 長い順からの長さのリスト
lengths = sorted(list(length_num.keys()), reverse=True)

ans = 0
sides = []

# 長い辺の順にループ
for l in lengths:
  if length_num[l] >= 4:
    ans = max(ans, l * l)
  elif length_num[l] >= 2:
    sides.append(l)
  if len(sides) == 2:
    ans = sides[0] * sides[1]
    break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 長さと個数の辞書
length_num = Counter(A)
# 長い順からの長さのリスト
lengths = sorted(list(length_num.keys()), reverse=True)

ans = 0
sides = []

# 長い辺の順にループ
for l in lengths:
  if len(sides) == 2:
    ans = sides[0] * sides[1]
    break
  if length_num[l] >= 4:
    ans = l * l
    break
  if length_num[l] >= 2:
    sides.append(l)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 長さと個数の辞書
length_num = Counter(A)
# 長い順からの長さのリスト
lengths = sorted(list(length_num.keys()), reverse=True)

ans = 0
sides = []

# 長い辺の順にループ
for l in lengths:
  if len(sides) == 2:
    break
  if length_num[l] >= 4:
    ans = l * l
    break
  if length_num[l] >= 2:
    sides.append(l)

if len(sides) == 2:
  ans = sides[0] * sides[1]

print(ans)

Submission status: Wrong Answer

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

x = 0
y = 0
selection = sorted(list(set(A)))[::-1]
c = collections.Counter(A)
for i in selection:
    if c[i] >= 4:
        if x == 0:
            x = i
            y = i
        elif y == 0:
            y = i
    elif c[i] >= 2:
        if x == 0:
            x = i
        elif y == 0:
            y = i
    if x != 0 and y != 0:
        print(int(x) * int(y))
        exit()

print(0)

Submission status: Wrong Answer

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

x = 0
y = 0
selection = sorted(list(set(A)))[::-1]

for i in selection:
    if A.count(i) >= 4:
        if x == 0:
            x = i
            y = i
        elif y == 0:
            y = i
    elif A.count(i) >= 2:
        if x == 0:
            x = i
        elif y == 0:
            y = i
    if x != 0 and y != 0:
        print(int(x) * int(y))
        exit()

print(x * y)

Submission status: Wrong Answer

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

edge_list =  []
selection = sorted(list(set(A)))[::-1]

for i in selection:
    edge_list += i * (A.count(i) // 2)
    if len(edge_list) >= 2:
        break
edge_list.sort()

if len(edge_list) < 2:
    print(0)
else:
    print(int(edge_list[-1]) * int(edge_list[-2]))

Submission status: Wrong Answer

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

edge_list =  []
selection = set(A)

for i in selection:
    edge_list += i * (A.count(i) // 2)
edge_list.sort()

if len(edge_list) < 2:
    print(0)
else:
    print(int(edge_list[-1]) * int(edge_list[-2]))

Submission status: Wrong Answer

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

edge_list =  []
selection = list(set(A))

for i in selection:
    edge_list += i * (A.count(i) // 2)

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

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=LI()
c=Counter(lis)
nums=[]
for i in c.keys():
    if c[i]>=2:
        nums.append(i)
nums.sort(reverse=True)
if len(nums)==0:
    print(0)
elif len(nums)==1:
    if c[nums[0]]>=4:
        print(nums[0]**2)
    else:
        print(0)
else:
    print(nums[0]*nums[1])

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=LI()
c=Counter(lis)
nums=[]
for i in c.keys():
    if c[i]>=2:
        nums.append(i)
nums.sort(reverse=True)
if len(nums)<=1:
    print(0)
else:
    print(nums[0]*nums[1])