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 = input()

a = map(int, raw_input().split())

a.sort()

tmp = [0]

for i in range(n - 1):
    if a[i] == a[i + 1]:
        if max(tmp) != a[i]:
            tmp.append(a[i])

if len(tmp) > 2:
    tmp.reverse()
    print tmp[0] * tmp[1]
else:
    print 0

Submission status: Wrong Answer

Solution code:
import sys

sys.stdin.readline()
d = list(map(int, sys.stdin.readline().strip().split()))

y = None
x = dict()
for i in d:
    if i not in x:
        x[i] = 1
    else:
        x[i] += 1

y = {i:j for i, j in x.items() if j>=2}

z = sorted(y.keys())


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

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
d = map(int, raw_input().split())
dict = {}
for i in range(n):
    if dict.has_key(d[i]):
        dict[d[i]] += 1
    else:
        dict[d[i]] = 1
dict = sorted(dict.items())
ans = []
for i in range(len(dict)-1, -1, -1):
    if dict[i][1] > 3:
        ans = [dict[i][0], dict[i][0]]
        break
    elif dict[i][1] > 1:
        if len(ans) > 0:
            ans.append(dict[i][0])
            break
        else:
            ans.append(dict[i][0])
if len(ans) > 1:
    print ans[0]*ans[1]
else:
    print 0

Submission status: Wrong Answer

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

counter = {}

for i in l:
    if i in counter:
        counter[i] = counter[i] + 1
    else:
        counter[i] = 1

a = None
b = None
for k in sorted(counter.keys(), reverse=True):
    if counter[k] >= 2 and a == None:
        a = k
    elif counter[k] >= 2 and a != None:
        b = k
    if (a != None and b != None):
        break

if (a != None and b!= None):
    print(a * b)
else:
    print('0')

Submission status: Wrong Answer

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

A=sorted(A,reverse=True)
if(len(A)%2==1):
    A.append(0)
c=0
l=1
for i in range(0,len(A),2):
    if(c==2):
        break
    elif(A[i]==A[i+1]):
        c+=1
        l*=A[i]
if(c==2):
    print(l)
else:
    print(int(0))

Submission status: Wrong Answer

Solution code:
N = int(input())
freq = {}
arr = map(int,input().split())
for i in arr:
    try:
        freq[i] += 1
    except KeyError:
        freq[i] = 1

to_multiply = []      
for i in sorted(freq.keys(),reverse=True):
    if freq[i] >= 2:
        to_multiply.append(i)
if len(to_multiply) >= 2:
    print(to_multiply[0] * to_multiply[1])
else:
    print("0")

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
d = map(int, raw_input().split())
dict = {}
for i in range(n):
    if dict.has_key(d[i]):
        dict[d[i]] += 1
    else:
        dict[d[i]] = 1
dict = sorted(dict.items())
ans = []
for i in range(len(dict)-1, -1, -1):
    if dict[i][1] > 3:
        ans = [dict[i][0], dict[i][0]]
    elif dict[i][1] > 1:
        if len(ans) > 0:
            ans.append(dict[i][0])
            break
        else:
            ans.append(dict[i][0])
if len(ans) > 1:
    print ans[0]*ans[1]
else:
    print 0

Submission status: Wrong Answer

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

    a = sorted(A, reverse=True)
    b = set()
    for i in range(N - 1):
        if a[i] == a[i+1]:
            b.add(a[i])

    if len(b) < 2:
        ans = 0
    else:
        edge = sorted(b, reverse=True)
        ans = edge[0] * edge[1]

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    N = int(input())
    counter = Counter(map(int, input().split()))

    a = 0
    b = 0

    def sort_func(t):
        return t[0]
    for length, n in sorted(counter.items(),
                            key=sort_func,
                            reverse=True):
        if n < 2:
            continue
        if a == 0:
            a = length
        else:
            b = length
            break
    print(a * b)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

last_num = 0
first_second_biggest_numpairs = []
for i in range(N):
    if A[i] == last_num:
        if len(first_second_biggest_numpairs) >= 2:
            break
        first_second_biggest_numpairs.append(A[i])
    last_num = A[i]

if len(first_second_biggest_numpairs) == 2:
    print(str(first_second_biggest_numpairs[0] * first_second_biggest_numpairs[1]))
else:
    print("0")

Submission status: Wrong Answer

Solution code:
N = input()
A = sorted([int(i) for i in input().split(' ')])
can = []
for i in range(len(A) - 2):
    if A[i] == A[i + 1]:
        can.append(A[i])
