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()))
a = sorted(a, reverse=True)
s = 1
count = 0

for i in range(len(a)-1):
	if count == 2:
		break
	else:
		if a[i] == a[i+1]:
			s = s * a[i]
			count += 1

if count == 2:
	print(s)
else:
	print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
B = []
C = []
for i in set(A):
    tmp = np.size(np.where(A == i))
    if tmp >= 4:
        C.append(i)
        B.append(i)
    elif tmp >= 2:
        B.append(i)

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

Submission status: Wrong Answer

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=spaceinput()


sa=sorted(a,reverse=True)
x=[]
for i in range(len(sa)-1):
    ssa=sa[i]
    if sa[i]==sa[i+1]:
        x.append(ssa)
        i+=1
        if len(x)==2:
            break

x.extend([0,0])

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    t = set()
    dup = [x for x in A if x in t or t.add(x)]
    no_dup = list(set(dup))
    square_list = []
    for i in no_dup:
        if 3 <= dup.count(i):
            square_list.append(i)

    no_dup.sort(reverse=True)
    # print(square_list)
    if len(no_dup) == 0:
        print(0)
    elif len(no_dup) == 1 and 1 <= len(square_list):
        # print(dup)
        # print(no_dup)
        square_list.sort(reverse=True)
        if square_list[0] * square_list[0] < dup[0] * dup[1]:
            print(dup[0] * dup[1])
        else:
            print(square_list[0] * square_list[0])
    else:
        print(no_dup[0] * no_dup[1])

Submission status: Wrong Answer

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

a = sorted(a)
i = len(a) - 1
b = []

while (i >= 1):
	if (a[i] == a[i - 1]):
		b.append(a[i - 1])
		i -= 2

	i -= 1

	if(len(b) == 2):
		break


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

else:
	print(0)

Submission status: Wrong Answer

Solution code:

N = int(input())

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

o = []
for i in s : 
    if i in s : 
        if not i in o : o.append(i)


o.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
B = []
C = []
for i in set(A):
    tmp = np.size(np.where(A == i))
    if tmp >= 4:
        C.append(i)
    elif tmp >= 2:
        B.append(i)

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

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]

s = collections.Counter(A)
res = 1
count = 0

for i in list(set(A)):
    if 4 <= s[i] and count != 1:
      res *= i
      res *= i
      count += 2
      
    elif 2 <= s[i]:
        res *= i
        count += 1
        
    if count == 2:
        break

if count == 2:
    print(res)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]

s = collections.Counter(A)
res = 1
count = 0

for i in list(set(A)):
    if 2 <= s[i]:
        res *= i
        count += 1
        
    if count == 2:
        break

if count == 2:
    print(res)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
B = []
for i in set(A):
    tmp = np.size(np.where(A == i))
    if tmp >= 2:
        B.append(i)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
s=Counter(a)
b=[]
for key, val in s.items():
 if val>=2:b.append(key)
if len(b)>1:
  b.sort()
  print(b[-1]*b[-2])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=spaceinput()


sa=sorted(a,reverse=True)
x=[]
for i in range(len(sa)-1):
    ssa=sa[i]
    if ssa in x:
        continue
    if sa[i]==sa[i+1]:
        x.append(ssa)
        if len(x)==2:
            break

