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 math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.items():
    if count[1] >= 2:
        B.append(count[0])
B.sort(reverse=True)
if len(B) < 2:
    print(0)
else:
    print(B[0]*B[1])

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.keys():
    if counts[count] >= 2:
        B.append(count)
B.sort(reverse=True)
if len(B) < 2:
    print(0)
else:
    print(B[0]*B[1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in a:
  d[i] += 1
l = [0, 0]
for k, v in d.items():
  if v >= 2 and k >= min(l):
    l = sorted(l)
    l[0] = k
print(l[0]*l[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter
lst=list(Counter(l).items())
lst.sort(reverse=True)
num=0
for i in range(n):
    if lst[i][1]>3:
        if num==0:
            ans=lst[i][0]**2
            break
        elif num==1:
            ans*=lst[i][0]
            num+=1
            break
    elif 1<lst[i][1]<=3:
        if num==0:
            ans=lst[i][0]
            num+=1
        elif num==1:
            ans*=lst[i][0]
            num+=1
            break
    else:
        continue
if num==2:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter
import math
lst=list(Counter(l).items())
lst.sort(reverse=True)

if lst[0][1]>3:
    print(lst[0][0]**2)
elif 1<lst[0][1]<=3:
    if lst[1][1]>=2:
        print(lst[0][0]*lst[1][0])
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=input()
m=l.split(" ")
lst=[]
for i in m:
    lst.append(int(i))
lst.sort(reverse=True)
a=0
b=0
c=0
d=0
for x in lst:
    if d==x and c==0:
        a=x
        c+=1
    elif d==x and c==1:
        b=x
        c+=1
    if c==2:
        break
    d=x
print(a*b)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
l.sort(reverse=True)
num=0
ans=1
A=False
for i in range(n-1):
  if l[i]==l[i+1]:
    ans*=l[i]
    num+=1
    i=i+2
  if num==2:
    A=True
    break
if A:
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

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

ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        break
    if num >= 4:
        print(length**2)
        sys.exit()
    if num >= 2:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        break
    if num >= 4:
        print(length**2)
        exit()
    if num >= 2:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        print(ans)
        break
    if num >= 4:
        print(length**2)
        exit()
    if num >= 2:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

counter = sorted(
    Counter(A).items(),
    key=lambda x:x[0],
    reverse=True)
print(counter)
ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        print(ans)
        break
    if num >= 4:
        print(length**2)
        exit()
    if num >= 2:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        break
    if num >= 2 and ans != length:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

print(counter)

ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        break
    if num >= 2 and ans != length:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        break
    if num >= 2:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
C = [x[0] for x in C.items() if x[1] > 1]
C.sort(reverse = True)
if len(C) > 1:
    print(C[0] * C[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
C = Counter(a)
k = sorted(list(C.keys()))[::-1]
ans = []
for c in k:
    if C[c]>1:
        ans.append(c)
if len(ans)<2:
    print(0)
else:
    print(ans[0]*ans[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
C = Counter(a)
ans = [0,1]
for c in C:
    if C[c]>1 and c>min(ans):
        ans[ans.index(min(ans))] = c
if 0 in ans:
    print(0)
elif 1 in ans and C[1]<2:
    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(reverse=True)
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        a1 = a[i]
        break
    elif i == len(a)-2:
        print(0)
        exit()
    else:
        continue
b = []
for i in range(len(a)):
    if a[i] == a1:
        continue
    else:
        b.append(a[i])
b.sort(reverse=True)
for i in range(len(b)-1):
    if b[i] == b[i+1]:
        a2 = b[i]
        break
    elif i == len(b)-2:
        print(0)
        exit()
    else:
        continue
print(a1*a2)

Submission status: Wrong Answer

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

a.sort(reverse=True)
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        a1 = a[i]
        break
    elif i == len(a)-2:
        print(0)
        exit()
    else:
        continue
b = []
for i in range(len(a)):
    if a[i] == a1:
        continue
    else:
        b.append(a[i])
b.sort()
for i in range(len(b)-1):
    if b[i] == b[i+1]:
        a2 = b[i]
        break
    elif i == len(b)-2:
        print(0)
        exit()
    else:
        continue
print(a1*a2)

Submission status: Wrong Answer

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

a.sort(reverse=True)
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        a1 = a[i]
        break
    elif i == len(a)-2:
        print(0)
        exit()
    else:
        continue
b = []
for i in range(len(a)):
    if a[i] == a1:
        continue
    else:
        b.append(a[i])
for i in range(len(b)-1):
    if b[i] == b[i+1]:
        a2 = b[i]
        break
    elif i == len(b)-2:
        print(0)
        exit()
    else:
        continue
print(a1*a2)

Submission status: Wrong Answer

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

A.sort(reverse=True)

j=0
prev=A[0]

longer_edge=0

for i,a in enumerate(A+[0,0,0,0]):
  if a==prev:
    pass
  else:
    if not longer_edge:
      if (i-j)>=4:
        print(prev**2)
        exit()
      elif (i-j)>=2:
        longer_edge=prev
    elif longer_edge:
      if (i-j)>=2:
        print(prev*longer_edge)
        exit()
    prev=a
    j=i

Submission status: Wrong Answer

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

A.sort(reverse=True)

j=0
prev=A[0]

longer_edge=0

for i,a in enumerate(A):
  if a==prev:
    pass
  else:
    if not longer_edge:
      if (j-i)>=4:
        print(a**2)
        exit()
      elif (j-i)>=2:
        longer_edge=a
    elif longer_edge:
      if (j-i)>=2:
        print(a*longer_edge)
    prev=a

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
stack=a[-1]
ans=[]
for i in range(n-2,-1,-1):
  if len(ans)==2:
    break
  if a[i]==stack:
    ans.append(stack)
  else:
    stack=a[i]
if len(ans)==2:
  print(ans[0]*ans[1])
else:
  print(0)

Submission status: Wrong Answer

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

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

def array_count(arr):
    arr_target = [[]]
    cnt = 1
    for i in range(1,len(arr)):
        if arr[i] == arr[i-1]:
            cnt += 1
        else:
            arr_target.append([arr[i-1],cnt])
            cnt = 1
    arr_target.append([arr[len(arr)-1],cnt])
    del arr_target[0]
    return arr_target

a.sort()
a = array_count(a)
b = []

for i in range(len(a)):
    if a[i][1] >= 2:
        b.append(a[i][0])

b.sort()
b.reverse()

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
alist = list(map(int,input().split()))
cc = Counter(alist)
blist = []
for c in cc.items():
    if c[1] >= 2:
        blist.append(c[0])
blist.sort()
if len(blist) < 2:
    print(0)
else:
    print(blist[-1]*blist[-2])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
judge = 0
side = []
while judge != 2 and len(A) > 1:
	MAX_A = A[len(A) -1]
	if MAX_A == A[len(A) - 2]:
		side.append(MAX_A)
		judge += 1
		del A[len(A) - 1]
		del A[len(A) - 2]
	else:
		del A[len(A) -1]

if judge == 2:
	print(side[0] * side[1])
else:
	print(0)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
l = collections.Counter(a)
l_ = [k for k, v in l.items() if v > 1]
if len(l_) > 1:
    l_.sort()
    if l[-1] > 3:
        print(l_[-1]**2)
    else:
        print(l_[-1]*l_[-2])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
l = collections.Counter(a)
l_ = [k for k, v in l.items() if v > 1]
if len(l_) > 1:
    l_.sort()
    if l_[-1] > 3:
        print(l_[-1]**2)
    else:
        print(l_[-1]*l_[-2])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
l = collections.Counter(a)
l = [k for k, v in l.items() if v > 1]
if len(l) > 1:
    l.sort()
    print(l[-1]*l[-2])
else:
    print(0)

Submission status: Wrong Answer

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

from collections import Counter

C = Counter(A).most_common()
D = []
for (k,v) in C:
    if v>=2:
        D.append(k)

D.sort()

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

Submission status: Wrong Answer

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

from collections import Counter

C = Counter(A).most_common()
D = []
for (k,v) in C:
    if v>=2:
        D.append(k)

D.sort()

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
d = defaultdict(int)
ls = []
for x in A:
    d[x] += 1
    if d[x] >= 2 and d[x] < 4:
        ls.append(x)
        if len(ls) == 2:
            break
    elif d[x] == 4:
        ls.append(x)
        break
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())

A=list(map(int,input().split()))
        
A.sort(reverse=True)

X=[]

t=-1

for i in A:
    if t==i:
        t=-1
        X.append(t)
        if len(X)>1:
            break
    else:
        t=i
        
if len(X)>1:
    print(X[0]*X[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())

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

ans=1
cnt_1=0
cnt_2=0

for k,v in sorted(X.items(),key=lambda x:x[0],reverse=True):
    if k>=2:
        cnt_1+=1
        ans*=k
        if cnt_1==2:
            break
        if k>=4:
            ans*=k
            break
    else:
        cnt_2+=1
        if cnt_2==n or cnt_2==n-2 or cnt_2==n-3:
            ans=0
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())

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

ans=1
cnt_1=0
cnt_2=0

for k,v in sorted(X.items(),key=lambda x:x[0],reverse=True):
    if v>=4:
        ans=k**2
        break
    elif v>1:
        ans*=k
        cnt_1+=1
        
        if cnt_1==2:
            break
    else:
        cnt_2+=1
        
        if cnt_2==n or cnt_2==n-2 or cnt_2==n-3:
            ans=0
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())

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

ans=1
cnt_1=0
cnt_2=0

for k,v in sorted(X.items(),key=lambda x:x[0],reverse=True):
    if v>=4:
        ans=k**2
        break
    elif v>1:
        ans*=k
        cnt_1+=1
        
        if cnt_1==2:
            break
    else:
        cnt_2+=1
        
        if cnt_2==n or cnt_2==n-1:
            ans=0
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())

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

ans=1
cnt_1=0
cnt_2=0

for k,v in sorted(X.items(),key=lambda x:x[0],reverse=True):
    if v>=4:
        ans=k**2
        break
    elif v>1:
        ans*=k
        cnt_1+=1
    else:
        cnt_2+=1
        
    
    if cnt_1==2:
        break
    if cnt_2==n or cnt_2==n-1:
        ans=0
        break
     

print(ans)

Submission status: Wrong Answer

Solution code:

import collections

n=int(input())

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

ans=1
cnt_1=0
cnt_2=0

for k,v in sorted(X.items(),key=lambda x:x[0],reverse=True):
    if v>=4:
        ans=k**2
        break
    elif v>1:
        ans*=k
        cnt_1+=1
    else:
        cnt_2+=1
        
    
    if cnt_1==2:
        break
    if cnt_2==n:
        ans=0
        break
    

print(ans)

Submission status: Wrong Answer

Solution code:

import collections

n=int(input())

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

ans=1
cnt_1=0
cnt_2=0

for k,v in sorted(X.items(),key=lambda x:x[0],reverse=True):
    if v>=4:
        ans=k**2
        break
    elif v>1:
        ans*=k
        cnt_1+=1
    else:
        cnt_2+=1
        continue
    
    if cnt_1==2:
        break
    if cnt_2==n:
        ans=0
        break
    

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A).most_common()
l = 0
s = 0
for e in c:
    if e[1] >= 2 and e[0] > l:
        s = l
        l = e[0]
    elif e[1] >= 2 and e[0] > s:
        s = e[0]
print(l * s)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted((int(x) for x in input().split()), reverse = True)
a, b = 0, 0
for x in l:
  if a==x:
    continue
  m = l.count(x)
  if m>3:
    a, b = x,x
    break
  elif m>1:
    if a!=0:
      b = x
      break
    else:
      a=x
print(a*b)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted((int(x) for x in input().split()), reverse = True)
a = 0
for x in l:
  if a==x:
    continue
  m = l.count(x)
  if m>3:
    print(x*x)
    break
  elif m>1:
    if a!=0:
      print(a*x)
      break
    else:
      a=x

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
a = list(set(A))
a.reverse()
B = []
for k in range(len(a)):
    i = a[k]
    if A.count(i) >= 4:
        if len(B) == 0:
            print(i**2)
            exit()
        else:
            B.append(i)
            if len(B) >= 2:
                print(B[0]*B[1])
                exit()

    if A.count(i) >= 2:
        B.append(i)
        if len(B) >= 2:
            print(B[0]*B[1])
            exit()
if len(B) <= 1:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
a = list(set(A))
a.reverse()
B = []
for i in a:
    if A.count(i) >= 4:
        if len(B) == 0:
            print(i**2)
            exit()
        else:
            B.append(i)
            if len(B) >= 2:
                print(B[0]*B[1])
                exit()

    if A.count(i) >= 2:
        B.append(i)
        if len(B) >= 2:
            print(B[0]*B[1])
            exit()
if len(B) <= 1:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
a = sorted(list(set(A)),reverse = True)
B = []
for i in a:
    if A.count(i) >= 4:
        print(i**2)
        exit()
    if A.count(i) >= 2:
        B.append(i)
        if len(B) >= 2:
            print(B[0]*B[1])
            exit()
if len(B) <= 1:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a = Counter(A)

tmp = 1
cnt = 0
four = 0
for k, v in a.items():
  if(v >= 4):
    four = k*k
  elif(v >= 2):
    if(cnt <= 2):
      tmp *= k
      cnt += 1
    else:
      break
if(tmp == 1):
  tmp = 0
print(max(four, tmp))

Submission status: Wrong Answer

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

AS = list(set(A))
D = {}
for i in A:
    if i in D.keys():
        D[i] += 1
    else:
        D[i] = 1

accum = []
AS.sort(reverse=True)
for i in AS:
    if D[i] >= 2:
       accum.append(i)

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

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n = I()
d = defaultdict(int)
a = LI()
for i in a:
    d[i] += 1
d = list(d.items())
d.sort(key = lambda x:-x[1])
l = 0
k = 0
for i,j in d:
    if j >= 2:
        if l == 0:
            l = i
        else:
            k = i
        if j >= 4:
            k = i
    if k != 0:break
print(l*k)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n = I()
d = defaultdict(int)
a = LI()
for i in a:
    d[i] += 1
d = list(d.items())
d.sort(key = lambda x:x[1])
l = 0
k = 0
for i,j in d:
    if j >= 2:
        if l == 0:
            l = i
        else:
            k = i
        if j >= 4:
            k = i
    if k != 0:break
print(l*k)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_set = sorted(list(set(a)), reverse=True)
cnt, ans = 0, 1

for i in range(len(a_set)):
    if a.count(a_set[i]) > 3 and cnt == 0:
        print(a_set[i]**2)
    if a.count(a_set[i]) > 1:
        ans *= a_set[i]
        cnt += 1
    if cnt == 2:
        print(ans)
        exit()

print(0)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    cands = set()
    s = set()
    for i in a:
        if i in s:
            cands.add(i)
        else:
            s.add(i)
    
    x = sorted(cands, reverse=True)
    if len(x) < 2:
        return 0
    
    return x[0] * x[1]

main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a=Counter(a).most_common()
a.reverse()

ans=0
for i,j in a:
    if j>=4 and ans==0:
        ans=i*i
        break
    elif j>=2 and ans==0:
        ans=i
    elif j>=2:
        ans*=i
        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)
l=c.most_common()
ans=[]
x=len(l)
for i in range(x):
    if l[i][1]>=2:
        ans.append(l[i][0])
ans.sort()
m=len(ans)
if m<2:
    print(0)
else:
    print(ans[-2]*ans[-1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = Counter([int(i) for i in input().split()])
mt4 = []
mt2 = []
for k, v in A.items():
    if v >= 4:
        mt4.append(k)
    elif v >= 2:
        mt2.append(k)

ans = 0
if len(mt4) != 0:
    ans = max(mt4) ** 2
if len(mt2) >= 2:
    mt2.sort(reverse = True)
    ans = max(ans, mt2[0] * mt2[1])

print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python 
# -*- coding: utf-8 -*- 
#===============================================================================
# Date created  : 2019-03-02T16:27:42+09:00
# Date modified : 2019-03-02T16:30:56+09:00
# Author        : awk
# Description   : unanswered
#===============================================================================

N = int(input())
L = list(map(int,input().split()))
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c=counter(L)
c = list(filter(lambda x:x[1]>1,c))
c = sorted(c,key=lambda x:x[0])[::-1]
try:
    print(c[0][0] * c[1][0])
except:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
count = {}
for i in set(a):
    count[i] = 0
for i in a:
    count[i] += 1
    
keys = [k for k,v in count.items() if v >= 2]
keys_2 = [k for k,v in count.items() if v >= 4]

ans = -10 ** 18
if len(keys) >= 2:
    ans = sorted(keys)[-1]* sorted(keys)[-2]
if len(keys_2) >= 1:
    ans = sorted(keys_2)[-1]**2
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

count = {}
for i in set(a):
    count[i] = 0
for i in a:
    count[i] += 1
    
keys = [k for k,v in count.items() if v >= 2]

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

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

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

c = dict(Counter(A))
c = sorted(c.items(), key=lambda x: x[0])

max_one = None
max_two = None
for k, v in c[::-1]:
    if v >= 2:
        if max_one is None:
            max_one = k
        else:
            max_two = k
            break

if max_two is None:
    print(0)
else:
    print(max_one*max_two)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

n = []
count = 0

for key, value in A.items():
    if value >= 4:
        n.extend([key, key])
        break
    elif value >= 2:
        n.append(key)
        count += 1
    if count == 2:
        break
if len(n) < 2:
    print(0)
else:
    print(n[0]*n[1])

Submission status: Wrong Answer

Solution code:
#071-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
a=IL()
da={}
for l in a:
    if l in da:
        da[l]+=1
    else:
        da[l]=1
sda=sorted(da.keys(),reverse=True)
lens=[]
for l in sda:
    if da[l]>=4:
        if len(lens)==1:
            lens.append(l)
        else:
            print(l*l)
        break
    elif da[l]>=2:
        lens.append(l)
    
    if len(lens)==2:
        print(lens[0]*lens[1])
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#071-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
a=IL()
da={}
for l in a:
    if l in da:
        da[l]+=1
    else:
        da[l]=1
sda=sorted(da.keys(),reverse=True)
lens=[]
for l in sda:
    if da[l]>=4:
        print(l*l)
        break
    elif da[l]>=2:
        lens.append(l)
    
    if len(lens)==2:
        print(lens[0]*lens[1])
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n, c = int(input()), collections.Counter(sorted(list(map(int,input().split()))))
ck, cv, match, ans = list(c.keys()), list(c.values()), [], 0
for i in range(len(c)):
    if cv[i] >= 2:
        match.append([ck[i],cv[i]])
ans = match[-1][0]**2 if len(match) >= 1 and match[-1][1] >= 4 else match[-1][0]*match[-2][0] if len(match) >= 2 else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n, c = int(input()), collections.Counter(sorted(list(map(int,input().split()))))
ck, cv, match, ans = list(c.keys()), list(c.values()), [], 0
for i in range(len(c)):
    if cv[i] >= 2:
        match.append([ck[i],cv[i]])
ans = match[-1][0]**2 if len(match) >= 2 and match[-1][1] >= 4 else match[-1][0]*match[-2][0] if len(match) >= 2 else 0
print(ans)