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: Accepted

Solution code:
int(input())
l=[int(x) for x in input().split()]
arr={}
for i in l:
	if not arr.get(i):
		arr[i]=1
	else:
		arr[i]+=1
max1=0
max2=-1
sqr=0
for i in arr:
	if arr[i]>=2:
		if i > max1:
			max1=i
		if arr[i]>=4:
			sol=i**2
			if sqr < sol :
				sqr=sol
for i in arr:
	if arr[i]>=2:
		if i > max2 and i < max1:
			max2=i

rec=max1 * max2
if rec > sqr:
	print(rec)
else:
	print(sqr)

Submission status: Accepted

Solution code:

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

y=sorted(x)
width=[0,0]
height=[0,0]


for i in range(0,len(y)-1):
    if (y[len(y)-1-i]==y[len(y)-2-i] and width[0]==0):
        width[0]=y[len(y)-1-i]
        width[1]=len(y)-1-i
        continue
    if (width!=0 and y[len(y)-1-i]==y[len(y)-2-i]):
        if(len(y)-1-i==width[1]-1):
            continue
        height[0]=y[len(y)-1-i]
        break



print('{0}'.format(int(width[0])*int(height[0])))



quit()

Submission status: Accepted

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
t=0
th=0
for i in range(0,len(A),2):
    if(c==2):
        break
    if(A[i]==A[i+1]):
        c+=1
        l*=A[i]
        th=True
    elif(t==A[i] and not(th)):
        c+=1
        l*=A[i]
        th=False
    else:
        th=False
    t=A[i+1]
if(c==2):
    print(l)
else:
    print(0)

Submission status: Accepted

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

for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]= 1

keys = sorted(d)
l= sorted(keys,reverse=True)
cnt =0
lenght=[]
found = False
for i in l:
    if d[i]>=4 and cnt <2:
        lenght.append(i)
        lenght.append(i)
        cnt+=2
    elif d[i]>=2 and cnt<2:
        lenght.append(i)
        cnt+=1
    else:
        found = True
        

if cnt>=2:
    print(lenght[0]*lenght[1])
else:
    print(0)

Submission status: Accepted

Solution code:
import itertools

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

num = dict()

for a in A:
    if a not in num:
        num[a] = 0
    num[a] += 1

m1 = 0
m2 = 0

for a in sorted(num.keys(), reverse=True):
    if num[a] >= 2:
        m1 = a
        num[a] = num[a] - 2
        break
for a in sorted(num.keys(), reverse=True):
    if num[a] >= 2:
        m2 = a
        num[a] = num[a] - 2
        break
print(m1*m2)

Submission status: Accepted

Solution code:
n=int(input())
a=map(int, input().split())
a=sorted(a)[::-1]
k=-2
l=-2
for i in range(n-1):
    if (a[i]==a[i+1])&(i>k+1):
        if (k>=0):
            l=i
            break
        else:
            k=i
if l>=0:
    print(a[k]*a[l])
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
hen1 = 0
hen2 = 0
hen_list = {}
for i in a:
    if(not i in hen_list):
        hen_list[i] = 0
    hen_list[i] += 1
for k, v in sorted(hen_list.items(), key=lambda x: -x[0]):
    if(v >= 4 and hen1 == 0):
        hen1 = k
        hen2 = k
        break
    if(v >= 2 and hen1 == 0):
        hen1 = k
    elif(v >= 2 and hen2 == 0):
        hen2 = k
    if(hen2!=0):
        break

print(hen1*hen2)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
b = []
for key,val in Counter(a).items():
    if val >= 2:
        b.append(key)
        if val >= 4:
            b.append(key)

b.sort()