if len(can) == 0:
    print(0)
else:
    print(can[len(can) - 1] * can[len(can) - 2])

Submission status: Wrong Answer

Solution code:
#!/bin/python3

import sys


n = int(input().strip())
ar = list(map(int, input().strip().split(' ')))
ar = sorted(ar)
s = set(ar)
s = list(s)
s = s[::-1]
k = []
for i in s:
    if(ar.count(i)>1):
        k.append(i)
    if(len(k) == 2):
        break
if(len(k)<2):
    print("0")
else:
    print(k[0]*k[1])

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
d = map(int, raw_input().split())
dict = {}
for i in range(n):
    if dict.has_key(d[i]):
        dict[d[i]] += 1
    else:
        dict[d[i]] = 1
dict = sorted(dict.items())
ans = []
for i in range(len(dict)-1, -1, -1):
    if dict[i][1] == 4:
        ans = [dict[i][0], dict[i][0]]
    elif dict[i][1] > 1:
        if len(ans) > 0:
            ans.append(dict[i][0])
            break
        else:
            ans.append(dict[i][0])
if len(ans) > 1:
    print ans[0]*ans[1]
else:
    print 0

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
A.sort()
li = []

for a in A:
    if A.count(a) > 1:
        li.append(a)
        while a in A:
            A.remove(a)

if len(li) != 0:
    print( int(li[-1])*int(li[-2]) )
else:
    print("0")

Submission status: Wrong Answer

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

b=sorted(list(d),reverse=True)


ans1=ans2=0

for i in b:
    if a.count(i)>=2 and ans1==0:
        ans1=i
    elif a.count(i)>=2 and ans1>0:
        ans2=i

    if ans1>0 and ans2>0:
        print(ans1*ans2)
        exit()

print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
h = 0
w = 0
for i in a:
  if a.count(i) >= 2:
    h = i
    break
for j in a:
  if a.count(j) >= 2 and j < i:
    w = j
    break
print(h*w)

Submission status: Wrong Answer

Solution code:
import collections
n = int(raw_input())
sides = map(int, raw_input().split())
obj, result = collections.Counter(sides), list()
for i in obj:
    if obj[i] >= 2:
        result.append(i)
if len(result) < 2:
    temp = list()
    for i in result:
        if obj[i] >= 4:
            temp.append(i)
    print(temp[0] ** 2 if temp else '0')
