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: Time Limit Exceeded

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

rec_hen = 0
a_set = sorted(set(a), reverse=True)
for ai in a_set:
  ac = a.count(ai)
  if ac >= 4:
    if rec_hen != 0:
      print(rec_hen * ai)
      exit(0)
    print(ai * ai)
    exit(0)
  if ac >= 2:
    if rec_hen != 0:
      print(rec_hen * ai)
      exit(0)
    rec_hen = ai

print(0)

Submission status: Time Limit Exceeded

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

a_list = sorted(a_list, reverse=True)
a_set = set(a_list)
a_dict = {}
sorted_dict = {}

ans_big = 0
ans_small = 0

for i in a_set:
    a_dict[i] = a_list.count(i)

for k, v in sorted(a_dict.items(), key=lambda x: -x[0]):
    if v >= 4:
        if ans_big < k:
            ans_big = k
        if ans_small < k:
            ans_small = k
    elif v >= 2:
        if ans_big < k:
            ans_big = k
        elif ans_small < k:
            ans_small = k
print(ans_small * ans_big)

Submission status: Time Limit Exceeded

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

a_list = sorted(a_list, reverse=True)

ans_list = [0,0]

for i in a_list:
    counter = a_list.count(i)
    if ans_list == [0,0] and counter >= 4:
        ans_list = [i,i]
        break
    elif counter >= 2 and ans_list[0] == 0:
        ans_list[0] = i
    elif counter >= 2 and ans_list[0] > i and ans_list[1] == 0:
        ans_list[1] = i
        break

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

Submission status: Time Limit Exceeded

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

a_list = sorted(a_list, reverse=True)

ans_list = [0,0]

for i in a_list:
    if ans_list == [0,0] and a_list.count(i) >= 4:
        ans_list = [i,i]
        break
    elif a_list.count(i) >= 2 and ans_list[0] == 0:
        ans_list[0] = i
    elif a_list.count(i) >= 2 and ans_list[0] > i and ans_list[1] == 0:
        ans_list[1] = i
        break

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

sList = list(map(int,input().split()))
sEdit = sorted(list(set(sList)),reverse=True)
res = 0
for i in sEdit:
  dcount = sList.count(i)//2
  if dcount >= 2 and res == 0:
    print(i*i)
    exit(0)
  elif dcount >= 1 and res == 0:
    res = i
  elif dcount >= 1 and res != 0:
    print(res*i)
    exit(0)

print(0)

Submission status: Time Limit Exceeded

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = list(map(int, input().split()))
b = sorted(set(a))[::-1]
ans = 1
cnt = 0
for i in b:
    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 = 2
        break
    ans *= i
    cnt += 1

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

Submission status: Time Limit Exceeded

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = list(map(int, input().split()))
b = sorted(set(a))[::-1]
ans = 1
cnt = 0
for i in b:
    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 = 2
        break
    ans *= i
    cnt += 1

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

Submission status: Time Limit Exceeded

Solution code:


n=int(input())

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

s=[]
t=[]
for i in a:
    if i not in s:
        s.append(i)
    else:
        t.append(i)
        s=[]
    if len(t)==2:
        break


try:
    print(t[0]*t[1])
except:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
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: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
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: Time Limit Exceeded

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: Time Limit Exceeded

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(sorted(listans)[-1]*sorted(listans)[-2])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
B = []
for a in A:
    if (A.count(a) >= 2):
        B.append(a)
        A.remove(a)
B.sort()
B.reverse()
if len(B) >= 2:
    width = B[0]
    length = B[1]
    print(width * length)
else: print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
uniq_a = sorted(list(set(a)), reverse=True)
c = 0
ans = 1
for num in uniq_a:
    if c == 0 and a.count(num) >= 4:
        print(num**2)
        exit()
    if a.count(num) >= 2:
        c += 1
        ans *= num
        if c == 2:
            print(ans)
            exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
n=input()

l=[int(x) for x in input().split()]
temp=list(set(x for x in l if l.count(x)>1))
if temp==[]:
	print("0")