if len(b)>=2:
    x = b.pop()
    y = b.pop()
    ans = x*y
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
num=raw_input()
tmp=map(int, raw_input().split(" "))
tmp.sort()
tmp.reverse()
oldnum=0
arr=[]
flag=0
out=0
for i in range(len(tmp)-1):
    if tmp[i]==tmp[i+1] and flag==0:
            arr.append(tmp[i])
            flag=1
    else:
        flag=0
    if len(arr)==2:
        out=arr[0]*arr[1]
        break
    try:
        if tmp[i]==tmp[i+1] and tmp[i]==tmp[i+2] and tmp[i]==tmp[i+3]:
            out=tmp[i]**2
            break
    except:
        pass
print out

Submission status: Accepted

Solution code:
from collections import *
n=int(input())
c=Counter(map(int,input().split()))
x=y=0
for k,v in c.items():
    if v>=2 and k>y:
        if k>=x:
            if v>=4:
                x=y=k
            else:
                x,y=k,x
        else:
            y=k
print(x*y)

Submission status: Accepted

Solution code:
def c():
    from collections import deque
    n = int(input())
    A = [int(ai) for ai in input().split()]
    A = deque(sorted(A, reverse=True))
    xy = []
    for i in range(1, n):
        # print(A)
        if A[0] == A[1]:
            tmp = A.popleft(); A.popleft()
            xy.append(tmp)
        else:
            A.popleft()

        if len(xy) == 2:
            print(xy[0] * xy[1])
            break
    if len(xy) < 2:
        print(0)

c()

Submission status: Accepted

Solution code:
import sys

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

mstack = []
stack = [0]
for a in A:
    if a == stack[-1]:
        mstack.append(a)
        stack.pop()
        if len(mstack) >= 2:
            print(mstack[-1] * mstack[-2])
            sys.exit()
    else:
        stack.append(a)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
side_list = list(map(int, input().split()))
side_list.sort()
side_list.reverse()

xy = [0, 0]

i = 0
j = 0
while i < N - 1:
    if side_list[i] == side_list[i+1]:
        xy[j] = side_list[i]
        i += 1
        j += 1
        if j > 1:
            break
    i += 1

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

Submission status: Accepted

Solution code:
#Make a Rectangle
N = int(input())
A = list(map(int, input().split()))

a = sorted(A, reverse=True)
b = []

i = 0
while i<N-1:
    if ( a[i]==a[i+1] ):
        b+=[a[i]]
        i+=2
    else:
        i+=1
    if (len(b)>1):
        break

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

Submission status: Accepted

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

while(i<n):
    if bn==a[i]:
        if count == 0:
            ans = a[i]
            if i+1<n:
                bn = a[i+1]
            i += 1
            count +=1
        else:
            ans *= a[i]
            count +=1
            break
    else:
        bn = a[i]
    i +=1

if count>=2:
    print(ans)
else:
    print(0)

Submission status: Accepted

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

    a = sorted(A, reverse=True)
    b = {}
    for i in range(N - 1):
        if a[i] == a[i+1]:
            if a[i] in b.keys():
                b[a[i]] += 1
            else:
                b[a[i]] = 2
    if len(b) < 2:
        ans = 0
    elif b[max(b)] >= 4:
        ans = max(b) ** 2
    else:
        c = sorted(b, reverse=True)
        ans = c[0] * c[1]

    print(ans)

main()

Submission status: Accepted

Solution code:
# coding=utf-8

def count(list, target, num):
    l = len(list)
    c = 0
    for i in xrange(-num, l + 1):
        if list[-i] == target:
            c += 1
            if c == 4:
                return c
        else:
            return c
    return c


N = int(raw_input())
A = map(int, raw_input().split())

candidates = []
A.sort()
t = -1
for i in xrange(0, N + 1):
    n = count(A, A[t], t)
    for m in range(n / 2):
        candidates.append(A[t])
        if len(candidates) == 4:
            break
    t -= n
    if t < -N:
        break
if len(candidates) < 2:
    print 0
else:
    print candidates[0] * candidates[1]

Submission status: Accepted

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n  = read_line(int)

as_ = [int(col) for col in input().split()]

max_a = -1
max_aa = -1

count = {}

