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=list(map(int,input().split()))
ac=collections.Counter(a)

for k,i in ac.items():
"""
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
count=0
ans4=0
ans2=[0]*2
for i in range(n-1):
    #print(a[i],i)
    if a[i]==a[i+1]:
        count+=1
    if i==(n-2) or a[i]!=a[i+1]:
        if 1<=count:
            if 3<=count:
                ans4=a[i]
                ans2.append(a[i])
            else:
                ans2.append(a[i])
        count=0
ans2.sort(reverse=True)
#print(ans2)  
print(max(ans4**2,ans4*ans2[0],ans2[0]*ans2[1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

h = 0
w = 0


for i in range(N-1):
    if A.count(A[i]) >= 4:
        print(A[i]*A[i])
        exit()

    elif A[i] == A[i+1]:
        h = max(A[i], h)

    if A[i] != h:
        if A[i] == A[i+1]:
            w = A[i]
            print(h*w)
            exit()

print(0)

Submission status: Wrong Answer

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

h = 0
w = 0


for i in range(N-1):
    if A[i] == A[i+1]:
        h = A[i]
        break

for i in range(N-1):
    if A[i] != h:
        if A[i] == A[i+1]:
            w = A[i]
            print(h*w)
            exit()

for i in range(N):
    if A.count(A[i]) >= 4:
        print(A[i]*A[i])
        exit()

print(0)

Submission status: Wrong Answer

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

h = 0
w = 0


for i in range(N-1):
    if A[i] == A[i+1]:
        h = A[i]
        break

for i in range(N-1):
    if A[i] != h:
        if A[i] == A[i+1]:
            w = A[i]
            print(h*w)
            exit()

print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
dic = {}
for a in A:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
l = []
for k, v in dic.items():
  if v >= 2:
    l.append(k)
l.sort()
if len(l) < 2:
  print(0)
else:
  print(l[-1] * l[-2])

Submission status: Wrong Answer

Solution code:
def makerectangle(n , a):

    listmax = []
    a.sort(reverse=True)
    for i in range(n):
        if a.count(a[i]) > 1 and listmax.count(a[i]) == 0:
            if a.count(a[i]) > 3 and len(listmax) == 0:
                return a[i] * 2
            else:
                listmax.append(a[i])
        if len(listmax) > 1:
            return listmax[0] * listmax[1]
    return 0



def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(makerectangle(n , a))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def makerectangle(n , a):

    listmax = []
    a.sort(reverse=True)
    for i in range(n):
        if a.count(a[i]) > 1 and listmax.count(a[i]) == 0:
            listmax.append(a[i])
        if len(listmax) > 1:
            return listmax[0] * listmax[1]
    return 0



def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(makerectangle(n , a))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
a = 0
b = 0
check = -1
for i in range(n-1):
  if l[i]==l[i+1]:
    if check != i:
      if a == 0:
        a = l[i]
        check = i+1
      else:
        b = l[i]
print(a*b)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
S = collections.Counter(A)
T=[]
sq=-1;r1=-1;r2=-1
T=S.most_common()
T.sort(reverse=True,key=lambda x: x[0])
#print(T)
for i in range(len(T)):
  if T[i][1]>3:
    if sq==-1:
      sq=i
  elif T[i][1]>1:
    if r1==-1:
      r1=i
    else:
      if r2==-1:
        r2=i
#print(sq,r1,r2)
if r1!=-1 and r2!=-1:
  if sq!=-1:
    print(max(T[sq][0]**2,T[r1][0]*T[r2][0]))
  else:
    print(T[r1][0]*T[r2][0])
elif sq!=-1:
  print(T[sq][0]**2)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
S = collections.Counter(A)
T=[]
sq=-1;r1=-1;r2=-1
T=S.most_common()
T.sort(reverse=True,key=lambda x: x[0])
#print(T)
for i in range(len(T)):
  if T[i][1]>3:
    sq=i
  elif T[i][1]>1:
    if r1==-1:
      r1=i
    else:
      if r2==-1:
        r2=i
#print(sq,r1,r2)
if r1!=-1 and r2!=-1:
  if sq!=-1:
    print(max(T[sq][0]**2,T[r1][0]*T[r2][0]))
  else:
    print(T[r1][0]*T[r2][0])
elif sq!=-1:
  print(T[sq][0]**2)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
S = collections.Counter(A)
T=[]
sq=-1;r1=-1;r2=-1
T=S.most_common()
T.sort(reverse=True,key=lambda x: x[0])
#print(T)
for i in range(len(T)):
  if T[i][1]>3:
    sq=i
  elif T[i][1]>1:
    if r1==-1:
      r1=i
    else:
      r2=i
#print(sq,r1,r2)
if r1!=-1 and r2!=-1:
  if sq!=-1:
    print(max(T[sq][0]**2,T[r1][0]*T[r2][0]))
  else:
    print(T[r1][0]*T[r2][0])
elif sq!=-1:
  print(T[sq][0]**2)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
S = collections.Counter(A)
T=[]
sq=-1;r1=-1;r2=-1
T=S.most_common()
T.sort(reverse=True,key=lambda x: x[0])
#print(T)
for i in range(len(T)):
  if T[i][1]>3:
    sq=i
    break
  elif T[i][1]>1:
    if r1==-1:
      r1=i
    else:
      r2=i
      break
#print(sq,r1,r2)
if sq!=-1:
  print(T[sq][1]**2)
elif r1!=-1 and r2!=-1:
  print(T[r1][0]*T[r2][0])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
a = sorted(filter(lambda x: x[1] > 1, Counter(map(int, input().split())).items()), reverse=True)
if len(a) < 2:
    print(0)
else:
    print(a[0][0] * a[1][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = Counter(map(int,input().split()))
A1 = list(A.items())
A1 = sorted(A1,key=itemgetter(1),reverse = True)
A1 = sorted(A1,key=itemgetter(0),reverse = True)
#print(A1)

#正方形の場合
B =[]
for i in range(len(A1)):
    if A1[i][1] > 3:
        B.append(A1[i][0])
        if len(B) == 1:
            break
C =[]
for i in range(len(A1)):
    if A1[i][1] > 1:
        C.append(A1[i][0])
        if len(C) == 2:
            break

if len(C) == 0:
    print(0)
elif len(B) !=0:
    print(max(B[0]*2,C[0]*C[1]))
else:
    print(C[0]*C[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = Counter(map(int,input().split()))
A1 = list(A.items())
A1 = sorted(A1,key=itemgetter(1),reverse = True)
A1 = sorted(A1,key=itemgetter(0),reverse = True)
#print(A1)

B =[]
for i in range(len(A1)):
    if A1[i][1] > 1:
        B.append(A1[i][0])
        if len(B) == 2:
            break
print(B[0]*B[1] if len(B) != 0 else 0)

Submission status: Wrong Answer

Solution code:
a = input()
a_list = list(map(int, input().split()))
 
a_list = sorted(a_list, reverse=True)
 
big = 0
small = 0
min_a = min(a)

while True:
    max_a = max(a_list)
    counter = counter = a_list.count(max_a)
    if counter >= 4:
        if big == 0:
            big = max_a
        if small == 0:
            small = max_a
        break

    elif counter >= 2:
        if big == 0:
            big = max_a
        elif small == 0:
            small = max_a

    a_list.remove(max_a)
    if small != 0 or len(a_list) == 0:
        break

print(big*small)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
c=collections.Counter(a)
li=c.most_common(2)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve(n, A):
    c = Counter(A)
    cands = sorted(filter(lambda kv: kv[1] >= 2, c.items()),  key=lambda kv: -kv[0])
    return cands[0][0] * cands[1][0] if len(cands) >= 2 else 0

_n = int(input())
_A = map(int, input().split())
print(solve(_n, _A))

Submission status: Wrong Answer

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
set_a = list(set(a))
length = len(set(a))
b = [0 for _ in range(length)]
for i in a:
    b[set_a.index(i)] += 1

# print(b)
h = 0
w = 0

for i in range(len(b) - 1, -1, -1):
    if h != 0 and w != 0:
        break
    if b[i] >= 4:
        w = set_a[i]
        if h == 0:
            h = set_a[i]
        break
    if b[i] >= 2:
        if h == 0:
            h = set_a[i]
        else:
            w = set_a[i]
            break
    continue

print(h * w)

Submission status: Wrong Answer

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = list(map(int, input().split()))
ans = 1
cnt = 0
minimum = min(a)
maximum = max(a)
for i in range(maximum, minimum - 1, -1):
    if a.count(i) < 2:
        continue
    if cnt == 1:
        ans *= i
        cnt += 1
        break
    if a.count(i) >= 4:
        ans = i ** 2
        cnt += 1
        break
    ans *= i
    cnt += 1

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

Submission status: Wrong Answer

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = list(map(int, input().split()))
ans = 1
cnt = 0
minimum = min(a)
maximum = max(a)
for i in range(minimum, maximum + 1)[::-1]:
    if cnt == 2:
        break
    if a.count(i) < 2:
        continue
    if cnt == 1:
        ans *= i
        cnt += 1
        break
    if a.count(i) >= 4:
        ans = i ** 2
        cnt += 1
        break
    ans *= i
    cnt += 1

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

Submission status: Wrong Answer

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
c = []
for i in b:
    if a.count(i) >= 2:
        c.append(i)

ans = 1
cnt = 0

c = c[::-1]
if len(c) == 0:
    print(0)

else:
    for i in c:
        if cnt >= 2:
            break
        if a.count(i) >= 4:
            ans = i ** 2
            break
        ans *= i
        cnt += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
c = []
for i in b:
    if a.count(i) >= 2:
        c.append(i)

if len(c) == 0:
    print(0)
elif len(c) == 1:
    if a.count(c[0]) >= 4:
        print(c[0] ** 2)
else:
    print(c[-1] * c[-2])

Submission status: Wrong Answer

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
c = []
for i in b:
    if a.count(i) >= 2:
        c.append(i)
print(c)

if len(c) == 0:
    print(0)
elif len(c) == 1:
    if a.count(c[0]) >= 4:
        print(c[0] ** 2)
else:
    print(c[-1] * c[-2])

Submission status: Wrong Answer

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
c = []
for i in b:
    if a.count(i) >= 2:
        c.append(i)
# print(c)

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
a.sort()
i = 0 # a[-i-1] 
big = 0
small = 0
while True:
    if i+2 >= n+1: break
    if a[-i-1] != a[-i-2]:
        i+=1
    elif big == 0:
        big = a[-i-1]
        if i >= 4: # 見れる
            if a[-i-1] == a[-i-3]: #正方形パターン
                small = big
                break
        else:
            i += 2 # ３つ同じ長さがあるときにかぶらないように
    else:
        small = a[-i-1]
        break

print(big*small)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
a.sort()
i = 0 # a[-i-1] 
big = 0
small = 0
while True:
    if i+2 == n-1: break
    if a[-i-1] != a[-i-2]:
        i+=1
    elif big == 0:
        big = a[-i-1]
        if i >= 4: # 見れる
            if a[-i-1] == a[-i-3]: #正方形パターン
                small = big
                break
        else:
            i += 2 # ３つ同じ長さがあるときにかぶらないように
    else:
        small = a[-i-1]
        break

print(big*small)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)

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

for i in li:
  d[i] += 1

h = 0
w = 0

for i in d:
  if 4 > d[i] >= 2:
    if h >= w:
      w = i
    else:
      h = i

  elif d[i] >= 4:
    w = i
    h = i
    
print(w * h)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)

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

for i in li:
  d[i] += 1

h = 0
w = 0

for i in d:
  if 2 > d[i] / 2 >= 1:
    if h >= w:
      w = i
    else:
      h = i

  elif d[i] / 2 >= 2:
    w = i
    h = i
    
print(w * h)

Submission status: Wrong Answer

Solution code:
n = int(input())
l=list(map(int, input().split()))
l.sort(reverse=True)
t=0
for i in range(n):
    if l.count(l[i])>=4:
        print(l[i]*l[i])
        exit()
    if 2<=l.count(l[i])<4 and t==0:
        t=l[i]
    elif 2<=l.count(l[i])<4 and t>=1 and t!=l[i]:
        print(t*l[i])
        exit()


print(0)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
f=-1
a1=-1
a2=-1
ans=0
S = collections.Counter(A)
T=[]
T=S.most_common()
T.sort(reverse=True,key=lambda x: x[0])
for i in range(len(T)):
  if T[i][1]>=4:
    f=i
  elif T[i][1]>=2:
    if a1!=-1:
      a2=i
    else:
      a1=i


if f!=-1:
  ans=max(T[f][0]**2,ans)
if a1!=-1 and a2!=-1:
  ans=max(T[a1][0]*T[a2][0],ans)
if f>=6 and a1!=-1:
  ans=max(T[f][0]*T[a1][0],ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
f=-1
a1=-1
a2=-1
ans=0
S = collections.Counter(A)
T=[]
T=S.most_common()
T.sort(reverse=True,key=lambda x: x[0])
for i in range(len(T)):
  if T[i][1]>=4:
    f=i
  elif T[i][1]>=2:
    if a1!=-1:
      a2=i
      break
    else:
      a1=i

#print(T)
#print(f,a1,a2)
if f!=-1:
  print(T[f][0]**2)
elif a1!=-1 and a2!=-1:
  print(T[a1][0]*T[a2][0])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = {}
for i in a:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1
count = [i for i, j in count.items() if j>1]
count.sort(reverse=True)
if len(count)<2:
  print(0)
else:
  print(count[0]*count[1])

Submission status: Wrong Answer

Solution code:
import collections
import heapq
n = int(input())
p = list(map(int, input().split()))
c = collections.Counter(p)
cond = 0
h = []
for line, cnt in c.most_common():
  if(cnt >= 2):
    heapq.heappush(h, int(-1*line))
if(len(h) < 2):
  print(0)
  exit()
print(heapq.heappop(h) * heapq.heappop(h))

Submission status: Wrong Answer

Solution code:
D = {}
N = int(input())
A = list(map(int, input().split()))
Rec = []
Sq = []
for i in A:
  if i in D:
    D[i] += 1
  else:
    D[i] = 1
for i in D:
  if D[i] >= 4:
    Sq.append(i)
  if D[i] >= 2:
    Rec.append(i)
Rec.sort(reverse=True)
if len(Rec) <= 1 and len(Sq) == 0:
  print(0)
elif len(Sq) != 0 and len(Rec) >= 2:
  print(max(Rec[0] * Rec[1], Sq[0]))
elif len(Sq) == 0 and len(Rec) >= 2:
  print(Rec[0] * Rec[1])

Submission status: Wrong Answer

Solution code:
n=int(input())

a=sorted(list(map(int,input().split())),reverse=True)

stack=-1
t=[]
for i in a:
    if stack==i:
        t.append(i)
        stack=-1
    stack=i
    
    if len(t)>=2:
        break
try:
    print(t[0]*t[1])
except:
    print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnt=1
ans=[]
for i in range(N-1):
    #print(cnt,ans)
    if A[i]==A[i+1] and cnt<2:
        cnt+=1
    elif cnt==2:
        ans.append(A[i-1])
        cnt=1
        if len(ans)==2:
            break
#print(A)
if len(ans)<=1:
    print(0)
else:
    print(ans[0]*ans[1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnt=1
ans=[]
for i in range(N-1):
    #print(cnt,ans)
    if A[i]==A[i+1]:
        cnt+=1
    elif cnt>=2:
        ans.append(A[i-1])
        cnt=1
        if len(ans)==2:
            break
#print(A)
if len(ans)<=1:
    print(0)
else:
    print(ans[0]*ans[1])

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int, input().split()))
edge = collections.Counter(A)
a = 0
b = 0
for i in sorted(edge.items()):
    if i[1] >= 2:
        if i[0] > a:
            b = a
            a = i[0]

print(a * b)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int, input().split()))
edge = collections.Counter(A)
a = 0
b = 0
for i in edge.items():
    if i[1] >= 2:
        if i[0] > a:
            b = a
            a = i[0]

print(a * b)

Submission status: Wrong Answer

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

cnt = {}

for a in A:
    cnt.setdefault(a, 0)
    cnt[a] += 1

cnt_filter = list(filter(lambda x: x[1] >= 2, cnt.items()))
cnt_filter.sort(key=lambda x: x[0], reverse=True)

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

from collections import Counter
a=Counter(a).most_common()

li=[] #2本以上あるもの
li4=[] #4本以上あるもの

for x,y in a:
  if  y>=4:
    li4.append(x)
  elif y>=2:
    li.append(x)

li.sort()
li4.sort()

x=0
y=0

if li4:
  x=li4[-1]**2
if len(li)>=2:
  y=li[-1]*li[-2]

print(max(x,y))

Submission status: Wrong Answer

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

from collections import Counter
a=Counter(a).most_common()

li=[]
li4=[]

for x,y in a:
  if  y>=4:
    li4.append(x)
  elif y>=2:
    li.append(x)

li.sort()
li4.sort()

if len(li)<2:
  print(0)
  exit()

x=0
if li4:
  x=(li4[-1])**2

y=li[-1]*li[-2]

print(max(x,y))

Submission status: Wrong Answer

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

from collections import Counter
a=Counter(a).most_common()

li=[]
li4=[]

for x,y in a:
  if  y>=4:
    li4.append(x)
  elif y>=2:
    li.append(x)

li.sort()
li4.sort()

if len(li)<2:
  print(0)
  exit()

x=0
if li4:
  x=(li4[-1])**2

y=li[-1]*li[-2]
print(max(x,y))

Submission status: Wrong Answer

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

from collections import Counter
a=Counter(a).most_common()

li=[]

for x,y in a:
  if y>=2:
    li.append(x)

li.sort()

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

Submission status: Wrong Answer

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

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

nums = sorted([num for num, freq in d.items() if freq >= 2])
if len(nums) >= 2:
    print(nums[-1] * nums[-2])
else:
    print(0)

Submission status: Wrong Answer

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

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

nums = [num for num, freq in d.items() if freq >= 2]
if len(nums) >= 2:
    print(nums[-1] * nums[-2])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
l = 0
m = 0
while len(A) >= 2:
    a = A.pop()
    b = A.pop()
    if a == b:
        if l == 0:
            l = a
        elif m == 0:
            m = a
print(l * m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
l = 0
m = 0
while len(A) >= 2:
    a = A.pop()
    b = A.pop()
    if a == b:
        if l == 0:
            l = a
        else:
            m = a
            break
print(l * m)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    d[An[i]] += 1

w, h = 0, 0
for num, amount in sorted(d.items(), key=lambda x: x[0], reverse=True):
    if amount >= 4:
        w, h = num, num
        break
    elif amount >= 2:
        if not w:
            w = num
        else:
            h = num
            break

print(w*h)

Submission status: Wrong Answer

Solution code:
num = int(input())

arr = {}
for i in input().split(" "):
	i = int(i)
	if arr.get(i, False):
		arr[i] += 1
	else:
		arr[i] = 1

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

side = []

for key in arr:
	if arr[key] >= 2:
		side.append((key, arr[key]))

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

Submission status: Wrong Answer

Solution code:
num = int(input())

arr = {}
for i in input().split(" "):
	i = int(i)
	if arr.get(i, False):
		arr[i] += 1
	else:
		arr[i] = 1

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

side = []

for key in arr:
	if arr[key] >= 2:
		side.append(key)

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

Submission status: Wrong Answer

Solution code:
num = int(input())

arr = {}
for i in input().split(" "):
	i = int(i)
	if arr.get(i, False):
		arr[i] += 1
	else:
		arr[i] = 1

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

side = []

for key in arr:
	if arr[key] >= 2:
		side.append(key)

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

Submission status: Wrong Answer

Solution code:
num = int(input())

arr = {}
for i in input().split(" "):
	i = int(i)
	if arr.get(i, False):
		arr[i] += 1
	else:
		arr[i] = 1

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


side = []

for key in arr:
	if arr[key] >= 2:
		side.append(key)

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

Submission status: Wrong Answer

Solution code:

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

from collections import Counter

ans = []

for (key, value) in Counter(A).most_common():
  if value >=2:
    ans.append(key)

if len(ans) <= 1:
  print(0)
else:
  ans = sorted(ans, reverse=True)
  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).items()
f=0
s=0
for k,v in c:
    if v>=4:
        if v>f:
            s=v
            f=v
        elif v>s:
            s=v
    if v>=2:
        if v>f:
            s=f
            f=v
        elif v>s:
            s=v

print(s*f)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A.sort(reverse=True)
A = Counter(A)
ans = 1
for k in sorted(A, reverse=True):
	if A[k] >= 2:
		if ans == 1:
			ans *= k
		else:
			ans *= k
			break
else:
	ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
HW = []
PCN = [-1]*3
for i in range(1,N):
  PCN[:1]=PCN[1:]
  PCN[2]=A[i]
  if PCN[2]==PCN[1] and PCN[1]!=PCN[0]:
    n = A.count(A[i])
    HW += [A[i]]*(n//2)
  if len(HW)>=2:
    break
HW = HW + [0,0]
print(HW[0]*HW[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
#A.sort(reverse = True)
Al=list(set(A))
Al.sort(reverse = True)
HW = []
for i in Al:
  n = A.count(i)
  for j in range(min(n//2,2)):
    HW.append(i)
  if len(HW)>=2:
    break
  HW = HW + [0,0]
print(HW[0]*HW[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
list1 = [int(x) for x in input().split()]


list2 = list(reversed(sorted(list1)))


m = list2[0]


ans = []

for i in range(1, len(list2)):
  if list2[i] == m:
    ans.append(m)
  if len(ans) == 2:
    break
  m = list2[i]


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

Submission status: Wrong Answer

Solution code:
n = int(input())
list1 = [int(x) for x in input().split()]


set1 = set(list1)


listans = []

for i in set1:
  if list1.count(i) > 1 and list1.count(i) < 4:
    listans.append(i)
  elif list1.count(i) >3:
    listans.append(i)
    listans.append(i)


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

Submission status: Wrong Answer

Solution code:
n = int(input())
list1 = [int(x) for x in input().split()]
set1 = set(list1)
listans = []

for i in set1:
  if list1.count(i) > 1:
    listans.append(i)

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

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 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 S(): return input()
def main():
    N = I()
    A = LI()
    d = collections.OrderedDict()
    A = sorted(A)[::-1]
    for a in A:
        if not a in d:
            d[a] = 1
        else:
            d[a] += 1
    l_num = -1
    ans = 0
    for num, freq in d.items():
        if freq < 2:
            continue
        elif 2 <= freq < 4:
            if l_num == -1:
                l_num = num
            else:
                ans = l_num * num
                break
        else:
            ans = num * num
            break
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 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 S(): return input()
def main():
    N = I()
    A = LI()
    d = collections.OrderedDict()
    A = sorted(A)[::-1]
    for a in A:
        if not a in d:
            d[a] = 1
        else:
            d[a] += 1
    l_num = -1
    ans = 0
    for num, freq in d.items():
        if freq < 2:
            continue
        elif 2<= freq < 4:
            if l_num == -1:
                l_num = num
            else:
                ans = l_num * num
                break
        else:
            ans = num * 2
            break
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
import collections

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

C = collections.Counter(A)

num = []

for k,v in C.items():
    if (v>=2):
        num.append(k)

num.sort(reverse=True)

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

Submission status: Wrong Answer

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

cc = collections.Counter(a)
cc = sorted(dict(filter(lambda x: x[1] > 1, cc.items())), reverse=True)

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

Submission status: Wrong Answer

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

ans = 0
for i in range(n-3):
    r = a[i:i+4]
    if r[0] == r[1] and r[2] == r[3]:
        ans = max(ans, r[0]*r[2])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])
print(ans_lis)
if not ans_lis:
    print(0)
    sys.exit()

if len(ans_lis) == 1 and ans_lis[0][1] < 4:
    print(0)
elif len(ans_lis) == 1 and ans_lis[0][1] >= 4:
    print(ans_lis[0][0] ** 2)
elif len(ans_lis) >= 2:
    area_1 = ans_lis[0][0] * ans_lis[1][0]
    area_2 = 0
    if ans_lis[0][1] >= 4:
        area_2 = ans_lis[0][0] ** 2
    print(max(area_1, area_2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if ans_lis is None:
    print(0)
    sys.exit()

if len(ans_lis) == 1 and ans_lis[0][1] < 4:
    print(0)
elif len(ans_lis) == 1 and ans_lis[0][1] >= 4:
    print(ans_lis[0][0] ** 2)
elif len(ans_lis) >= 2:
    area_1 = ans_lis[0][0] * ans_lis[1][0]
    area_2 = 0
    if ans_lis[0][1] >= 4:
        area_2 = ans_lis[0][0] ** 2
    print(max(area_1, area_2))