else:	
	y=max(temp)
	if l.count(y)>3:
		lar=sec=y
	else:
		lar=y
		temp.remove(y)
		sec=max(temp)
	print(lar*sec)

Submission status: Time Limit Exceeded

Solution code:
n=input()
temp=[]
l=[int(x) for x in input().split()]
for x in l:
	if x not in temp:
		y=l.count(x)
		if y>3:
			temp.append(x)
		if(y>1):
			temp.append(x)
	
if len(temp)<2:
	print(0)
else:
	x=max(temp)
	temp.remove(x)
	print(x*max(temp))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ls=[]
temp=[]
l= list((int(x) for x in input().split()))
temp=list(set([x for x in l if l.count(x)>1]))
for x in l:
	if (l.count(x)>3):
		ls.append(x)
temp+=list(set(ls))
if len(temp)<2:
	print(0)
else:
	x=max(temp)
	temp.remove(x)
	print(x*max(temp))

Submission status: Time Limit Exceeded

Solution code:
input()
L = [int(i) for i in input().split()]
cnt,ans = 0,1
for i in sorted(set(L),reverse=True):
  if L.count(i)>=4 and cnt==0:
    ans = i*i
    break
  elif 2<=L.count(i)<4:
    ans *= i
    cnt += 1
    if cnt == 2:
      break
  elif L.count(i)>=4 and cnt==1:
    ans *=i
    break