for a in as_:
    if a not in count:
        count[a] = 1
    else:
        count[a] += 1

        if a == max_a:
            pass
        elif a > max_a:
            max_aa = max_a
            max_a = a
        elif a > max_aa:
            max_aa = a
    # print(count, max_a, max_aa)

if max_a > 0 and count[max_a] >= 4:
    print(max_a * max_a)
    exit()

if max_a > 0 and max_aa > 0:
    print(max_a * max_aa)
    exit()

print(0)

Submission status: Accepted

Solution code:
N = int(input())						# 5
a = [int(i) for i in input().split()]	# 1 2 3 4 5 ...


a.sort(reverse=True)

s=0
t=0
x=0
y=0
for _ in range(N):
	i = a[_]
	if t==0:
		if(s==i):
			t = i
		else:
			s = i
	else:
		if(x==i):
			y = i
			break
		else:
			x = i


print(s * x)

Submission status: Accepted

Solution code:
import sys

N=input()
#print N
A=list(map(int,raw_input().split()))
A.sort()
#print A

hen=[]
tmp_hen=-1
for i in reversed(A):
	if len(hen)==2:
		break
	if tmp_hen==i:
		hen.append(i)
		tmp_hen=-1
	else:
		tmp_hen=i


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

Submission status: Accepted

Solution code:
#!/bin/python3

import sys


n = int(input().strip())
ar = list(map(int, input().strip().split(' ')))
ar = sorted(ar,reverse=True)
k = []
se = set(k)
for i in range(len(ar)-1):
    if(ar[i] == ar[i+1]):
        if(ar.count(ar[i])>=4 and len(se) == 0):
            print(ar[i]*ar[i])
            exit(0)
        se.add(ar[i])
    if(len(se)>1):
        break

se = list(se)
if(len(se)<2):
    print("0")
else:
    print(se[0]*se[1])

Submission status: Accepted

Solution code:
n = int(input())
a_in = list(input().split())
a = list(map(int,a_in))
a.sort(reverse=True)
ans = 0
t = 0
c = 1

for i in range(n-1):
    if a[i] == a[i+1]:
        c = c + 1
        if t == 0:
            t = int(a[i])
        elif t != int(a[i]):
            ans = t * int(a[i])
            break
        elif c == 4:
            ans = t * t
            break
    else:
        c = 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n = input()
n = int(n)
a_list = input().split()
a_list = [int(a) for a in a_list]

a_dict = dict()
for a in a_list:
    if a in a_dict:
        a_dict[a] += 1
    else:
        a_dict[a] = 1


l = []
for k,v in a_dict.items():
    l.append([k,v])
ar = np.array(l)

menseki = 1
for i in range(2):
    ar = ar[ar[:,1]>=2]
    if len(ar) == 0:
        menseki = 0
        break
    else:
        saidai = ar[:,0].max()
        menseki *= saidai
        ar[ar[:,0]==saidai,1] -=2
print(menseki)

