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:
n=int(input())
A=list(map(int,input().split()))
ans1=0
ans2=0
A.sort(reverse=True)
for i in range(n-1):
  if i < n-1 and A[i+1] == A[i]:
    i += 1
    if A[i] >= ans1:
      ans2 = ans1
      ans1 = A[i]
    elif A[i] > ans2:
      ans2 =A[i]
print(ans1*ans2)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans1=0
ans2=0
A.sort(reverse=True)
for i in range(n-1):
  i += 1
  if i < n-1 and A[i+1] == A[i]:
    if A[i] >= ans1:
      ans2 = ans1
      ans1 = A[i]
    elif A[i] > ans2:
      ans2 =A[i]
print(ans1*ans2)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans1=0
ans2=0
A.sort(reverse=True)
for i in range(n-1):
  i += 1
  if i < n-1 and A[i+1] == A[i]:
    if A[i] > ans1:
      ans2 = ans1
      ans1 = A[i]
    elif A[i] > ans2:
      ans2 =A[i]
print(ans1*ans2)

Submission status: Wrong Answer

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

d={}

for n in range(N):
    if d.get(A[n])==None:
        d[A[n]]=1
    else:
        d[A[n]]+=1

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

cnt=0
ans=0
for i in range(len(d)):
    if cnt==0:
        if d[i][1]>=4:
            ans=d[i][0]**2
        elif d[i][1]>=2:
            temp=d[i][0]
            cnt+=1
    else:
        if d[i][1]>=2:
            ans=temp*d[i][0]
            break
print(ans)

Submission status: Wrong Answer

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

d={}

for n in range(N):
    if d.get(A[n])==None:
        d[A[n]]=1
    else:
        d[A[n]]+=1

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

cnt=0
ans=0
for i in range(len(d)):
    if d[i][1]>=4:
        ans=d[i][0]**2
        break
    else:
        if cnt==0:
            if d[i][1]>=2:
                temp=d[i][0]
                cnt+=1
        else:
            if d[i][1]>=2:
                ans=temp*d[i][0]
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()

    a.sort()

    l = []
    start = a[0]
    cnt = 1
    for i in a:
        if i == start:
            cnt += 1
        else:
            start = i
            cnt = 1
        if cnt == 2:
            l.append(i)
    if cnt == 2:
        l.append(i)
    if len(l) < 2:
        print(0)
    else:
        print(l[-1]*l[-2])



if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


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

    Num = [0] * N

    l1 = l2 = 0
    print(l1*l2)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=reverse)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictsort(dict,reverse=False):
    return sorted( dict.items(), reverse=reverse )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

for i in range(n):
    ddict[ a[i] ] += 1

d = mydictsort(ddict,reverse=True)
# print(d)

h = 0
w = 0
for i in range(len(ddict)):
    if d[i][1]>=2:
        if h==0:
            h = d[i][0]
        elif w==0:
            w = d[i][0]

if h!=0 and w!=0:
    print(w*h)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(al)

l4 = []
l2 = []

for k, v in c.items():
    if v >= 4:
        l4.append(k)
        l2.append(k)
    elif v >= 2:
        l2.append(k)

s1, s2 = 0, 0
l4 = sorted(l4, reverse=True)
l2 = sorted(l2, reverse=True)

if len(l4) >= 1:
    s1 = l4[0]*2
if len(l2) >= 2:
    s2 = l2[0] * l2[1]