print(0 if ans==1 else ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
cnt = 0
ans = 1
for i in sorted(set(L),reverse=True):
  if L.count(i)>=4 and cnt==0:
    print(i*i)
    exit()
  elif 2<=L.count(i)<4:
    ans *= i
    cnt += 1
    if cnt == 2:
      break
  elif L.count(i)>=4 and cnt==1:
    ans *=i
    print(ans)
    exit()
print(0 if cnt<2 else ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
a = []
for l in L:
  if L.count(l) >= 4 and a==[]:
    print(l*l)
    exit()
  elif L.count(l)>=2 and l not in a:
    a.append(l)
    if len(a) == 2:
      break
print(0 if a==[] else a[0]*a[1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
a = []
for l in L:
  if L.count(l) >= 4 and a==[]:
    print(l*l)
    exit()
  if L.count(l)>=2 and l not in a:
    a.append(l)
    if len(a) == 2:
      break
print(0 if a==[] else a[0]*a[1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(input().split())
q=1
j=0
for i in range(n-1,-1,-1):
  if j==2:
    print(q)
    exit()
  elif a.count(str(i))>=4:
    print(i*i)
    exit()
  elif a.count(str(i))>=2 :
    q*=i
    j+=1
  else:
    pass
print(0)

Submission status: Time Limit Exceeded

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

L = []
for s in S:
    if A.count(s) > 3:
        L.append(s)
        L.append(s)
    elif A.count(s) > 1:
        L.append(s)
    if len(L) > 1:
        print(L[0]*L[1])
        break
else:
    print(0)

Submission status: Time Limit Exceeded

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

n = int(input())
a = list(map(int, input().split()))
aset = set(a)
b = []
c = []
for i in aset:
    if a.count(i)>1:
        b.append(i)
    
    if a.count(i)>3:
        c.append(i)
b.sort()
c.sort()
m = len(b)
if m<2:
    if len(c)<1:
        print(0)
    else:
        print(c[-1]*c[-1])
else:
    if len(c)<1:
        print(b[-1]*b[-2])
    else:
        ans = max(b[-2]*b[-1],c[-1]*c[-1])
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
aset = set(a)
b = []
c = []
for i in aset:
    if a.count(i)>1:
        b.append(i)
    
    if a.count(i)>3:
        c.append(i)
b.sort()
c.sort()
m = len(b)
if m<2:
    if len(c)<1:
        print(0)
    else:
        print(c[-1]*c[-1])
else:
    if len(c)<1:
        print(b[-1]*b[-2])
    else:
        ans = max(b[-2]*b[-1],c[-1]*c[-1])
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [ x for x in set(a) if a.count(x)>1]
c = [ x for x in set(a) if a.count(x)>3]
b.sort()
c.sort()
m = len(b)
if m<2:
    if len(c)<1:
        print(0)
    else:
        print(c[-1]*c[-1])
else:
    if len(c)<1:
        print(b[-1]*b[-2])
    else:
        ans = max(b[-2]*b[-1],c[-1]*c[-1])
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [ x for x in set(a) if a.count(x)>1]
c = [ x for x in set(a) if a.count(x)>3]
b.sort(reverse=True)
c.sort(reverse=True)
m = len(b)
if m<2:
    if len(c)<1:
        print(0)
    else:
        print(c[0]*c[0])
else:
    if len(c)<1:
        print(b[0]*b[1])
    else:
        ans = max(b[0]*b[1],c[0]*c[0])
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n, *a = map(int, stdin.read().split())
lengths = sorted(set(a), reverse=1)     
a.sort()

long_side, short_side = 0, 0
for l in lengths:
    c = a.count(l)
    if c != 1:
        if not long_side:
            if c >= 4:
                print(l ** 2)
                exit()
            else:
                long_side = l
        else:
            short_side = l
            break

print(long_side * short_side)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n, *a = map(int, stdin.read().split())
lengths = sorted(set(a), reverse=1)
a.sort()

remainder = 4
long_side, short_side = 0, 0
for l in lengths:
    th = a.index(l)
    c = len(a) - th
    if c != 1:
        if remainder == 4:
            if c >= 4:
                print(l ** 2)
                exit()
            else:
                remainder = 2
                long_side = l
        else:
            short_side = l
            break
    a = a[:th]

print(long_side * short_side)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
c=[]
for i in range(N):
  if A.count(A[i])>=2:
    c.append(A[i])
d=[x for x in set(c) if c.count(x) > 1]
if len(c)>0:
  a=max(d)
  d.remove(a)
  b=max(d)
  print(a*b)
else:
  print("0")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
c=[]
for i in range(N):
  if A.count(A[i])>=2:
    c.append(A[i])
if len(c)>0:
  d=[x for x in set(c) if c.count(x) > 1]
  a=max(d)
  d.remove(a)
  b=max(d)
  print(a*b)
else:
  print("0")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=set(a)
l=[0]*2
for i in s:
	if a.count(i)>=4:
		l+=[i]*2
	elif a.count(i)>=2:
		l+=[i]
h=max(l)
l.remove(h)
w=max(l)
l.remove(w)
print(h*w)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in c: 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in set(l): 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Submission status: Time Limit Exceeded

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

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

W = 0
D = 0

for i in range(len(A_uniq)):
  if W == 0:
    if A.count(A_uniq[i]) >= 4:
      print(A_uniq[i] ** 2)
      sys.exit()
    elif A.count(A_uniq[i]) >= 2:
      W = A_uniq[i]
  elif D == 0:
    if A.count(A_uniq[i]) >= 2:
      D = A_uniq[i]
  elif W != 0 and D != 0:
    print(W * D)
    sys.exit()

print(W * D)

Submission status: Time Limit Exceeded

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

if len(a) <= len(seta)+1:
  print(0)
  exit()

seta.sort(reverse=True)
c2 = []
c4 = 0
for i in seta:
  if a.count(i)>=2:
    c2.append(i)
    if len(c2) == 2:
      break
  
for i in seta:
  if a.count(i)>=4:
    c4=i
    break

if c4 == 0 and len(c2)<2:
  print(0)
elif c4 == 0 and len(c2)>=2:
  print(c2[0]*c2[1])
elif c4 > 0 and len(c2)<2:
  print(c4**2)
else:
  print(max(c4**2,c2[0]*c2[1]))

Submission status: Time Limit Exceeded

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

seta.sort(reverse=True)
c2 = []
c4 = 0
for i in seta:
  if a.count(i)>=2:
    c2.append(i)
    if len(c2) == 2:
      break
  
for i in seta:
  if a.count(i)>=4:
    c4=i
    break

if c4 == 0 and len(c2)<2:
  print(0)
elif c4 == 0 and len(c2)>=2:
  print(c2[0]*c2[1])
elif c4 > 0 and len(c2)<2:
  print(c4**2)
else:
  print(max(c4**2,c2[0]*c2[1]))

Submission status: Time Limit Exceeded

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

c4 = []
c2 = []
for i in seta:
  if Counter(a)[i] >= 4:
    c4.append(i)
  if Counter(a)[i] >= 2:
    c2.append(i)

c2.sort(reverse=True)
c4.sort(reverse=True)
if len(c4) == 0 and len(c2)<2:
  print(0)
elif len(c4) == 0 and len(c2)>=2:
  print(c2[0]*c2[1])
elif len(c4) > 0 and len(c2)<2:
  print(c4[0]**2)
else:
  print(max(c4[0]**2,c2[0]*c2[1]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
rect_long = 0
rect_small = 0
while A != []:
    long_max = max(A)
    if A.count(long_max) >= 2:
        rect_long += long_max
        A.remove(long_max)
        A.remove(long_max)
        break
    A.remove(long_max)

while A != []:
    small_max = max(A)
    if A.count(small_max) >= 2:
        rect_small += small_max
        break
    A.remove(small_max)

print(rect_long * rect_small)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
rect_long = 0
rect_small = 0
while A != []:
    long_max = max(A)
    if A.count(long_max) >= 2:
        rect_long += long_max
        A.remove(long_max)
        A.remove(long_max)
        break
    else:
        A.remove(long_max)

while A != []:
    small_max = max(A)
    if A.count(small_max) >= 2:
        rect_small += small_max
        break
    A.remove(small_max)

print(rect_long * rect_small)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())),reverse=True)
for i in range(n):
    if A.count(A[i])>=2:
        for j in range(i+2,n):
            if A[i+2:].count(A[j])>=2:
                print(A[i]*A[j])
                exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())),reverse=True)
m=0
i=0
while i<len(A):
    if A[i:].count(A[i])>=2:
        if m==0:
            m=A[i]
            i+=2
        else:
            n=A[i]
            print(m*n)
            exit()
    else:
        i+=1
print(0)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())),reverse=True)
for a in A:
    if A.count(a)>=2:
        if A.count(a)>=4:
            print(a**2)
            exit()
        else:
            for b in A:
                if b!=a:
                    if A.count(b)>=2:
                        print(a*b)
                        exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