Submission status: Accepted

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
            if n >= 4:
                b = length
                break
        else:
            b = length
            break
    print(a * b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
a = 0
b = 0

for i in range(N):
    if A[i] not in d:
        d[A[i]] = 1
    else:
        d[A[i]] += 1
    if d[A[i]] == 2 or d[A[i]] == 4:
        if A[i] > a:
            b = a
            a = A[i]
        elif A[i] > b:
            b = A[i]

print(a * b)

Submission status: Accepted

Solution code:
N=int(raw_input())
A=[int(x) for x in raw_input().split()]
 
used=dict()
for a in A:
    if a in used:
        used[a] += 1
    else:
        used[a]=1

B=[]
for a in used:
    if used[a]>=4:
        B.append(a)
        B.append(a)
    elif used[a]>=2:
        B.append(a)

if len(B)<2:
    print 0
else:
    B.sort(reverse=True)
    print B[0]*B[1]

Submission status: Accepted

Solution code:
# coding=utf-8


# x,a,b = map(int, input().split())
# if abs(x-a) < abs(x-b):
#     print('A')
# else :
#     print('B')

#BBBBBBBBB
# hoge = [0] * 26
# a = ord('a')
# string = input()
# for i in range(len(string)):
#     hoge[ord(string[i])-a] = 1

# for i in range(26):
#     if hoge[i] == 0:
#         print(chr(i+a))
#         break
#     if i == 25:
#         print('None')


###CCCC

n = map(int, input().split())
A = map(int, input().split())
A = sorted(A,reverse = True)
# print(A)
e1 = A[0]
e2 = 0
hoge = False
skip = 0
# print(range(1,len(A)-1))
for i in range(1,len(A)-1):
    # print('i={}'.format(i))
    if i == skip:
        # print('cont')
        continue
    else:
        if hoge == False:
            if A[i] == e1 :
                hoge = True
                e2 = A[i+1]
                skip = i+1
                # print('skip={}'.format(skip))
            else :
                e1 = A[i] 
        else:
            if A[i] == e2 :
                # print('break')
                break
            else:
                e2 = A[i]
        if i == range(1,len(A)-1)[-1]:
            e2 = 0

print(e1*e2)

Submission status: Accepted

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

first_second_biggest_numpairs = []

flag = False
for i in range(N):
    if flag == True:
        flag = False
        continue
    if i + 1 < N:
        if A[i] == A[i + 1]:
            if len(first_second_biggest_numpairs) < 2:
                first_second_biggest_numpairs.append(A[i])
                flag = True
            else:
                break
            
if len(first_second_biggest_numpairs) == 2:
    print(str(first_second_biggest_numpairs[0] * first_second_biggest_numpairs[1]))
else:
    print("0")

Submission status: Accepted

Solution code:
tree_dict = dict()

input()
l = map(int, raw_input().split())

for x in l:
    if tree_dict.has_key(x):
        tree_dict[x] += 1
    else:
        tree_dict[x] = 1

long_line = 0
short_line = 0

for k,v in tree_dict.iteritems():
    if v >= 4:
        (_,_,short_line,long_line) = sorted((k,k,short_line,long_line))
        next
    if v >= 2:
        (_,short_line,long_line) = sorted((k,short_line,long_line))


print(long_line * short_line)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
data = list(map(int,input().split()))
dic = {}
max1=0
max2=0
for x in data:
    if x not in dic:
        dic[x]=1
    else:
        dic[x]+=1
    if dic[x]>=2:
        if max1<x:
            max2=max1
            max1=x
            dic[x]=0
        elif max2<x:
            max2=x
            dic[x]=0
        else:
            pass
print(max1*max2)

Submission status: Accepted

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] >= 4 and a == None and b == None:
        a = k
        b = k
    elif 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: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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:
    if y[z[-1]] >= 4:
        print(z[-1]**2)
    else:
        print(z[-1] * z[-2])
else:
    print(0)

Submission status: Accepted

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:
        if len(ans) == 0:
            ans = [dict[i][0], dict[i][0]]
            break
        else:
            ans.append(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: Accepted

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

a,b = 0,0
A.sort(reverse=True)
for i in range(N-1):
    if A[i] == A[i+1]:
        a = A[i]
        A.remove(a)
        A.remove(a)
        break
for i in range(N-3):
    if A[i] == A[i+1]:
        b = A[i]
        break

print(a*b)

Submission status: Accepted

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] >= 4:
        to_multiply.append(i)
        to_multiply.append(i)
    elif freq[i] >= 2:
        to_multiply.append(i)
if len(to_multiply) >= 2:
    print(to_multiply[0] * to_multiply[1])
else:
    print("0")

Submission status: Accepted

Solution code:
n = input()
bars = map(int,raw_input().split(' '))
bars.sort()
h1_cand=0
h2_cand=0
h1=0
h2=0
for i in range(n):
  m = n-1-i
  if h1 > 0:
    if h2_cand == bars[m]:
      h2 = h2_cand
      break
    else:
      h2_cand = bars[m]
  else:
	if h1_cand == bars[m]:
    	  h1 = h1_cand
    	  h1_cand = 0
  	else:
    	  h1_cand = bars[m]
 