if s1 != 0 or s2 != 0:
    print(max(s1, s2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(al)

l4 = []
l2 = []

for k, v in c.items():
    if v >= 4:
        l4.append(k)
    elif v >= 2:
        l2.append(k)

s1, s2 = 0, 0
l4 = sorted(l4, reverse=True)
l2 = sorted(l2, reverse=True)

if len(l4) > 0:
    s1 = l4[0]*2
if len(l2) >= 2:
    s2 = l2[0] * l2[1]

if s1 != 0 or s2 != 0:
    print(max(s1, s2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(al)

l4 = []
l2 = []

for k, v in c.items():
    if v >= 4:
        l4.append(k)
    elif v >= 2:
        l2.append(k)

s1, s2 = 0, 0

if len(l4) > 0:
    s1 = l4[0]*2
if len(l2) >= 2:
    s2 = l2[0] * l2[1]

if s1 != 0 or s2 != 0:
    print(max(s1, s2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(al)

print(c)

l4 = []
l2 = []

for k, v in c.items():
    if v >= 4:
        l4.append(k)
    elif v >= 2:
        l2.append(k)

s1, s2 = 0, 0

if len(l4) > 0:
    s1 = l4[0]*2
if len(l2) >= 2:
    s2 = l2[0] * l2[1]

if s1 != 0 or s2 != 0:
    print(max(s1, s2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
input()
one=[]
two=[]
for i in input().split(' '):
    if i not in two:
        if i in one:
            two.append(i)
        else:
            one.append(i)
two.sort()
print(int(two[-1])*int(two[-2]) if len(two) else 0)

Submission status: Wrong Answer

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

for i in range(n):
  dic[a[i]] += 1
ans = 0
ls = list(dic.keys())
ls.sort()
ans_ls = []

for i in range(len(ls)-1,-1,-1):
  if dic[ls[i]] >= 2:
    ans_ls.append(ls[i])
if len(ans_ls) < 2:
  print(0)
else:
  print(ans_ls[0] * ans_ls[1])

Submission status: Wrong Answer

Solution code:
from collections import *
n=int(input())
l=list(map(int,input().split()))
d=defaultdict(int)
for i in l:
    d[i]+=1
x,y=[],[]
for i in d:
    if(d[i]>=2 and d[i]<4):
        x.append(i)
    elif(d[i]>=4):
        y.append(i)
xx,yy=0,0
x.sort()
y.sort()
if(len(x)>1):
    xx=x[-1]*x[-2]
if(len(y)>0):
    yy=y[-1]*y[-1]
print(max(0,xx,yy))

Submission status: Wrong Answer

Solution code:
from collections import *
n=int(input())
l=list(map(int,input().split()))
d=defaultdict(int)
for i in l:
    d[i]+=1
x,y=[],[]
for i in d:
    if(d[i]>=2 and d[i]<4):
        x.append(i)
    elif(d[i]>=4):
        y.append(i)
xx,yy=0,0
if(len(x)>1):
    xx=x[-1]*x[-2]
if(len(y)>0):
    yy=y[-1]*y[-1]
print(max(0,xx,yy))

Submission status: Wrong Answer

Solution code:
from collections import *
n=int(input())
l=list(map(int,input().split()))
d=defaultdict(int)
for i in l:
    d[i]+=1
x,y=[],[]
for i in d:
    if(d[i]>=2 and d[i]<4):
        x.append(i)
    elif(d[i]==4):
        y.append(i)
xx,yy=0,0
if(len(x)>1):
    xx=x[-1]*x[-2]
if(len(y)>0):
    yy=y[-1]*y[-1]
print(max(0,xx,yy))

Submission status: Wrong Answer

Solution code:
from collections import *
n=int(input())
l=list(map(int,input().split()))
d=defaultdict(int)
for i in l:
    d[i]+=1
x,y=[],[]
for i in d:
    if(d[i]==2):
        x.append(i)
    elif(d[i]==4):
        y.append(i)
xx,yy=0,0
if(len(x)>1):
    xx=x[-1]*x[-2]
if(len(y)>0):
    yy=y[-1]*y[-1]
print(max(0,xx,yy))

Submission status: Wrong Answer

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

counter = dict(Counter(A))
tmp = []
for num in counter.keys():
    if counter[num] >= 2:
        tmp.append(num)
if len(tmp) < 2:
    print(0)
else:
    tmp.sort(reverse=True)
    print(tmp[0] * tmp[1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
from collections import Counter
from typing import Tuple
counter = dict(Counter(A))
tmp = []
for num in counter.keys():
    if counter[num] >= 2:
        tmp.append(num)
if len(tmp) < 2:
    print(0)
else:
    tmp.sort(reverse=True)
    print(tmp[0] * tmp[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
hoge=list(map(int,input().split()))
hoge.sort()
huga=list(set(hoge))
hav2=[]
hav4=[]
for i in range(len(huga)):
  tmp=(hoge.count(huga[i]))
  if(tmp>=2):
    hav2.append(huga[i])
  if(tmp>=4):
    hav4.append(huga[i])

ans=[0]
if(len(hav2)>=2):
  ans.append(hav2[-1]*hav2[-2])
if(len(hav4)>=1):
  ans.append(hav4[-1]*hav4[-1])
  
print(max(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ca = Counter(A)
ca = sorted(ca.items(), key=lambda x:-x[0])
cnt = 0
m = []
for k, v in ca:
  if v >= 2:
    cnt += 1
    m += [k]
  if cnt >= 2:
    break

if len(m) <= 1:
  print(0)
  exit()
print(m[0]*m[1])

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=c.keys()
B=c.values()
R = zip(A,B)
R=sorted(R,reverse=True)
a, b = zip(*R)
if b[0]>=4:
  print(a[0]**2)
else:
  print(a[0]*a[1])

Submission status: Wrong Answer

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

A.sort(reverse=True)
l1 = 0
c1 = 0
l2 = 0
c2 = 0

L1 = 0
L2 = 0

for i in range(len(A)):
  print(" ".join([str(s) for s in [i, l1, c1, l2, c2, L1, L2]]))
  if L1 and L2:
    break
  elif L1:
    if l2 == A[i]:
      c2 += 1
    elif l2 != A[i]:
      l2 = A[i]
      c2 = 1
    if c2 == 2:
      L2 = l2
  else:
    if l1 == A[i]:
      c1 += 1
    elif l1 != A[i]:
      l1 = A[i]
      c1 = 1
    if c1 == 2:
      L1 = l1

print(L1 * L2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in range(n):
    dic.setdefault(a[i],0)
    dic[a[i]] += 1
ans = []
for item in dic.items():
    if item[1]>=2:
        ans.append(item[0])
if len(ans)<=1:
    print(0)
else:
    ans.sort()
    print(ans[-1]*ans[-2])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
s=set()
l=[]
for i in A:
    if i in s and not i in l:
        l.append(i)
    else:
        s.add(i)
l.sort()
print(0 if len(l)<2 else l[-1]*l[-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
xy = []
a = sorted(a.items(), key=lambda x: x[0], reverse=True)
for i in a:
    if len(xy) == 2:
        break
    if i[1] >= 4:
        xy.append(i[0])
        xy.append(i[0])
        break
    if i[1] >= 2:
        xy.append(i[0])

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
xy = []
a = sorted(a.items(), key=lambda x: x[0], reverse=True)
for i in a:
    if len(xy) == 2:
        break
    if i[1] >= 4:
        xy.append(i[0])
    if i[1] >= 2:
        xy.append(i[0])

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
xy = []
a = sorted(a.items(), key=lambda x: x[0], reverse=True)
for i in a:
    if len(xy) == 2:
        break
    if i[1] >= 2:
        xy.append(i[0])
    else:
        pass
print(xy[0] * xy[1]) if len(xy) == 2 else print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
xy = [0] * 2
for i in a.items():
    if i[1] >= 2:
        if i[0] > xy[0] and i[0] > xy[1]:
            xy[1] = xy[0]
            xy[0] = i[0]
        elif i[0] > xy[1]:
            xy[1] = i[0]
    else:
        pass
print(xy[0] * xy[1]) if xy[0] != 0 and xy[1] != 0 else print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
xy = [0] * 2
for i in a.items():
    if i[1] >= 2:
        if i[0] > xy[0] and i[0] > xy[1]:
            xy[1] = xy[0]
            xy[0] = i[0]
        elif i[0] > xy[1]:
            xy[1] = i[0]
    else:
        pass
print(xy[0] * xy[1]) if all(xy) else print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
xy = [0]*2
for i in a.items():
    if i[1] >= 2:
        if i[0] > xy[0] and i[0] > xy[1]:
            if i[0] > xy[1]:
                xy[1] = xy[0]
            xy[0] = i[0]
        elif i[0] > xy[1]:
            xy[1] = i[0]
    else:
        pass
print(xy[0]*xy[1]) if all(xy) else print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)
mc=[]
for k in c.keys():
  if c[k]>=2:mc.append(k)
    
if len(mc)<2:
  print(0)
  exit()
  
mc = sorted(mc,reverse=True)
print(mc[0]*mc[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
i = 0
c = 0
x = 0
y = 0 
while i < len(a) - 1:
	if a[i] == a[i+1] and c == 0:
		x = a[i]
		c += 1
	if a[i] == a[i+1] and c == 1 and a[i] != x:
		y = a[i]
		break
	i += 1
if x != 0 and y != 0:
	print(x*y)
else:
	print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

A.sort(reverse=True)

for i in A:
  D[i] += 1

cnt1 = 0
ans1 = 1
cnt2 = 0
ans2 = 1

for i, x in D.items():
  if x >= 4:
    ans2 *= i**2
    cnt2 += 2
  if x >= 2:
    ans1 *= i
    cnt1 += 1
  if cnt1 == 2:
    print(max(ans1, ans2))
    exit()

if cnt2 == 2:
  print(ans2)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

A.sort(reverse=True)

for i in A:
  D[i] += 1

cnt = 0
ans = 1

for i, x in D.items():
  if x >= 2:
    ans *= i
    cnt += 1
  if cnt == 2:
    print(ans)
    exit()

print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
from collections import Counter
CA = Counter(A)
CA = sorted(CA.items(), key=lambda x: x[0], reverse=True)

maxa = 0
for v, c in CA:
    if 2 <= c <= 3:
        if maxa == 0:
            maxa = v
        else:
            print(maxa*v)
            break
    elif 4 <= c:
        print(v*v)
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
  if a.count(a[i]) >= 2 and a[i] not in l:
    l.append(a[i])
l.sort()
print(a[-1]*a[-2])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

A.sort()

s1 = 0
s2 = 0

at = -1
atc = 0

for a in A:
    if at == a:
        atc += 1

    else:
        if atc >= 4:
            s1 = at
            s2 = at
        elif atc >= 2:
            s2 = s1
            s1 = at
        
        at = a
        atc = 0

if atc >= 4:
    s1 = at
    s2 = at
elif atc >= 2:
    s2 = s1
    s1 = at

print(s1 * s2)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

adic = {}

for a in A:
    if a in adic:
        adic[a] += 1
    else:
        adic[a] = 1

t1 = 0
t2 = 0

for obj in adic:
    if adic[obj] >= 4:
        t1 = obj
        t2 = obj
    elif adic[obj] >= 2:
        t2 = t1
        t1 = obj

print(t1 * t2)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

adic = {}

for a in A:
    if a in adic:
        adic[a] += 1
    else:
        adic[a] = 1

t1 = 0
t2 = 0

for obj in adic:
    if adic[obj] // 4 >= 1:
        t1 = obj
        t2 = obj
    elif adic[obj] // 2 >= 1:
        t2 = t1
        t1 = obj

print(t1 * t2)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

adic = {}

for a in A:
    if a in adic:
        adic[a] += 1
    else:
        adic[a] = 1

t = 0

for obj in reversed(adic):
    if adic[obj] // 4 >= 1:
        if t != 0:
            print(t * obj)
            exit()
        else:
            print(obj ** 2)
            exit()
    elif adic[obj] // 2 >= 1:
        if t != 0:
            print(t * obj)
            exit()
        else:
            t = obj

print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

adic = {}

for a in A:
    if a in adic:
        adic[a] += 1
    else:
        adic[a] = 1

print(adic)

t = 0

for obj in reversed(adic):
    if adic[obj] // 4 >= 1:
        if t != 0:
            print(t * obj)
            exit()
        else:
            print(obj ** 2)
            exit()
    elif adic[obj] // 2 >= 1:
        if t != 0:
            print(t * obj)
            exit()
        else:
            t = obj

print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

adic = {}

for a in A:
    if a in adic:
        adic[a] += 1
    else:
        adic[a] = 1

t = 0

for obj in reversed(adic):
    if adic[obj] // 4 >= 1:
        print(obj ** 2)
        exit()
    elif adic[obj] // 2 >= 1:
        if t != 0:
            print(t * obj)
            exit()
        else:
            t = obj

print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
d={}
for a in l:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
ks=sorted(d,reverse=True)
f=0
for i,k in enumerate(ks):
    if d[k]>=2:
        f=k
        break
s=0
for k in ks[i+1:]:
    if d[k]>=2:
        s=k
        break
print(f*s)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = sorted(collections.Counter(int(T) for T in input().split()).most_common(),reverse=True)
Flag = False
LS = 0
SS = 0
for T in range(0,len(A)):
    if A[T][1]>=4:
        Sq = A[T][0]**2
        Flag = True
        break
    if 2<=A[T][1]<=3:
        if LS==0:
            LS = A[T][0]
        else:
            SS = A[T][0]
            Sq = LS*SS
            Flag = True
            break
if Flag:
    print(Sq)
else:
    print(0)

Submission status: Wrong Answer

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

a.sort(reverse=True)

width = 0
height = 0
i = 0
while i < n-2:
    i += 1
    if a[i] == a[i+1]:
        if width == 0:
            width = a[i+1]
            i += 1
        elif height == 0:
            height = a[i+1]
            break
print(width * height)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    counter = Counter(A)
    vec = [k for k, v in counter.items() if v >= 2]
    vec.sort()

    if len(vec) >= 2:
        ans = vec[-2] * vec[-1]

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import collections

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

count = collections.Counter(AN)


edge1 = 0
edge2 = 0
for c in sorted(count.keys(),reverse=True):
  if count[c] >= 4:
    if edge1 == 0:
      print(c*c)
      sys.exit()
    else:
      edge1 == c
  elif count[c] >= 2:
    if edge1 == 0:
      edge1 = c
    else:
      print(edge1*c)
      sys.exit()
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys
import collections

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

count = collections.Counter(AN)


edge1 = 0
edge2 = 0
for c in sorted(count.keys(),reverse=True):
  if count[c] >= 4:
    print(c*c)
    sys.exit()
  elif count[c] >= 2:
    if edge1 == 0:
      edge1 = c
    else:
      print(edge1*c)
      sys.exit()
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
pin=a[0]
cnt=1
x=[]
for i in range(1,n):
  if a[i]==pin:
    cnt+=1
  else:
    if cnt>=4:
      x+=[pin]
      x+=[pin]
    elif cnt>=2:
      x+=[pin]
    if len(x)>=2:
      break
    pin=a[i]
    
if len(x)<=1:
  print(0)
else:
  print(x[0]*x[1])

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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

A = collections.Counter(A).most_common()
N = len(A)

ans = [0]

for i in range(N):
    if A[i][1] >= 4:
        ans.append(A[i][0]**2)

ref = []
for j in range(N):
    if A[j][1] >= 2:
        ref.append(A[j][0])

if len(ref) >= 2:
    ans.append(ref[-2]*ref[-1])

print(max(ans))

Submission status: Wrong Answer

Solution code:
import collections

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

A = collections.Counter(A).most_common()
N = len(A)

ans = [0]

for i in range(N):
    if A[i][1] >= 4:
        ans.append(A[i][0]**2)

ref = []
for j in range(N):
    if A[i][1] >= 2:
        ref.append(A[i][0])

if len(ref) >= 2:
    ans.append(ref[0]*ref[1])

print(max(ans))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
box = []
acnt =dict(Counter(a))
acnt = sorted(acnt.items(), key=lambda x:x[0],reverse=True)
#print(acnt)
a_val =[acnt[x][1] for x in range(len(acnt))]
a_key = [acnt[y][0] for y in range(len(acnt))]
#print(a_key,a_val)
for i in range(len(a_val)):
	if a_val[i] >= 4:
		print(a_key[i]**2)
		sys.exit()
	elif 2 <= a_val[i]:
		box.append(a_key[i])
		#print(box)
		if len(box) == 2:
			print(box[0]*box[1])
			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()))
box = []
acnt = dict(Counter(a))
acnt = sorted(acnt.items(), key=lambda x:x[0],reverse=True)
#print(acnt)
a_val = [acnt[x][1] for x in range(len(acnt))]
a_key = [acnt[y][0] for y in range(len(acnt))]
#print(a_key,a_val)
for i in range(len(a_val)):
	if a_val[i] >= 4:
		print(a_key[i]**2)
		sys.exit()
	elif 2 <= a_val[i] < 4:
		box.append(a_key[i])
box.sort(reverse=True)
if len(box) >= 2:
    print(box[0]*box[1])
    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()))
box = []
acnt =dict(Counter(a))
acnt = sorted(acnt.items(), key=lambda x:x[0],reverse=True)
#print(acnt)
a_val =[acnt[x][1] for x in range(len(acnt))]
a_key = [acnt[y][0] for y in range(len(acnt))]
#print(a_key,a_val)
for i in range(len(a_val)):
	if a_val[i] >= 4:
		print(a_key[i]**2)
		sys.exit()
	elif 2 <= a_val[i] < 4:
		box.append(a_key[i])
		#print(box)
		if len(box) == 2:
			print(box[0]*box[1])
			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()))
box = []
acnt = Counter(a)
a_val = list(acnt.values())
a_val.reverse()
a_key = list(acnt.keys())
a_key.reverse()
#print(a_key,a_val)
for i in range(len(a_val)):
	if a_val[i] >= 4:
		print(a_key[i]**2)
		sys.exit()
	elif 2 <= a_val[i] < 4:
		box.append(a_key[i])
		#print(box)
		if len(box) == 2:
			print(box[0]*box[1])
			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()))
box = []
acnt = Counter(a)
a_val = list(acnt.values())
#a_val.sort(reverse=True)
a_key = list(acnt.keys())
#a_key.sort(reverse=True)
#print(a_key,a_val)
for i in range(len(a_val)):
	if a_val[i] >= 4:
		print(a_key[i]**2)
		sys.exit()
	elif 2 <= a_val[i] < 4:
		box.append(a_key[i])
		if len(box) == 2:
			print(box[0]*box[1])
			sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
box = []
acnt = Counter(a)
a_val = list(acnt.values())
#a_val.sort(reverse=True)
a_key = list(acnt.keys())
#a_key.sort(reverse=True)
#print(a_key,a_val)
for i in range(len(a_val)):
	if a_val[i] >= 4:
		print(a_key[i]**2)
		sys.exit()
	elif 2 <= a_val[i] < 4:
		box.append(a_key[i])
		print(box)
		if len(box) == 2:
			print(box[0]*box[1])
			sys.exit()

Submission status: Wrong Answer

Solution code:
import collections

N, *X,=map(int, open(0).read().split())
c=collections.Counter(X)
l=sorted(c.items(), key=lambda x: x[0])
x=0
for i in l[::-1]:
    if i[1]>3:
        print(i[0]*i[0])
        exit(0)
    elif i[1]>1:
        if x:
            print(i[0]*x)
            exit(0)
        else:
            x=i[0]
print(0)

Submission status: Wrong Answer

Solution code:
import collections

_=input()
a=list(map(int,input().split()))
c=collections.Counter(a)
l=sorted(c.items(), key=lambda x: x[0])
x=0
for i in l[::-1]:
    if i[1]>3:
        print(i[0]*i[0])
        exit(0)
    elif i[1]>1:
        if x:
            print(i[0]*x)
            exit(0)
        else:
            x=i[0]
print(0)

Submission status: Wrong Answer

Solution code:
import collections

_=input()
a=list(map(int,input().split()))
c=collections.Counter(a)
l=sorted(c.items(), key=lambda x: x[0])
x=0
for i in l[::-1]:
    if i[1]>3:
        print(i[0]*4)
        exit(0)
    elif i[1]>1:
        if x:
            print(i[0]*x)
            exit(0)
        else:
            x=i[0]
print(0)

Submission status: Wrong Answer

Solution code:
_=input()
a=list(map(int,input().split()))
a.sort(reverse=True)
x=0
for i in a:
    if a.count(i)>3:
        print(i*i)
        exit(0)
    elif a.count(i)>1:
        if x:
            print(x*i)
            exit(0)
        else:
            x=i
            a.remove(x)
            a.remove(x)
print(0)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
a = [int(i) for i in input().split()]
check = []
dict = collections.Counter(a)
for a, b in dict.items():
    if b >= 2:
        check.append(a)

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

Submission status: Wrong Answer

Solution code:
_ = input()
a = [int(x) for x in input().split()]

b = sorted(set(a))
b.reverse()
ans = 1
cnt = 0
for i in b:
    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)