pandu-product

Pandu has started learning about sub-sets. His teacher gave him a simple work. Given a list of numbers, Pandu has to choose the sub-set which gives the max product. However, the teacher asked Pandu only to submit the max product obtained by taking exactly two numbers from the list. Please help Pandu in finding out the answer to this assignment.

Input Format:

The first line will contain the integer N, the length of the array. The next line contains N space separated integers.

Output Format:

For each test case, output Pandu's query.

Constraints:

2 ≤ N ≤ 105

Subtask 1: (25 points)
0 ≤ Integers ≤ 109

Subtask 2: (75 points)
-109 ≤ Integers ≤ 109

SAMPLE INPUT
2
2 3

SAMPLE OUTPUT
6

Source: hackerearth | Difficulty: EASY


Solutions:
n = eval(input())
arr = list(map(int, input().split()))
arr.sort()
if arr[0] < 0 and arr[1] < 0:
	neg = arr[0] * arr[1]
	pos = arr[-1] * arr[-2]
else:
	neg = arr[0] * arr[1]
	pos = arr[-1] * arr[-2]
print(max(neg, pos))


n = eval(input())
ar = sorted(map(int, input().split()))    
ans  = ar[-1]*ar[-2]
anss = ar[0] * ar[1]
print(max(anss, ans))  


     



# Uses python3
import time
n = eval(input())
a = [int(x) for x in input().split()]

def naive(a):
	result = -99999999
	for i in range(0, n):
		for j in range(i+1, n):
			if a[i]*a[j] > result:
				result = a[i]*a[j]
	return result

def sorted_sol(a):
	a.sort()
	return max(a[-1] * a[-2],a[0]*a[1])
start = time.time()
print((sorted_sol(a)))
#print(time.time()-start)

#start = time.time()
#print(sorted_sol(a))
#print(time.time()-start)