print h1*h2

Submission status: Accepted

Solution code:
#! -*- coding:utf-8 -*-
n = int(input())
a = map(int,input().split())
a = list(a)
a = sorted(a,reverse=True)

x = 0
tmp = 0
for i in range(len(a)):
    #print(a)
    #print(tmp,a[0])
    if tmp == a[0]:
        x = a[0]
        a.remove(a[0])
        break
    else:
        tmp = a[0]
        a.remove(a[0])

b = 0
tmp = 0
for i in range(len(a)):
    if tmp == a[0]:
        b = a[0]
        break
    else:
        tmp = a[0]
        a.remove(a[0])

#print(x)
#print(b)
print(x*b)

Submission status: Accepted

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[i] == a[i+1]:
    h = a[i]
    break
for j in range(i+2, n-1):
  if a[j] == a[j+1]:
    w = a[j]
    break
print(h*w)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = map(int, input().split())
A=Counter(A)
t = []
for k, v in A.items():
    if v > 1:
        t.append(k)
        if v > 3:
            t.append(k)
A = sorted(t,reverse=True)
if len(A) < 2:
    print(0)
else:
    print(A[0] * A[1])

Submission status: Accepted

Solution code:
N = int(input())
listA = input().split()
listA = [int(i) for i in listA]
listA.sort()
listA.reverse()
side1 = 0
side2 = 0

# print(side1, side2, listA)
if N == 1 or N == 2 or N == 3:
    pass
else:
    while len(listA) != 1:
        if listA[0] == listA[1]:
            if side1 == 0:
                side1 = listA[0]
                listA.pop(0)
                listA.pop(0)
            else:
                side2 = listA[0]
                break
        else:
            listA.pop(0)
        # print(side1, side2, listA)

print(side1 * side2)
# print(side1, side2, listA)

Submission status: Accepted

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)
candidate_ans = [0]
if len(A_ordered) >= 2:
    candidate_ans.append(A_ordered[0] * A_ordered[1])
for i in A_ordered:
    if A_dict[i] >= 4:
        candidate_ans.append(i ** 2)
        break
print(max(candidate_ans))

Submission status: Accepted

Solution code:
#coding=UTF-8

N=int(input())

mozir=input()
hyo=mozir.split(' ')
A=[int(mono) for mono in hyo]

ans=0
kireiA=sorted(A,reverse=True)
mae=0
tmphen=0
for bo in kireiA:
    if mae==bo:
        if tmphen == 0:
            tmphen=mae
            mae=0 # do not use again
            continue
        else:
            ans=tmphen*mae
            break

    mae=bo

print(ans)

Submission status: Accepted

Solution code:
import collections as col


n = int(input())
a = col.Counter(map(int, input().split()))

edges = []
for k, v in a.items():
    if v >= 4:
        edges.extend((k, k))
    elif v >= 2:
        edges.append(k)

edges.sort(reverse=True)

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

Submission status: Accepted

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

counter = sorted(counter.items(), key=lambda x: x[0],
                 reverse=True)

for k, v in counter:
    while v >= 2:
        if cnt == 2:
            break

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

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

Submission status: Accepted

Solution code:
n=input()
lens=raw_input().split()
lens=[int(x) for x in lens]
lens.sort()
lens=lens[::-1]
i=0
needed=[]
while i<n-1:
    if lens[i] == lens[i+1]:
        needed.append(lens[i])
        i+=1
    i+=1
if len(needed)<2:print '0'
else: print needed[0]*needed[1]

Submission status: Accepted

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

Submission status: Accepted

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

l = 0
ans = []
for i in a:
    if l == i:
        ans.append(i)
        l = 0
    else:
        l = i
    if len(ans) == 2:
        print(ans[0] * ans[1])
        exit()
print(0)

Submission status: Accepted

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

