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:
a = int(input())
x = list(map(int, input().split()))
y = set(x)
k=[]
for i in y:
    if x.count(i)>=2:
        k.append([i,x.count(i)])
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])

Submission status: Time Limit Exceeded

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

c = {a: A.count(a) for a in A if A.count(a) >= 2}
cc = sorted(c)
x = len(c)
if(x <= 1):
  ans = 0
elif(c.get(cc[x-1]) >= 4):
  ans = cc[x-1] * cc[x-1]
else:
  ans = cc[x-1] * cc[x-2]
print(ans)

Submission status: Time Limit Exceeded

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

d = {aa: 0 for aa in A}
c = sorted({a: A.count(a) for a in A if A.count(a) >= 2})
x = len(c)
if(x <= 1):
  ans = 0
elif(d.get(c[x-1]) >= 4):
  ans = c[x-1] * c[x-1]
else:
  ans = c[x-1] * c[x-2]
print(ans)

Submission status: Time Limit Exceeded

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

d = {aa: A.count(aa) for aa in A}
c = sorted({k: v for k, v in d.items() if v >= 2})
x = len(c)
if(x <= 1):
  ans = 0
elif(d.get(c[x-1]) >= 4):
  ans = c[x-1] * c[x-1]
else:
  ans = c[x-1] * c[x-2]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

n = int(input())
A = list(map(int,input().split()))
A = [i for i in A if A.count(i) >= 2]
if len(A) == 0:
  print(0)
  exit()

if A.count(max(A)) >= 4:
  print(max(A)**2)
  exit()
elif 2<= A.count(max(A)) < 4:
  print(max(A)*A[bisect_left(A,max(A))-1])

Submission status: Time Limit Exceeded

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

for n in sorted_dup:
    total = num_list.count(n)
    if cnt == 0 and total >= 4:
        ans = n*n
        cnt = 2
    elif total >= 2:
        ans *= n
        cnt += 1
    if cnt == 2:
        break

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
for i in set(a):
  if a.count(i)== 1:
    a.remove(i)
if len(a) <= 3:
  print(0)
else:
  if a.count(max(a)) == 3:
    print(a[-1]*a[-4])
  else:
    print(a[-1]*a[-3])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=(int(i) for i in input().split())

C=[0 for i in range(1000000000)]

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

print(C)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

C.sort(reverse=True)

W=0
for j in range(len(C)):
    if C[j]==W:
        pass
    elif C.count(C[j])>=4:
        if W==0:
            
            print(C[j]*C[j])
            exit()
        else:
            print(W*C[j])
            exit()
    elif C.count(C[j])>=2:
        if W==0:
            W=C[j]
        else:
            print(W*C[j])
            exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = input().split()

d = {}
for i in a:
    d[i] = d.get(i,0)+1
    
for i in d:
    d[i] = d[i]//2

s = []
for i in d:
    for _ in range(d.get(i)):
        s.append(int(i))
    s.sort()
if(len(s)>=2):
    print(s[-1]*s[-2])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = sorted(li_input(), reverse=1)

    X = []

    for a in A:

        if A.count(a) >= 4:
            X.append(a)
            X.append(a)
            break

        if A.count(a) >= 2 and a not in X:
            X.append(a)
            if len(X) >= 2:
                break
        

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



main()

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0

for i in A.keys():
    if A[i] >= 2:
        tyouhou = tyouhou+[i]
    if A[i] >= 4:
        seihou = seihou+[i]

if len(seihou) >= 1:
    ans = max(seihou)**2

if len(tyouhou) >= 2:
    c = max(tyouhou)
    tyouhou.remove(c)
    ans = max(ans, c*max(tyouhou))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0

for i in A.keys():
    if A[i] >= 2:
        tyouhou = tyouhou+[i]
    if A[i] >= 4:
        seihou = seihou+[i]

if len(seihou) >= 1:
    ans = max(seihou)**2

if len(tyouhou) >= 2:
    tyouhou.sort()
    ans = max(ans, tyouhou[-1]*tyouhou[-2])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
AA = [i for i in A if A.count(i)>=2]

AAA =sorted(set(AA))

#長方形を調べる
if len(AAA) >= 2:
    ans = AAA[-1]*AAA[-2]