x.extend([0,0])
print(x[0]*x[1])

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    t = set()
    dup = [x for x in A if x in t or t.add(x)]
    dup = list(set(dup))
    dup.sort(reverse=True)
    # print(dup)
    if len(dup) == 0 or len(dup) == 1:
        print(0)
    else:
        print(dup[0] * dup[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
C = Counter(A)
t = 2
E = sorted(C.keys())
E.reverse()
ans = 1
for e in E:
    if(C[e] >= 4):
        t -= 2
        ans *= e*e
    elif(C[e] >= 2):
        ans *= e
        t -= 1
    if(t <= 0):
        print(ans)
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
C = Counter(A)
t = 2
E = sorted(C.keys())
E.reverse()
ans = 1
for e in E:
    if(C[e] >= 4):
        t -= 2
        ans *= e*e
    elif(C[e] >= 2):
        ans *= e
        t -= 1
    if(not t):
        print(ans)
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
freq={}
for x in list(map(int,input().split())):
    if x not in freq:
        freq[x] = 1
    else:
        freq[x] += 1

s = []
for i, v in sorted(list(freq.items()),reverse=True):
    if v >= 4:
        print(i * i)
        exit(0)
    if v >= 2:
        s.append(i)
        if len(s) == 2:
            print(s[0] * s[1])
            exit(0)

print(0)

Submission status: Wrong Answer

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

    cnt = {}
    for a in A:
        if a not in cnt:
            cnt[a] = 0
        cnt[a] += 1

    B = []
    for a, x in cnt.items():
        if x >= 2:
            B.append(a)

    B = sorted(B, reverse=True)
    if len(B) > 1:
        print(B[0] * B[1])
    else:
        print('0')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
N=map(int,raw_input().split())
d={}
for i in N:
    d[i]=0
for i in N:
    d[i]+=1
res=res2=res3=0
for i in N:
    if d[i]>=2:
        res=max(res,i)
for i in N:
    if d[i]>=2 and i!=res:
        res2=max(res2,i)
for i in N:
    if d[i]==4:
        res3=max(res3,i)
print max(res*res2,res3*res3)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = input()
ac = Counter(map(int, input().split()))

w, h = 0, 0
for i in sorted(ac.keys(), reverse=True):
    if ac[i] == 1:
        continue
    if w:
        h = i
        break
    w = i

print(w * h)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import defaultdict


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


def read():
    N = II()
    A = ILI()
    return N, A


def solve(N, A):
    count = defaultdict(int)
    for a in A:
        count[a] += 1
    l_len = [key for key, value in count.items() if value >= 2]
    l_len.sort(reverse=True)
    if len(l_len) <= 1:
        ans = 0
    else:
        ans = l_len[0] * l_len[1]
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

a.sort()
first = 0
second = 0
for i in range(n - 1):
    if (a[i] == a[i + 1]) & (a[i] > first):
        second = first
        first = a[i]

print(first * second)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = input()
A = map(int, raw_input().split())
C = Counter(A)

m1 = -1
m2 = -1

for k in C.keys():
    if C[k] >= 2 and m1 < k:
        m1, m2 = k, m1
    elif C[k] >= 2 and m2 < k:
        m2 = k

if m1 < 0 or m2 < 0:
    print 0
else:
    print m1 * m2

Submission status: Wrong Answer

Solution code:
from collections import Counter
_ = input()
c = [k for k, x in Counter(map(int, input().split())).items() if x>=2]
if len(c) < 2:
    print(0)
else:
    c.sort(reverse=True)
    print(c[0] * c[1])

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
N=map(int,raw_input().split())
d={}
for i in N:
    d[i]=0
for i in N:
    d[i]+=1
res=res2=0
for i in N:
    if d[i]>=2:
        res=max(res,i)
for i in N:
    if d[i]>=2 and i!=res:
        res2=max(res2,i)
print res*res2

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = set()
cc = set()

for a in aa:
  if aa.count(a) > 1:
    bb.add(a)
  if aa.count(a) >3:
    cc.add(a)
    
if len(cc) > 0:
  y = max(cc)
else:
  y = 0

if len(bb) >= 2:
  m1 = max(bb)
  bb.remove(m1)
  m2 = max(bb)
  ans = max(m1*m2, y*y)
  
else:
  ans = max(0, y*y)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = set()
cc = set()

for a in aa:
  if aa.count(a) > 1:
    bb.add(a)
  if aa.count(a) >3:
    cc.add(a)
    
x = sorted(bb) 

if len(cc) > 0:
  y = max(cc)
else:
  y = 0

if len(bb) >= 2:
  ans = max(x[-2]*x[-1], y*y)
else:
  ans = max(0, y*y)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = set()

for a in aa:
  if aa.count(a) > 1:
    bb.add(a)
x = list(bb)
y = sorted(x, reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
f=0
s=0
mx=max(a)

stk=[]
ed=[0,0]
for i in a:
  if i in stk:
    stk.remove(i)
    ed.append(i)
  else:
    stk.append(i)
ans=sorted(ed,reverse=True)
print(ans[0]*ans[1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
f=0
s=0
mx=max(a)
cnt=[0]*(100001)
stk=[]
ed=[0,0]
for i in a:
  if i in stk:
    stk.remove(i)
    ed.append(i)
  else:
    stk.append(i)
ans=sorted(ed,reverse=True)
print(ans[0]*ans[1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
f=0
s=0
mx=max(a)
cnt=[0]
for i in range(mx+1):
  x=a.count(i)
  if x>=2:
    if x>=4:
      f=i
      s=i
    else:
      s=f
      f=i
print(f*s)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

a_max = max(an)
z = [0 for i in range(a_max)]
for i in range(len(an)):
    z[an[i]-1]+=1
l = []
for i in range(len(z)):
    if z[i] >= 2:
        l.append(i+1)
Ans = 0
if len(l)<2:
    print(0)
else:
    Ans = l[len(l)-1]*l[len(l)-2]
    print(Ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=set(a)
data=[]
for i in s:
  p=a.count(i)
  if p>=2:
    data.append([i,p//2])
data.sort(reverse=True)
h=0
w=0
for i in data:
  if i[1]>=2:
    if h==0:
      h=i[0]
    if w==0:
      w=i[0]
  else:
    if h==0:
      h=i[0]
    elif h!=0 and w==0:
      w=i[0]
print(h*w)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

bar = {}

for i in A:
    if A.count(i)>=2:
        bar[i] = A.count(i)

if len(bar)>=2:
    bar = sorted(bar.items(), reverse=True)
    print(bar[0][0]*bar[1][0])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
l1 = []
l2 = []
l3 = []
l4 = []
for i in A:
    if i in l1:
        if i in l2:
            if i in l3:
                if i not in l4:
                    l4.append(i)
            else:
                l3.append(i)
        else:
            l2.append(i)
    else:
        l1.append(i)
for i in l4:
    l2.append(i)
if len(l2) < 2:
    print(0)
else:
    l2.sort()
    print(l2[-1]*l2[-2])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
w=sorted(list(set(A)))[::-1]
leng=[0]*2
k=0
for i in w:
    if A.count(i)==2 or A.count(i)==3:
        leng[k]=i
        k+=1
    elif A.count(i)>3 and k==1:
        leng[k]=i
        k+=1
    elif A.count(i)>3 and k==0:
        leng[k]=i
        leng[k+1]=i
        k+=2
    
    if k==2:
        break

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
set_A = sorted((set(A)), reverse=True)

cnt = 0
for a in set_A:
  if A.count(a) >= 4:
    print(max(cnt*a, a*a))
    exit()
  if A.count(a) >= 2:
    tmp = cnt * a
    if tmp != 0:
      print(tmp)
      exit()
    cnt = a
    
print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = list(IL())
    sa = set(a)
    f = s = 0

    for rep in sa:
        if 4<=a.count(rep): 
            f = max(f,rep)
            s = max(s, rep)
        elif 2<=a.count(rep):
            l = [f,s,rep]
            l.sort()
            f = l[-1]
            s = l[-2]
    print(f*s)
    return

if __name__=='__main__':
    Main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())))
val, ans = [], []
for i in a:
    if i in set(val):
        ans.append(i)
    else:
        val.append(i)
ans.sort()
if len(ans) == 0:
    print(0)
else:
    if ans.count(ans[-1]) >= 4:
        print(ans[-1]**2)
    elif ans.count(ans[-1]) == 3:
        print(ans[-1]*ans[-4])
    elif ans.count(ans[-1]) == 2:
        print(ans[-1]*ans[-3])
    else:
        print(ans[-1]*ans[-2])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
w=[x for x in set(a) if a.count(x) > 1]
w.append(0)
w.append(0)
mw=max(w)
w.sort(reverse=True)
if a.count(mw)>=4:
    mh=mw
else:
    mh=w[1]
print(mh*mw)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-2):
    for j in range(i+2, n):
        if a.count(a[i]) < 2:
            continue
        if a[j:n].count(a[j]) < 2:
            continue
        ans = max(ans, a[i] * a[j])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = set(ar)
cr = []
for r in br:
    if ar.count(r) >= 4:
        cr.append(r)
        cr.append(r)
    elif ar.count(r) >= 2:
        cr.append(r)
cr = sorted(cr,reverse=True)
if len(cr) < 2:
    print(0)
else:
    print(cr[0] * cr[1])

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = set(ar)
cr = []
for r in br:
    if ar.count(r) >= 2:
        if ar.count(r) % 2 == 1:
            for i in range(ar.count(r) - 1):
                cr.append(r)
        else:
            for i in range(ar.count(r)):
                cr.append(r)
cr = sorted(cr,reverse=True)
if len(cr) < 4:
    print(0)
else:
    print(cr[0] * cr[2])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# from collections import Counter
N = int(input())
A = list(map(int, input().split()))
# cnts = Counter(A)
cnts = {}
for i in range(N):
    if A[i] not in cnts.keys():
        cnts[A[i]] = 1
    else:
        cnts[A[i]] += 1
d = {}
for k in cnts.keys():
    if cnts[k] >= 2:
        d[k] = cnts[k] // 2
        
ans = 0
for i, k1 in enumerate(list(d.keys())[:-1]):
    for k2 in list(d.keys())[i:]:
        if k1 == k2:
            if d[k1] < 2:
                continue
            else:
                ans = max(ans, k1 * k2)
        else:
            ans = max(ans, k1 * k2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnts = Counter(A)
d = {}
for k in cnts.keys():
    if cnts[k] >= 2:
        d[k] = cnts[k] // 2
ans = 0
for i, k1 in enumerate(list(d.keys())[:-1]):
    for k2 in list(d.keys())[i:]:
        if k1 == k2:
            if d[k1] < 2:
                continue
            else:
                ans = max(ans, k1 * k2)
        else:
            ans = max(ans, k1 * k2)
print(ans)

Submission status: Time Limit Exceeded

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

L = sum([[a for _ in range(min(2, c // 2))] for a, c in cnt.items()], [])
L.sort()

ans = 0 if len(L) < 2 else L[-1] * L[-2]
print(ans)

Submission status: Time Limit Exceeded

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

L = sum([[a for _ in range(c // 2)] for a, c in cnt.items()], [])
L.sort()

ans = 0 if len(L) < 2 else L[-1] * L[-2]
print(ans)

Submission status: Time Limit Exceeded

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

L = sum([[a] * (c // 2) for a, c in cnt.items()], [])
L.sort()

ans = 0 if len(L) < 2 else L[-1] * L[-2]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lens = list(map(int,input().split()))
items = list(set(lens))
items.sort(reverse = True)

cnt = 0
for j in items:
  k = lens.count(j)
  if k >= 4 and cnt == 0:
    print(j**2)
    break
  elif k >= 2 and cnt == 0:
    cnt = j
  elif k >= 2 and cnt != 0:
    print(cnt * j)
    break
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
l2 = list(set(l))
l2.sort(reverse=True)
a = 0
for i in range(len(l2)-1):
  if 2 <= l.count(l2[i]) <= 3:
    a = l2[i]
    for j in range(i+1, len(l2)):
      if 2 <= l.count(l2[j]):
        print(a * l2[j])
        sys.exit()
  elif l.count(l2[i]) >= 4:
    print(l2[i]**2)
    sys.exit()
print(0)

Submission status: Time Limit Exceeded

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

a = list(set(A))
ans = []
for i in range(len(a)):
  if A.count(a[i]) < 2:
    continue
  if A.count(a[i]) >= 4:
    ans += [a[i] , a[i]]
  else:
    ans.append(a[i])
ans.sort()
print(ans[-1]* ans[-2] if len(ans) >= 2 else 0)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = dict()

    for aa in a:
        if a.count(aa) >= 2:
            if aa not in sidelist:
                sidelist[aa] = 1
            else:
                sidelist[aa] += 1

    side_a = 0
    side_b = 0

    for s in sidelist:
        if sidelist[s] >= 4 and s > side_a:
            side_a = s
            side_b = s
        elif sidelist[s] >= 2:
            if side_a == 0:
                side_a = s
            elif side_b == 0:
                side_b = s
            elif s > side_a:
                side_b = side_a
                side_a = s
            elif s > side_b:
                side_b = s

    print(side_a*side_b)

Submission status: Time Limit Exceeded

Solution code:
from collections import OrderedDict
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = OrderedDict()

    for aa in a:
        if a.count(aa) >= 2:
            if aa not in sidelist:
                sidelist[aa] = 1
            else:
                sidelist[aa] += 1

    side_sorted = sorted(sidelist, reverse=True)

    side_a = 0
    side_b = 0

    for s in side_sorted:
        if sidelist[s] >= 4:
            side_a = s
            side_b = s
            break
        elif sidelist[s] >= 2:
            if side_a == 0:
                side_a = s
            else:
                side_b = s
                break

    print(side_a*side_b)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
A2 = [a for a in A if A.count(a)>=2]
A2.sort()
print(A2[-1]*A2[-4] if len(A2)>=4 else 0)

Submission status: Time Limit Exceeded

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

#%%
keys = set(A)
keys = sorted(keys, reverse=True)

lengths = []
for k in keys:
    num = A.count(k)
    if num >= 4 and len(lengths) == 0:
        lengths.append(k)
        lengths.append(k)
    elif num >= 2:
        lengths.append(k)

    if len(lengths) == 2:
        break

try:
    ans = lengths[0] * lengths[1]
except:
    ans = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = sorted([i for i in B if A.count(i) // 2 >= 1],reverse = True)

ans = 0
m = 0
n = 0

if len(C) == 0:
 ans = 0
 
elif A.count(C[0]) >= 4:
  m = C[0]
  ans = m ** 2

elif len(C) > 1:
  m = C[0]
  n = C[1]
  ans = m * n

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())),reverse = True)
A = [i for i in A if A.count(i) // 2 >= 1]

ans = 0

for i in range(len(A)):
  m = A[0]
  if A.count(0) >= 4:
    ans = m ** 2
    break
  else:
    if A[i] != m:
      n = A[i]
      ans = m * n
      break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

N = int(input())
A = list(map( lambda x: -int(x),input().split()))
AA = [0 for _ in range(-min(A)+1)]
heapq.heapify(A)
flg = False
ans = 0
while A:
    a = -heapq.heappop(A)
    AA[a] += 1
    if not flg and AA[a] >= 2:
        flg = True
        s = a
        AA[a] -= 2
    if flg and AA[a] >= 2:
        ans = s*a
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
AA = [0 for _ in range(max(A)+1)]
A.sort(reverse=True)
flg = False
ans = 0
for a in A:
    AA[a] += 1
    if not flg and AA[a] >= 2:
        flg = True
        s = a
        AA[a] -= 2
    if flg and AA[a] >= 2:
        ans = s*a
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
AA = [0 for _ in range(max(A)+1)]
for a in A:AA[a] += 1
flg = False
ans = 0
A.sort(reverse=True)
for a in A:
    if not flg and AA[a] >= 2:
        flg = True
        s = a
        AA[a] -= 2
    if flg and AA[a] >= 2:
        ans = s*a
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

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

    mg = 0
    for i in a:
        if a.count(i) > 3 and mg != i:
            if mg == 0:
                print(i**2)
                exit(0)
            print(mg*i)
            exit(0)
        if a.count(i) > 1 and mg != i:
            if mg == 0:
                mg = i
                continue
            print(mg*i)
            exit(0)
    print(0)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

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

    mg = 0
    for i in a:
        if a.count(i) > 3 and mg != i:
            if mg == 0:
                print(i**2)
                exit(0)
            print(mg*i)
            exit(0)
        if a.count(i) > 1 and mg != i:
            if mg == 0:
                mg = i
                continue
            print(mg*i)
            exit(0)
    print(0)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = A.count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
Ans = []
d = 0
while len(Ans) < 2:
  c = A.count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
print(Ans[0]*Ans[1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(set(A))
B.sort()
B.reverse()
C = []
for i in range(len(B)):
  c = A.count(B[i])
  if c//2!=0:
    for j in range(c//2):
      C.append(B[i])
  if len(C)==2:
    break
if len(C)==0:
  print(0)
else:
  print(C[0]*C[1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

d = {}
for i in range(N):
    if A[i] not in d:
        d[A[i]] = 0
    d[A[i]] += 1


ans = 0
for k in d:
    if d[k] >= 4:
        ans = max(ans, k ** 2)
    
    if d[k] >= 2:
        for l in d:
            if k == l: continue
            elif d[l] >= 2:
                ans = max(ans, k * l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
l = sorted([int(i) for i in input().split()])
l2 = sorted(set(l), key=l.index)
c = Counter(l)
ans = []

square = True
for i in l2[::-1]:
    if c[i] > 3:
        ans.append(i)
        break
    elif c[i] <= 1:
        square = False
        pass
    else:
        square = False
        if len(ans) == 2:
            break
        else:
            ans.append(i)
            
if square:
    print(ans[0]**2)
elif ans:
    print(ans[0]*ans[1])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set([-x for x in A if A.count(x) >= 2]))

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

    heapq.heapify(A)

    print((-heapq.heappop(A)) * (-heapq.heappop(A)))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
setA = sorted(set(A))
pairA = []

for i in range(len(setA)):
    if(A.count(setA[i]) > 1):
        temp = [setA[i]] * (A.count(setA[i]) // 2)
        pairA += temp

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

Submission status: Time Limit Exceeded

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

A_num = list(set(A))
bar_list = []

for a in A_num:
    if A.count(a) > 1:
        bar_list.append(a)
        if A.count(a) > 3:
            bar_list.append(a)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
X = set()
for i in range(N):
  if A.count(A[i]) > 1:
    X.add(A[i])
Y = list(X)
Y.sort(reverse=True)
if len(Y) == 0:
  print(0)
else:
  print(Y[0]*Y[1])

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
cr = set(ar)
dr = sorted(cr,reverse=True)
br = []
for r in dr:
    if len(br) >= 2:
        break
    if ar.count(r) >= 4:
        br.append(r)
        br.append(r)
    elif ar.count(r) >= 2:
        br.append(r)
if len(br) == 0:
    print(0)
else:
    print(br[0] * br[1])

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
cr = set(ar)
dr = sorted(cr,reverse=True)
br = []
for r in dr:
    if len(br) == 2:
        break
    if ar.count(r) >= 4:
        br.append(r)
        if len(br) == 2:
            break
        br.append(r)
    elif ar.count(r) >= 2:
        br.append(r)
if len(br) == 0:
    print(0)
else:
    print(br[0] * br[1])

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = []
for r in set(ar):
    if ar.count(r) >= 4:
        br.append(r)
        br.append(r)
    elif ar.count(r) >= 2:
        br.append(r)
br = sorted(br,reverse=True)
if len(br) == 0:
    print(0)
else:
    print(br[0] * br[1])

Submission status: Time Limit Exceeded

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


AA = list(set(A))
AA.sort(reverse=True)

cnt = 0
l = []
for val in AA:
    if A.count(val) >= 4 and cnt == 0:
        print(val*val)
        exit()
    if A.count(val) >= 2:
        cnt += 1
        l.append(val)

    if cnt == 2:
        print(l[0]*l[1])
        exit()

print(0)