prev = 0
es = []
for a in reversed(sorted(A)):
    if(prev == a):
        es.append(a)
        prev = 0
        if len(es) == 2:
            print(es[0] * es[1])
            break
    else:
        prev = a
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
inp = lambda t: t(sys.stdin.readline().strip())
inpm = lambda t: map(t, sys.stdin.readline().split())
inpl = lambda t: list(map(t, sys.stdin.readline().split()))

n = inp(int)
l = inpl(int)

s = set()

a = 0
b = 0

for i in l:
	if i in s:
		if i > a and a < b:
			a = i
		elif i > b:
			b = i
		s.remove(i)
	else:
		s.add(i)

print(a * b)

Submission status: Accepted

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: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
tmp = input()
As = [int(a) for a in tmp.split()]

dic = {}
maxes = [0, 0]
for a in As:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
    if dic[a] % 2 == 0:
        if maxes[0] < a:
            maxes[0], maxes[1] = a, maxes[0]
        elif maxes[1] < a:
            maxes[1] = a

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

Submission status: Accepted

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

A = sorted(A, reverse=True)


pairs = []

flag = True

for i in range(1, len(A)):
    if flag:
        if A[i] == A[i-1]:
            pairs.append(A[i])
            flag = False
    else:
        flag = True
        
if len(pairs) < 2:
    print(0)
else:
    print(pairs[0]*pairs[1])

Submission status: Runtime Error

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

d={}

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
hst = [0] * (max(A) + 1)
for a in A:
    hst[a] += 1

rec = []
squ = []
A_ = list(set(A))
for a in A_:
    if hst[a] > 1:
        rec.append(a)
    if hst[a] >= 4:
        squ.append(a)

# print(rec)
# print(squ)

s = 0
if len(squ) != 0:
    s = squ[-1]**2

if len(rec) < 2:
    print(s)
else:
    print(max(s, rec[-1]*rec[-2]))

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
hst = [0] * (max(A) + 1)
for a in A:
    hst[a] += 1

rec = []
squ = []
for a in list(set(A)):
    if hst[a] > 1:
        rec.append(a)
    if hst[a] >= 4:
        squ.append(a)

# print(rec)
# print(squ)

s = 0
if len(squ) != 0:
    s = squ[-1]**2

if len(rec) < 2:
    print(s)
else:
    print(max(s, rec[-1]*rec[-2]))

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
hst = [0] * (max(A) + 1)
for a in A:
    hst[a] += 1

rec = []
squ = []
for a in list(set(A)):
    if hst[a] > 1:
        rec.append(a)
    if hst[a] >= 4:
        squ.append(a)

# print(rec)
# print(squ)

s = 0
if len(squ) != 0:
    s = squ[-1]**2

if len(rec) < 2 and s == 0:
    print(0)
else:
    print(max(s, rec[-1]*rec[-2]))

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
hst = [0] * (A[-1] + 1)
for a in A:
    hst[a] += 1

rec = []
squ = []
for a in list(set(A)):
    if hst[a] > 1:
        rec.append(a)
    if hst[a] >= 4:
        squ.append(a)

# print(rec)
# print(squ)

s = 0
if len(squ) != 0:
    s = squ[-1]**2

if len(rec) <= 1 and len(squ) < 1:
    print(0)
else:
    print(max(s, rec[-1]*rec[-2]))

Submission status: Runtime Error

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


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

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

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

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


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

    Num = [0] * 10**9
    for a in A:
        Num[a-1] += 1

    l1 = l2 = 0
    for i in range(N-1, -1, -1):
        if l1 == 0:
            if Num[i] >= 2:
                l1 = i+1
                if Num[i] >= 4:
                    l2 = i+1
                    break
        else:
            if Num[i] >= 2:
                l2 = i+1
                break

    print(l1*l2)


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

Submission status: Runtime Error

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


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

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

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

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


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

    Num = [0] * N

    print(l1*l2)


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

Submission status: Runtime Error

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


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

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

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

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


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

    Num = [0] * N
    for a in A:
        Num[a-1] += 1

    l1 = l2 = 0
    print(l1*l2)


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