#正方形を調べる
for i in AAA:
    if AA.count(i) >=4:
        ans =max(ans, i**2)
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
AA = [i for i in A if A.count(i)>=2]

AAA =sorted(set(AA))

#長方形を調べる
if len(AAA) >= 2:
    ans = AAA[-1]*AAA[-2]

#正方形を調べる
for i in AAA:
    if AA.count(i) >=4:
        ans =max(ans, i**2)
        
print(ans)

Submission status: Time Limit Exceeded

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

a_sorted = sorted(a, reverse=True)
x = 0
y = 0

while True:
    if len(a_sorted) == 0:
        break
    max = a_sorted[0]
    if x != 0 and y != 0:
        break
    if a_sorted.count(max) >= 2:
        if x == 0:
            x = max
        else:
            y = max
        a_sorted.remove(max)
        a_sorted.remove(max)
    else:
        a_sorted.remove(max)
print(x * y)

Submission status: Time Limit Exceeded

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

d = dict()
for a_i in a:
	if a_i not in d:
		d[a_i] = 0
	d[a_i] += 1
d = sum([[d_i[0] for i in range(d_i[1]//2)] for d_i in d.items()], [])

if len(d) < 2:
	print(0)
else:
	max_1 = max(d)
	d.remove(max_1)
	max_2 = max(d)
	print(max_1 * max_2)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
max1=0;max2=0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]==a[j]:
      if a[i]>max1:
        max2=max1
        max1=a[i]
      elif a[i]>max2:
        max2=a[i]
      a[j]=0
      break
print(max1*max2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
k = max(A)
l = []
while k >= min(A):
  if len(l)>=2:
    break
  if A.count(k)>=4:
    l.append(k)
    l.append(k)
  elif A.count(k)>=2:
    l.append(k)
  k += -1
if len(l)<= 1:
  print(0)
else:
  print(l[0]*l[1])

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

f = 0
s = 0
processed = [0]*n
for i in range(len(a)):
    if a[i] <= s:
        continue
    if a[i] in processed:
        continue
    if a.count(a[i]) < 2:
        continue
    if a.count(a[i]) < 4:
        if a[i] < f:
            s = a[i]
        else:
            s = f
            f = a[i]
    else:
        if a[i] < f:
            s = a[i]
        else:
            f = a[i]
            s = a[i]
    processed[i] = a[i]

print(s*f)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

f = 0
s = 0
processed = []
for i in a:
    if i <= s:
        continue
    if i in processed:
        continue
    if a.count(i) < 2:
        continue
    if a.count(i) < 4:
        if i < f:
            s = i
        else:
            s = f
            f = i
    else:
        if i < f:
            s = i
        else:
            f = i
            s = i
    processed.append(i)

print(s*f)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

f = 0
s = 0
processed = []
for i in a:
    if i < s or a.count(i) < 2 or i in processed:
        continue
    if a.count(i) < 4:
        if i < f:
            s = i
        else:
            s = f
            f = i
    else:
        if i < f:
            s = i
        else:
            f = i
            s = i
    processed.append(i)

print(s*f)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer,num = collections.Counter(a),1,-1
while a != []:
	if x[a[0]]>=4 and num==-1:
		print(a[0]**2)
		break
	elif x[a[0]]>=2:
		answer *= a[0]
		num += 1
		if num==1:
			print(answer)
			break
	a = a[x[a[0]]:]
	if a == []:
		print(0)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer,num = collections.Counter(a),1,-1
for i in x.keys():
	if x[i] == 1:
		a.remove(i)
while a != []:
	if x[a[0]]>=4 and num==-1:
		answer = a[0]**2
		num = 1
		break
	elif x[a[0]]>=2:
		answer *= a[0]
		num += 1
		if num==1:
			break
	a = a[x[a[0]]:]
print(max(answer*num,0))

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer,num = collections.Counter(a),1,-1
while a != []:
	if x[a[0]]>=4 and num==-1:
		answer = a[0]**2
		num = 1
		break
	elif x[a[0]]>=2:
		answer *= a[0]
		num += 1
		if num==1:
			break
	a = a[x[a[0]]:]
print(max(answer*num,0))

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer = collections.Counter(a),[]
while a != []:
	if x[a[0]]>=4 and len(answer)==0:
		answer = [a[0],a[0]]
		break
	elif x[a[0]]>=2:
		answer.append(a[0])
		if len(answer)==2:
			break
	a = a[x[a[0]]:]
if len(answer)==2:
	print(answer[0]*answer[1])
else:
	print(0)

Submission status: Time Limit Exceeded

Solution code:
from collections import *
n=int(input())
a=list(map(int,input().split()))
#a.sort()
b=sorted(set(a))[::-1]
wid=0
hei=0
for i in b:
  c=a.count(i)
  if(c>3):
    if(hei==0):
      hei,wid=i,i
    elif(wid==0):
      wid=i
    break
  elif(c>1):
    if(hei==0):hei=i
    elif(wid==0):
      wid=i
      break
print(wid*hei)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
set_a=list(set(a))
a_4=[]
for i in set_a:
    if a.count(i)==1:
        a.remove(i)
    if 4<=a.count(i):
        a_4.append(i)
        a.remove(i)
if len(a)==0:
    print(0)
    exit()
a=list(set(a))
a.sort()
a.reverse()
a_4.sort()
a_4.reverse()
v=0
x=0
z=0
if 1<=len(a_4):
    v=a_4[0]*a_4[0]
if 1<=len(a):
    x=a[0]*a[1]
if 1<=len(a) and 1<=len(a_4):
    z=a[0]*a_4[0]
print(max(v,x,z))

Submission status: Time Limit Exceeded

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

n = int(line())
a = list(map(int, line().split()))
l = [0 for i in range(max(a)+1)]
for i in a: l[i] += 1
l.reverse()
h = 0
for i in range(len(l)):
    if l[i] > 4:
        print(l[i])
        sys.exit()
    if l[i] >= 2 and h:
        print((len(l) - 1 - i) * h)
        sys.exit()
    if l[i] >= 2:
        h = len(l) - 1 - i
print(0)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(n):
    if a.count(i)>=2:
        ans.append(i)
new=list(set(ans))
if len(new)<=1:
    print(0)
    exit()
sorted(new,key=int)
print(new[-1]*new[-2])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
P = list(map(int,input().split()))
P.sort(reverse=True)
a = 0
b = 0
for i in range(N-1):
    if P[i] > 0:
        if a == 0:
            if P.count(P[i]) >= 2:
                a = P[i]
                P[i] = -i
                P[i+1] = -i -1
        elif b == 0:
            if P.count(P[i]) >= 2:
                b = P[i]
                P[i] = -i
                P[i+1] = -i -1
        else:
            break
    else:
        continue
ans = a * b
print(ans)

Submission status: Time Limit Exceeded

Solution code:

input()
xs = map(int, input().split())

d = dict()
for x in xs:
    if x in d.keys():
        d[x] += 1
    else:
        d[x] = 1

res = 0
for x, c1 in d.items():
    if c1 >= 4:
        if res < x * x: res = x * x
    for y, c2 in d.items():
        if x != y and c1 >= 2 and c2 >= 2:
            if res < x * y: res = x * y


print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
#k = int(input())
arr = list(map(int, input().split()))

a = [0 for i in range(1, max(arr)+2)]

# print(arr)
# print(a)

for ar in arr:
  a[ar] += 1

t = []
for i, z in enumerate(a):
  if z >= 2:
    t.append(i)

if len(t) < 2:
  print(0)
else:
  sort = sorted(t, reverse=True)

  ans = sort[0] * sort[1]

  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sticks = list(map(int, input().split()))
multi = set()
f = 0
s = 0
for i in sticks:
  if sticks.count(i) >= 2:
    if i > f:
      f, s = i, f

print(f * s)

Submission status: Time Limit Exceeded

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

ai.sort()
l = []
tmp = -1
for x in ai:
    if(tmp != x):
        l.append(x)
        tmp = x
l.reverse()

#dic = {x : ai.count(x) for x in ai}

m1 = 0
m2 = 0
for x in l:
    if(ai.count(x) >= 4):
        if m1 > 0:
            m2 = x
        else:
            m1 = m2 = x
        break
    elif(2 <= ai.count(x) < 4):
        if m1:
            m2 = x
            break
        else:
            m1 = x
            continue

print(m1*m2)

Submission status: Time Limit Exceeded

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

ai.sort()
l = []
tmp = -1
for x in ai:
    if(tmp != x):
        l.append(x)
        tmp = x
l.reverse()

dic = {x : ai.count(x) for x in ai}

m1 = 0
m2 = 0

for x in l:
    tmp = dic[x]
    if(tmp >= 4):
        m1 = m2 = x
        break
    if(2 <= tmp < 4):
        if m1:
            m2 = x
            break
        else :
            m1 = x

print(m1*m2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ai = list(input().split())

ai.sort()
l = []
tmp = -1
for x in ai:
    if(tmp != x):
        l.append(x)
        tmp = x
l.reverse()

dic = {x : ai.count(x) for x in ai}

m1 = 0
m2 = 0

for x in l:
    tmp = dic[x]
    if(tmp >= 4):
        m1 = m2 = x
        break
    if(2 <= tmp < 4):
        if m1:
            m2 = x
            break
        else :
            m1 = x

print(int(m1)*int(m2))

Submission status: Time Limit Exceeded

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

for i in a:
    if a.count(i)>1:
        s.add(i)

s=list(s)
s.sort()
s.reverse()

if len(s)>1:
    print(s[0]*s[1])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num_l=sorted(map(int,input().split()),reverse=True)
s=sorted(set(num_l),reverse=True)
d={i:num_l.count(i) for i in s}
res=[]
#c=max()
for i in num_l:
    if len(res) == 2:
        print(res[0]*res[1])
        break
    if d[i] >= 2:
        d[i]-=2
        res.append(i)
    else:
        pass
else:print(0)

Submission status: Time Limit Exceeded

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

def max_pair(A):
    m1 = 0
    while A:
        m2 = max(A)
        A.remove(m2)
        if m1 == m2:
            return m1
        m1 = m2

    return 0

print(max_pair(A) * max_pair(A))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

bous = Counter(bou)
hen = []
ans = -1

i = 0
while(i<2):
    if len(bous) == 0:
        ans = 0
        break
    
    mkey = max(bous.keys())
    if bous[mkey] > 3:
        bous[mkey] = bous[mkey] - 2
        hen.append(mkey)
        i += 1
    elif bous[mkey] > 1:
        hen.append(mkey)
        bous.pop(mkey)
        i += 1
    else:
        bous.pop(mkey)
    
if ans:
    print(hen[0]*hen[1])
else:
    print(ans)

Submission status: Time Limit Exceeded

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

b = 0
c = 0
while a:
    if a.pop() in a:
        if b == 0:
            b = a.pop()
        elif c == 0:
            c = a.pop()
        else:
            break
print(b * c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
bar = [int(x) for x in input().split()]
ls = []
a,b = 0,0
for x in bar:
    if x>b:
        if x in ls:
            ls.remove(x)
            if x>a:
                b = a
                a = x
            else:
                b = x
        else:
            ls.append(x)
print(a*b)

Submission status: Time Limit Exceeded

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

N = int(input())
A = map(int,input().split())
A = sorted(A,reverse=True)

i = 0
check = 0
x = 0
y = 0

while(i<N and check == 0):
    count = A.count(A[i])
    if(count>=4 and x==0):
        x = A[i]
        y = A[i]
        check = 1
    elif(count>=2):
        if(x == 0):
            x = A[i]
            i = i + count
        else:
            y = A[i]
            check = 1
    else:
        i = i + count

if(check == 0):
    print(check)
else:
    print(x*y)

Submission status: Time Limit Exceeded

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

x = 0
y = 0
S = []

for a in A:
    if a in S:
        if a < x:
            continue
        elif a > y:
            x = y
            y = a
        else:
            x = a
        S.remove(a)
    else:
        S.append(a)

print(x*y)

Submission status: Time Limit Exceeded

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


B = sorted(list(set(A)), reverse=True)

for i in range(len(B)):
    b = B[i]
    n = A.count(b)
    if n >= 2:
        if n >= 4:
            print(b*b)
            exit()
        else:
            C = B[i+1:]
            for c in C:
                if  A.count(c) >= 2:
                    print(b*c)
                    exit()

print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
arr = []
ans = []
ans = []
cnt = []
already = []
for index, i in enumerate(l):
    if l.count(i) >= 2:
        arr.append(i)
if len(arr) == 0:
    print(0)
else:
    for i in arr:
        if i not in already:
            already.append(i)
            cnt.append(arr.count(i))
    for i in range(len(already)):
        for j in range(i, len(already)):
            if i == j and cnt[i] >= 4:
                ans.append(already[i] ** 2)
            elif i != j:
                ans.append(already[i] * already[j])
    print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
l1, l2 = 0, 0
while len(A) > 1:
    if A[-1] == A[-2] and l1 == 0:
        l1 = A[-1]
        A = A[:-2]
    elif A[-1] == A[-2] and l2 == 0:
        l2 = A[-1]
        break
    else:
        A = A[:-1]
print(l1 * l2)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
one=[]
two=[]
three=[]
four=[]
for i in range(N):
    if A[i] not in one:
          one.append(A[i])
    elif A[i] not in two:
          two.append(A[i])
    elif A[i] not in three:
          three.append(A[i])
    elif A[i] not in four:
          four.append(A[i])
    else:
          one.append(A[i])
if len(two)<=1:
    print(0)
elif len(four)==0:
    a = max(two)
    two.remove(a)
    b = max(two)
    print(a*b)
elif max(four)==max(two):
    print(max(four)*max(four))
else:
    a = max(two)
    two.remove(a)
    b = max(two)
    print(a*b)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
memo=[]

h=0; w=0
for element in a:
    if element in memo: pass
    else:
        memo.append(element)
        num=a.count(element)
        if num>=4 and h==0: h=w=element
        elif num>=2 and h==0: h=element
        elif num>=2 and w==0: w=element

ans=h*w
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
memo=[]

h=0; w=0
for element in a:
    if element in memo: pass
    else:
        memo.append(element)
        num=a.count(element)
        if num>=4 and h==0: h=w=element
        elif num>=2 and h==0: h=element
        elif num>=2 and w==0: w=element

ans=h*w
print(ans)

Submission status: Time Limit Exceeded

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


B = list(set(A))          

while B:                  
    b = max(B)            
    if A.count(b) >= 4:   
        print(b**2)       
        exit()            
    elif A.count(b) >=2:  
        B.remove(b)       
        while B:          
            c = max(B)    
            if  A.count(c) >= 2:                    
                print(b*c)                          
                exit()    
            else:         
                B.remove(c)                         
    else:                 
        B.remove(b)       

print(0)

Submission status: Time Limit Exceeded

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

for element in a:
    if element in list: pass
    elif a.count(element)>=2:
        list.append(element)
        if a.count(element)>=4:sqrt.append(element)

list.sort()
sqrt.sort()
n=len(list)
m=len(sqrt)

if n==0: ans=0
elif n==1:
    if m==0: ans=0
    else: ans=max(sqrt)**2
elif n>=2:
    if m==0:
        x=max(list); list.remove(x)
        y=max(list)
        ans=x*y
    else:
        x=max(list); list.remove(x)
        y=max(list)
        ans=x*y
        if ans<max(sqrt)**2: ans=max(sqrt)**2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy 
def search(A):
  B = list(set(A))
  B.sort(reverse=True)
  if len(A)-len(B) < 2: return (0,0)
  else:
    a1,a2 = 0,0
    for a in copy.deepcopy(B):
      A.pop(A.index(a))
      if a in A:
        A.pop(A.index(a))
        a1 = a
        break
      else:
        B.pop(B.index(a))

    if a1 > 0:
      B = list(set(A))
      B.sort(reverse=True)
      if len(A)-len(B) == 0: return (a1,0)
      for a in copy.deepcopy(B):
        if a in A: A.pop(A.index(a))
        if a in A:
          A.pop(A.index(a))
          a2 = a
          break
        else:
          B.pop(B.index(a))
  return (a1,a2)

N = int(input())
A = map(int, input().split())
A = [a for a in A]
A.sort(reverse=True)
a1, a2 = search(A)
if a1 > 0 and a2 > 0: print(a1*a2)
else: print(0)

Submission status: Time Limit Exceeded

Solution code:
import logging
logging.basicConfig(level=logging.DEBUG,format=' %(asctime)s - %(levelname)s - %(message)s')
input()
edge=[]
edge=input().split()
e=[]
for i in range(len(edge)):
    e.append(int(edge[i]))
    logging.info('e[{}] = {}'.format(i,e[i]))
e.sort()
E=[0,0]
j=0
for i in range(len(e)-1,0,-1):
    if e[i]==e[i-1] and not e[i]==E[0]:
        E[j]=e[i]
        logging.info('E[{}] = {}'.format(j,E[j]))
        j+=1
        if E[1]:
            break
print(E[0]*E[1])

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    area = 0
    u_len = []

    #sort_a = sorted(set(a), reverse=True)
    #print(sort_a)
    max_num = max(a)
    for num in range(max_num, 0, -1):
        #print(num)
        c_num = a.count(num)
        if(c_num >= 4):
            area = num**2
            break
        elif(c_num >= 2):
            u_len.append(num)
            if(len(u_len) >= 2):
                area = u_len[0] * u_len[1]
                break
    
    print(area)
    
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

def solve(i):
    if len(que) >=  2:
        return True
    num = A[i]
    check = num in que
    if A.count(num) > 3:
        que.append(num)
        que.append(num)
    elif A.count(num) > 1 and check == False:
        que.append(num)
    if i == N - 1:
        return False
    else:
        return solve(i+1)

a = solve(0)
if a == True:
    ans = que[0] * que[1]
    print(ans)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
cou = int(input())
bars = input().split()
two = [0, 0]
i = 0
ca = len(bars)
while i < ca:
    if bars[i] in two:
        pass
    else:
        if bars.count(bars[i]) > 3:
            two.extend(bars[i])
            two.extend(bars[i])
        elif bars.count(bars[i]) > 1:
            two.extend(bars[i])
        else:
            pass
    i += 1
two.sort(key=int)
print(int(two[-1]) * int(two[-2]))

Submission status: Time Limit Exceeded

Solution code:
count = [0]
N = int(input())
A = map(int, input().split())
B = 0
C = 0

for i in A:
	if B > i and C > i:
		continue
	if i not in count:
		count.append(i)
		continue
	elif B <= i:
		B, C = i, B
		count.remove(i)
	elif C < i:
		C = i
		count.remove(i)

print(B * C)

Submission status: Time Limit Exceeded

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


B = sorted(list(set(A)), reverse=True)

for i in range(len(B)):
    b = B[i]
    if A.count(b) >= 4:
        print(b**2)
        exit()
    elif A.count(b) >=2:
        C = B[i+1:]
        for c in C:
            if  A.count(c) >= 2:
                print(b*c)
                exit()

print(0)

Submission status: Time Limit Exceeded

Solution code:
cou = int(input())
bars = input().split()
two = [0, 0]
i = 0
ca = len(bars)
while i < ca:
    if bars[i] in two:
        pass
    else:
        now = bars[i]
        if bars.count(now) > 3:
            two.extend(now)
            two.extend(now)
        elif bars.count(now) > 1:
            two.extend(now)
        else:
            pass
    i += 1
two.sort(key=int)
ans = int(two[-1]) * int(two[-2])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
cou = int(input())
bars = input().split()
two = [0, 0]
i = 0
ca = len(bars)
while i < ca:
    if bars[i] in two:
        pass
    else:
      now = bars[i]
      if bars.count(now) > 3:
          two.extend(now)
          two.extend(now)
      elif bars.count(now) > 1:
          two.extend(now)
      else:
          pass
    i += 1
two.sort(key=int)
ans = int(two[-1]) * int(two[-2])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = map(int, input().split())
s = 0
for a, b, c, d in itertools.combinations(A, 4):
    l = [a, b, c, d]
    l = sorted(l)
    if l[0] == l[1] and l[2] == l[3]:
        s = max(s, l[0]*l[2])
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
w = 0
h = 0
arr = []
ans = []
arr.append(list(map(int,(input().split()))))
arr = sorted(arr[0])
for num in arr:
    if arr.count(num) >= 2:
        ans.append(num)
if len(ans) < 4:
    print("0")
elif ans.count(ans[-1]) >= 4:
    print(ans[-1] **2)
else:
    w = ans[-1]
    max_num = ans.count(ans[-1])
    for i in range(max_num):
        del ans[-1]
    h = ans[-1]
    print(w * h)