else:
    result.sort(reverse=True)
    print(result[0] * result[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sa = list(set(a))
sa.sort(reverse=True)
ans = 0
useble = []
for i in sa:
    if len(useble)>=2:
        ans = useble[0]*useble[1]
        break

    if a.count(i)>1:
        useble.append(i)
        if a.count(i)>3:
            useble.append(i)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
c=0
l=1
for i in range(0,len(A),2):
    if(c==4):
        break
    if(A[i]==A[i+1]):
        c+=2
        l*=A[i]
if(c==4):
    print(l)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n = int(raw_input())
sides = map(int, raw_input().split())
obj, result = collections.Counter(sides), list()
for i in obj:
    if obj[i] >= 2:
        result.append(i)
if len(result) < 2:
    print('0')
else:
    result.sort(reverse=True)
    print(result[0] * result[1])

Submission status: Wrong Answer

Solution code:


_ = input()
a = list(map(int, input().split()))
counter = {}

for a_ in a:
    if a_ in counter.keys():
        counter[a_] += 1
    else:
        counter[a_] = 1

ans = 1
cnt = 0
for k, v in sorted(counter.items(), key=lambda x: x[1]):
    while v >= 2:
        if cnt == 2:
            break

        ans *= k
        cnt += 1
        v -= 2

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sa = list(set(a))
sa.sort(reverse=True)
ans = 0
useble = []
for i in sa:
    if len(useble)>=2:
        print(useble[0]*useble[1])
        break

    if a.count(i)>1:
        useble.append(i)
        if a.count(i)>3:
            useble.append(i)

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
b={}
for i in a :
    if i in b :
        b[i] = 2
    else :
        b[i] = 1
c = []
for i,j in b.items():
    if j==2 :
        c.append(i)
c=sorted(c)
if len(c) >= 2 :
    c = sorted(c)
    print c[-1]*c[-2]
else :
    print 0

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A_dict = dict()
for i in A:
    if i in A_dict:
        A_dict[i] += 1
    else:
        A_dict[i] = 1
A_ordered = sorted([i for i in A_dict if A_dict[i] >=2], reverse = True)
if len(A_ordered) >= 2:
    print(A_ordered[0] * A_ordered[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = map(int, input().split())
A=Counter(A)
A = sorted([k for k, v in A.items() if v > 1 ],reverse=True)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
data = list(map(int,input().split()))
tmp = set(data)
arr = []
for x in tmp:
    if data.count(x)>=2:
        arr.append(x)
arr = sorted(arr)
print(arr[-1]*arr[-2] if len(arr)>=2 else 0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sa = list(set(a))
sa.sort(reverse=True)
ans = 0

for i in sa:
    if a.count(i)>=2:
        if ans!=0:
            ans *= i
            break
        else:
            ans = i

print(ans)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]

    lens = defaultdict(int)

    for x in xs:
        lens[x] += 1

    max_a = 0
    max_b = 0

    sides = sorted(
        [(length, num) for length, num in lens.items() if num >= 2],
        reverse=True,
    )

    if len(sides) == 1 and sides[0][1] >= 4:
        max_a = sides[0][0]
        max_b = max_a
    elif len(sides) >= 2:
        max_a = sides[0][0]
        max_b = sides[1][0]

    print(max_a * max_b)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


_ = input()
a = list(map(int, input().split()))
counter = {}

for a_ in a:
    if a_ in counter.keys():
        counter[a_] += 1
    else:
        counter[a_] = 1

ans = 1
cnt = 0
for k, v in sorted(counter.items(), key=lambda x: x[1]):
    while v >= 2:

        if cnt >= 2:
            break

        ans *= k
        v -= 2
        cnt += 1

    if cnt >= 2:
        break

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sa = set(a)
useble = []
for i in sa:
    if a.count(i)>=2:
        useble.append(i)

useble.sort(reverse=True)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
cnt = int(input())
num_list = list(map(int, input().split()))
rect_list = sorted({num for num in num_list if num_list.count(num) > 1})

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
res=[]
for i in range(min(A),max(A)+1) :
  if A.count(i)>=2 :
    res.append(i)
if len(res)<=1 :
  print(0)
else :
  res.sort()
  print(res[-1]*res[-2])

Submission status: Time Limit Exceeded

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

lis = []

for i in set(a):
    if 2 <= a.count(i) <= 3:
        lis.append(i)
    elif 4 <= a.count(i):
        lis.append(i)
        lis.append(i)


lis.sort(reverse=True)
if len(lis) <= 1:
    ans = 0
else:
    ans = lis[0]*lis[1]

print(ans)

Submission status: Time Limit Exceeded

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

lis = []

for i in set(a):
    if 2 <= a.count(i) <= 3:
        lis.append(i)
    elif 4 <= a.count(i):
        lis.append(i)
        lis.append(i)


lis.sort(reverse=True)
if len(lis) <= 1:
    ans = 0
else:
    ans = lis[0]*lis[1]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)
b = []
for i in range(len(a)):
    if a.most_common()[i][1] >= 2:
        b.append(a.most_common()[i])
    else:
        break
b.sort()
if len(b) >= 1 and b[-1][1] >= 4:
    print(b[-1][0] ** 2)
elif len(b) >= 2:
    print(b[-1][0] * b[-2][0])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)
b = []
for i in range(len(a)):
    if a.most_common()[i][1] >= 2:
        b.append(a.most_common()[i])
    else:
        break
b.sort(reverse=True)
if len(b) >= 1 and b[0][1] >= 4:
    print(b[0][0] ** 2)
elif len(b) >= 2:
    print(b[0][0] * b[1][0])
else:
    print(0)

Submission status: Time Limit Exceeded

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

pair = []
unpair = []
for a in A:
    if a in unpair:
        pair.append(a)
        unpair.remove(a)
    else:
        unpair.append(a)

pair.sort()
pair.reverse()
if len(pair) <= 1:
    ans = 0
else:
    ans = pair[0] * pair[1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:

N=input()

list1=input().split()

list1=[int(i) for i in list1]

#print(list1)

aaa=[]

for i in list1:
    #print(list1.count(i))
    if list1.count(i)>=2:
        aaa.append(i)

bbb=[]

for i in list1:
    #print(list1.count(i))
    if list1.count(i)>=4:
        bbb.append(i)

if len(bbb)==0:
    d=0
else:
    d=max(bbb)

aaa.sort(reverse=True)

aaa=set(aaa)

ccc=[]

for i in aaa:
    ccc.append(i)

#print(d)

#print(ccc)

#print(f)

if (d==0) and (len(ccc)<=1):
    print(0)
elif d>=max(ccc):
    print(d*d)
else:
    print(ccc[len(ccc)-1]*ccc[len(ccc)-2])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

A.sort()

s1 = 0
s2 = 0

t = -1
for a in A:
    if a != t:
        ac = A.count(a)
        if ac >= 4:
            s1 = a
            s2 = a
        elif ac >= 2:
            s2 = s1
            s1 = a

    t = a

print(s1 * s2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
i = 0
flg = 2
b = []
while i < n:
    x = a.count(a[i])
    y = x
    while y >= 2 and flg != 0:
        y -= 2
        b.append(a[i])
        flg -= 1
    if flg == 0:
        print(b[0]*b[1])
        exit(0)
    else:
        i += x
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = sorted([a for a in set(A) if 2<=A.count(a)])[::-1]
x = 0
y = 0

for b in B:
  if x==0:
    if 4<=A.count(b):
      x = b
      y = b
    elif 2<=A.count(b):
      x = b
  else:
    if 2<=A.count(b):
      y = b

  if x*y!=0:
    break

print(x*y)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = sorted(list(set(A)))[::-1]
x = 0
y = 0

for b in B:
  if x==0:
    if 4<=A.count(b):
      x = b
      y = b
    elif 2<=A.count(b):
      x = b
  else:
    if 2<=A.count(b):
      y = b

  if x*y!=0:
    break

print(x*y)

Submission status: Time Limit Exceeded

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

b = sorted(set(x for x in a if 2 <= a.count(x)))
if b:
    maxb = b[-1]
    if 4 <= a.count(maxb):
        print(maxb ** 2)
    elif 2 <= len(b):
        print(maxb * b[-2])
    else:
        print(0)
else:
    print(0)

Submission status: Time Limit Exceeded

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

b = [0] * 2
for i in set(a):
    c = a.count(i)
    if 4 <= c:
        b.extend([i] * 2)
    elif 2 <= c:
        b.append(i)
else:
    b.sort()
    print(b[-1] * b[-2])

Submission status: Time Limit Exceeded

Solution code:

def keisan(a):
    a.sort(reverse = True)
    ans = 0
    for i in range(0,n,2):
        if a.count(a[i]) >= 4:
            ans = a[i]*a[i]
            break
        elif a.count(a[i]) >=2:
            
            for j in range(i+a.count(a[i]),n,2):
                if a.count(a[j]) >=2:
                    ans = a[i]*a[j]
                    break
            break
    print(ans)

n = int(input())
in_=list(map(int,input().split()))
keisan(in_)

Submission status: Time Limit Exceeded

Solution code:

def keisan(a):
    a.sort(reverse = True)
    ans = 0
    for i in range(0,n,2):
        if a.count(a[i]) >= 4:
            ans = a[i]*a[i]
            break
        elif a.count(a[i]) >=2:
            
            for j in range(i+a.count(a[i]),n,2):
                if a.count(a[j]) >=2:
                    ans = a[i]*a[j]
                    break
            break
    print(ans)

n = int(input())
in_ = [int(i) for i in input().split()]
keisan(in_)

Submission status: Time Limit Exceeded

Solution code:

def keisan(a):
    a.sort(reverse = True)
    ans = 0
    for i in range(0,n,2):
        if a.count(a[i]) >= 4:
            ans = a[i]*a[i]
            break
        elif a.count(a[i]) >=2:
            if a.count(a[i]) ==3:
                i+=1
            for j in range(i+a.count(a[i]),n,2):
                if a.count(a[j]) >=2:
                    ans = a[i]*a[j]
                    break
            break
    print(ans)

n = int(input())
in_ = [int(i) for i in input().split()]
keisan(in_)

Submission status: Time Limit Exceeded

Solution code:

def keisan(a):
    a.sort(reverse = True)
    ans = 0
    for i in range(n):
        if a.count(a[i]) >= 4:
            ans = a[i]*a[i]
            break
        elif a.count(a[i]) >=2:
            for j in range(i+a.count(a[i]),n):
                if a.count(a[j]) >=2:
                    ans = a[i]*a[j]
                    break
            break
    print(ans)

n = int(input())
in_ = [int(i) for i in input().split()]
keisan(in_)

Submission status: Time Limit Exceeded

Solution code:
from numba import jit
@jit
def keisan(a):
    a.sort(reverse = True)
    ans = 0
    for i in range(n):
        if a.count(a[i]) >= 4:
            ans = a[i]*a[i]
            break
        elif a.count(a[i]) >=2:
            for j in range(i+a.count(a[i]),n):
                if a.count(a[j]) >=2:
                    ans = a[i]*a[j]
                    break
            break
    print(ans)

n = int(input())
in_ = [int(i) for i in input().split()]
keisan(in_)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse = True)
    ans = 0
    for i in range(n):
        if a.count(a[i]) >= 4:
            ans = a[i]*a[i]
            break
        elif a.count(a[i]) >=2:
            for j in range(i+a.count(a[i]),n):
                if a.count(a[j]) >=2:
                    ans = a[i]*a[j]
                    break
            break
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
ans = 0
for i in range(n):
    if a.count(a[i]) >= 4:
        ans = a[i]*a[i]
        break
    elif a.count(a[i]) >=2:
        for j in range(i+a.count(a[i]),n):
            if a.count(a[j]) >=2:
                ans = a[i]*a[j]
                break
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sorted(set(A), reverse=True)
w, h = 0, 0

cnt = 0
for s in S:
  c = A.count(s)
  if c > 1:
    if cnt == 0:
      if c > 3:
        w, h = s, s
        cnt += 2
        break
      else:
        w = s
        cnt += 1
    else:
      h = s
      cnt += 1
      break
ans = w * h
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sorted(set(A), reverse=True)
w, h = 0, 0

cnt = 0
for s in S:
  if A.count(s) > 1:
    if cnt == 0:
      if A.count(s) > 3:
        w, h = s, s
        cnt += 2
        break
      else:
        w = s
        cnt += 1
    else:
      h = s
      cnt += 1
      break
ans = w * h
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
A.sort(reverse=True)
list = []
while len(A) > 1:
    if A[0] == A[1]:
        list.append(A[0])
        A = A[2:]
    else:
        A.pop(0)
if len(list) >= 2:
    print(list[0]*list[1])
else:
    print(0)

Submission status: Time Limit Exceeded

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

a.sort()
a.reverse()

edge = []

i = 0
while i < len(a):
    count_a = a.count(a[i])
    if count_a >= 4:
        edge.append(a[i])
        edge.append(a[i])
        break
    elif 2 <= count_a < 4:
        edge.append(a[i])
        i += count_a
        if len(edge) >= 2:
            break
    else:
        i += 1

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

Submission status: Time Limit Exceeded

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

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

if len(a) <= 1:
    print(0)
else:
    a = set(a)
    a = list(a)
    a.reverse()
    print(a[0]*a[1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

rec=set()
for i in range(n):
  if A.count(A[i])>=2:
    rec.add(A[i])

if len(rec)<2:
  print(0)
else:
  rec=sorted(list(rec), reverse=True)
  print(rec[0]*rec[1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int,input().split()))
max = 0
comb = list(itertools.combinations(A,4))
for i in range(len(comb)):
    item = list(set(comb[i]))
    if len(item) == 2:
        if max < item[0]*item[1]:
            max = item[0]*item[1]

print(max)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int,input().split()))
a = set(A)
max = 0
comb = list(itertools.combinations(A,4))
for i in range(len(comb)):
    item = list(set(comb[i]))
    if len(item) == 2:
        if max < item[0]*item[1]:
            max = item[0]*item[1]

print(max)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = list(map(int,input().split()))
x = [0 for i in range(max(a)+1)]
for i in range(n):
    x[a[i]]+=1
li2 = [0]
li4 = [0]
for i in range(len(x)):
    if x[i]>=4:
        li4.append(i)
    elif x[i]>=2:
        li2.append(i)
ans = li4[-1]**2
ans2 = 0
if len(li2)>=2:
    ans2 = li2[-1]*li2[-2]
else:
    ans2 = 0
print(max(ans,ans2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
nums = list(set(a_list))
nums.sort(reverse=True)
a = 0
b = 0
for num in nums:
	count = a_list.count(num)
	if count > 1:
		if a == 0:
			a = num
			if count > 3:				
				b = num
				break
		else:
			b = num
			break
r = a * b
print(r)

Submission status: Time Limit Exceeded

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

n4 = []
n2 = set()
for a in A:
    if A.count(a) >= 4:
        if len(n4) >= 1:
            break
        n4.append(a)
    elif A.count(a) >= 2:
        if len(n2) >= 2:
            break
        n2.add(a)
n2 = list(n2)

ans = 0
if len(n2) >= 2:
    ans = n2[0] * n2[1]
for i in n4:
    for j in n2:
        ans = max(ans, i*j)
if len(n4) >= 1:
    ans = max(ans, n4[0] ** 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
a = list(map(int, input().split()))
b = sorted(set(a), reverse=True)
c = deque([])
for i in b:
    if a.count(i) >= 4 and c == deque([]):
        print(i*i)
        exit(0)
    elif a.count(i) >= 2:
        c.append(i)
        if len(c)==2:
            print(c[0]*c[1])
            exit(0)
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int,input().split()))
s = set(l)
ss = list(s)
ss.sort(reverse= True)
r = []  
for i in ss:
  if l.count(i) >= 4:
    	r.append(i)
    	r.append(i)
  elif l.count(i) >= 2:
    	r.append(i)
  if len(r) >= 2:
    print(r[0]*r[1])
    exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
_=input()
A=list(map(int,input().split()))
B=list(set(A))
ans=-1
B=sorted(B)[::-1]
for i in B:
  if A.count(i) >=4:
    if ans==-1 : 
      print(i*i)
      exit()
    else:
      print(ans*i)
      exit()
  else:
    if A.count(i) >= 2:
      if ans==-1:
        ans=i
      else:
        print(ans*i)
        exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
be=0
num=[]

for i in a:
  if be==i:
    num.append(i)
    index=a.index(i)
    a[index]=0
    a[index-1]=0
  be=i
  
if len(num)>=2:
  print(max(num)*sorted(num)[-2])
  
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:

r = int(input())

stick = [int(v) for v in input().split()]
stick = sorted(stick, reverse=True)
s_stick = sorted(set(stick), reverse=True)

line = []
for v in s_stick:
    if stick.count(v) >= 4:
        if len(line) == 0:
            print(v * v)
            exit()
        else:
            print(line[0] * v)
            exit()
    if stick.count(v) >= 2:
        line.append(v)
        if len(line) == 2:
            print(line[0] * line[1])
            exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
for i in A:
    d[i] += 1
d = [x for x in d.items() if x[1]>=2]

ans = 0
for i1,j1 in d:
    for i2,j2 in d:
        if j1 >= 2 and j2 >= 2 and i1 != i2:
            ans = max(ans,i1*i2)
        elif i1==i2 and j1>=4 and j2>=4:
            ans = max(ans,i1*i2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
for i in A:
    d[i] += 1

ans = 0
for i1,j1 in d.items():
    for i2,j2 in d.items():
        if j1 >= 2 and j2 >= 2 and i1 != i2:
            ans = max(ans,i1*i2)
        elif i1==i2 and j1>=4 and j2>=4:
            ans = max(ans,i1*i2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=input().split()
As=[int(a) for a in A]
numbers=sorted(As,reverse=True)
list=[]
kotae=0
ai=0
for a in numbers:
    if a in list:
        pass
    else:
        list.append(a)
        kazu=numbers.count(a)
        if kazu>=4:
            print(a**2)
            kotae+=1
            break
        elif kazu>=2 and kazu<4:
            for b in numbers:
                if b in list:
                    pass
                else:
                    list.append(b)
                    suuji=numbers.count(b)
                    if suuji>=2:
                        print(a*b)
                        kotae+=1
                        ai+=1
                        break
    if ai==1:
        break

if kotae==0:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


n = int(input())
a = list(map(int, input().split()))
ans = 0
a = [i for i in a if a.count(i) > 1]
b = [j for j in a if a.count(j) > 3]
a = set(a)
b = set(b)
a -= b
a = list(a)
b = list(b)
for v in combinations(a, 2):
    ans = max(ans, v[0] * v[1])
for s in range(len(b)):
    ans = max(ans, s ** 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in a:
    if a.count(i)>=2:
        b.append(i)
b=sorted(b,reverse=True)
if len(b)<=1:
    print(0)
elif b.count(b[0])>=4:
    print(b[0]*2)
else:
    b=list(set(b))
    b=sorted(b,reverse=True)
    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)

h = 0
w = 0


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

    elif A[i] == A[i+1]:
        h = A[i]
        break

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

print(0)

Submission status: Time Limit Exceeded

Solution code:
def makerectangle(n , a):

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



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

if __name__ == '__main__':
    main()