A = sorted(list(map(int,input().split())), reverse = True)
edge = []

for i in range(N):
    a = A[i]
    if A.count(a) >= 2 and a not in edge:
        edge.append(a)
        if len(edge) == 2:
            print(edge[0]*edge[1])
            exit()
        if A.count(a) >= 4:
            print(a*a)
            exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
*l, = map(int,input().split())
rect = [i for i in set(l) if l.count(i)>=2]
squ = [i for i in rect if l.count(i)>=4]
rect.sort()
squ.sort()
if len(rect)>=2:
  srect = rect[-1]*rect[-2]
else:
  srect = 0
if len(squ)>=1:
  ssqu=squ[-1]**2
else:
  ssqu=0
print(max([srect,ssqu]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
d = {}
ans = []
for i in range(n):
    if a[i] in d.keys():
        d[a[i]] += 1
    else:
        d[a[i]] = 1
    if d[a[i]]==4:
      ans.append(a[i])
    elif d[a[i]]==2:
      ans.append(a[i])
    if len(ans)> 1:
      break
ans.append(0)
ans.append(0)
print(ans[0]*ans[1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
li1 = []
for i in range(len(li)):
    if li.count(li[i])>=2:
        li1.append(li[i])
li1 = sorted(list(set(li1)))[::-1]
if len(li1)>=2:
    print(li1[0]*li1[1])
else:
    print(0)

Submission status: Time Limit Exceeded

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

    max_num = 0

    for a in set_A:
        if A.count(a) >= 2:
            if max_num == 0:
                max_num = a
                if A.count(a) >= 4:
                    print(a * a)
                    exit()
            else:
                print(max_num * a)
                exit()

    print(0)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    sort_A = sorted(A, reverse=True)
    set_A = sorted(set(sort_A), reverse=True)

    max_num = 0

    for a in set_A:
        if sort_A.count(a) >= 2:
            if max_num == 0:
                max_num = a
                if sort_A.count(a) >= 4:
                    print(a * a)
                    exit()
            else:
                print(max_num * a)
                exit()

    print(0)

main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(set(A),reverse=True)
li=[]
for aa in AA:
  if A.count(aa)>=4:
    li.append(aa)
    break
  if A.count(aa)>=2:
    li.append(aa)
  if len(li)==2:
    break
if len(li)==0:
  print(0)
if len(li)==1:
  print(li[0]**2)
if len(li)==2:
  print(li[0]*li[1])

Submission status: Time Limit Exceeded

Solution code:
# ABC071-C　
N = int(input())
A_list = list(map(int, input().split()))

A_set = sorted(set(A_list), reverse = True)

side_list = [0, 0]

for i in range(len(A_set)):   # 大きい順に取っていき，リストで個数を確認する
    if len(side_list) >= 4:
        break
    count = A_list.count(A_set[i])    # リストの個数を確認
    if count == 2 or count == 3:
        side_list.append(A_set[i])
    if count >= 4:
        side_list.append(A_set[i])
        side_list.append(A_set[i])
        
side_list.sort(reverse = True)
print(side_list[0] * side_list[1])

Submission status: Time Limit Exceeded

Solution code:
# ABC071-C　
N = int(input())
A_list = list(map(int, input().split()))

A_set = set(A_list)
A_set = sorted(A_set, reverse=True)

side_list = [0, 0]

for i in range(len(A_set)):   # 大きい順に取っていき，リストで個数を確認する
    if len(side_list) >= 4:
        break
    count = A_list.count(A_set[i])    # リストの個数を確認
    if count == 2 or count == 3:
        side_list.append(A_set[i])
    if count >= 4:
        side_list.append(A_set[i])
        side_list.append(A_set[i])
        
side_list.sort(reverse = True)
print(side_list[0] * side_list[1])

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
n = input()
ans = 0
num_list = [ int(v) for v in input().split() ]
count_list = [ [num_list.count(i),i] for i in sorted(set(num_list),reverse = True)]

a, b = -1, -1
for i in count_list:
	if i[0] >= 4 and a == -1:
		ans = i[1]**2
		break
	elif i[0] >= 2:
		if a == -1:
			a = i[1]
		else:
			b = i[1]
			ans = a*b
			break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc071/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))
A.sort()
tmp = [0,0]
for i in range(len(A)-1):
    if A[i] == A[i+1] and not A[i] in tmp:
        tmp.append(A[i])
ans = tmp[-1]*tmp[-2]
if A.count(tmp[-1]) >=4:
        ans = tmp[-1]*tmp[-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = []
x = []
for i in range(n):
    if a.count(a[i]) != 1:
        l.append(a[i])
for i in range(n):
    if a.count(a[i]) == 1:
        x.append(a[i])
if len(x) == len(a):
    print(0)
elif l.count(max(l)) >= 4:
    print(max(l)**2)
else:
    l = sorted(set(l))[::-1]
    print(l[0]*l[1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A, key=lambda x: -x)

    B = []
    C = []
    for a in A:
        if a in B:
            C.append(a)
            B.remove(a)
            if len(C) >= 2:
                break
        else:
            B.append(a)

    if len(C) < 2:
        return 0
    else:
        return C[0] * C[1]


if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    B = []
    C = []
    for a in A:
        if a in B:
            C.append(a)
            B.remove(a)
        else:
            B.append(a)

    C = sorted(C, key=lambda x: -x)
    if len(C) < 2:
        return 0
    else:
        return C[0] * C[1]


if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
A = [int(i) for i in input().split()]
B = list(set(A))
B.sort(reverse=True)
ls = []
for x in B:
    num = A.count(x)
    if num >= 2:
        ls.append(x)
        if len(ls) == 2:
            break
        if num >= 4:
            print(x**2)
            sys.exit()
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data=[int(aa) for aa in input().split()]
data.sort()
#print(data)
mydata=0
mylist=[0,0]
for aa in data:
    if data.count(aa) >3:
        mydata=aa
    if data.count(aa) >1 :
        if aa not in mylist:
            mylist.pop(0)
            mylist.append(aa)
#            print(mylist)

print(max(mydata*mydata,mylist[0]*mylist[1]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
m = sorted((i for i in set(l) if l.count(i) > 1), reverse=True)
if len(m) > 0:
  x = m[0]
  if l.count(x) > 3:
    print(x*x)
  elif len(m) > 1:
    y = m[1]
    print(x*y)
  else:
    print(0)
else:
  print(0)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(0)

Submission status: Time Limit Exceeded

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

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

print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
aset = set(a)
aset = sorted(aset, reverse = True)
res = 0
for i in aset:
    count = a.count(i)
    if count >= 4 and res == 0:
        print(i*i)
        exit()
    elif count >= 2 and res == 0:
        res = i
    elif count >= 2:
        print(res * i)
        exit()
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

X = list(map(int, input().split()))
A = []
for i in X:
    if(X.count(i) > 1 and i not in A):
        A.append(i)
sorted(A)
if(len(A) < 2):
    print(0)
else:
    print(A[-1] * A[-2])

Submission status: Time Limit Exceeded

Solution code:
#長方形ができるかの判定を行いながら、長方形の面積を求める
N=int(input()) 
A=list(map(int,input().split()))
A.sort()
max1=0
max2=0
max3=0
max4=0
for i in range(0,len(A)): 
    if A.count(A[i])>=2: 
        a=max1
        b=max2
        c=max3
        max1=A[i]
        max2=a
        max3=b
        max4=c
print(max1*max4)
#これは求めるべき答えを見出せたが、TLEとなった
#これはcount関数を使ったため

Submission status: Time Limit Exceeded

Solution code:
int_n = int(input())
ar_int_a = list(map(int, input().split()))

result = []

ar_int_a.sort(reverse=True)

headers = set(ar_int_a)

counters = [{'number': i, 'count': ar_int_a.count(i)} for i in headers
            if ar_int_a.count(i) >= 2]

for i in sorted(counters, key=lambda x: x['number'], reverse=True):

    if len(result) == 0 and i['count'] >= 4:
        print(i['number'] ** 2)
        exit(0)
    elif len(result) < 2:
        result.append(i['number'])
    else:
        break
if len(result) == 2:
    print(result[0] * result[1])
else:
    print(0)

Submission status: Time Limit Exceeded

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

n = int(input())
re_nums = []
nums = []
A = list(map(int, input().split()))
for a in A:
    if a not in re_nums:
        re_nums.append(a)
    else:
        nums.append(a)
nums.sort(reverse=True)
l = len(nums)
ans = 0
if l < 2:
    ans = 0
else:
    l1 = nums[0]
    l2 = nums[1]
    if l2 == l1:
        if l > 3:
            if nums[2] == l2:
                ans = l1**2
            else:
                ans = l1*nums[2]
        else:
            ans = 0
    else:
        ans = l1*l2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
x = list(map(int, input().split()))
y = set(x)
k=[]
s = 0
for i in y:
    z = x.count(i)
    if z>=2:
        k.append([i,z])
        s+=z
        if s >=a:break
        
k.append([0,0])
k.append([0,0])
k.sort()
if k[-1][1] >=4:
    print(k[-1][0]**2)
else:
    print(k[-1][0]*k[-2][0])