#C14647. Maximum Product of Two Distinct Elements

    ID: 44319 Type: Default 1000ms 256MiB

Maximum Product of Two Distinct Elements

Maximum Product of Two Distinct Elements

Given a list of integers, determine the maximum product of any two distinct elements. The product may come from either two large positive numbers or two very small (negative) numbers, since the product of two negatives is positive. If the array contains fewer than two elements, output the exact error message: "Array must contain at least two elements."

The input is provided via standard input and the output should be sent to standard output.

Note: To handle both positive and negative numbers correctly, compute both the product of the two largest numbers and the product of the two smallest numbers. Then, take the maximum of these two products:

\[ \max( a \times b,\ c \times d ) \]

where \(a\) and \(b\) are the two largest numbers and \(c\) and \(d\) are the two smallest numbers in the array.

inputFormat

The first line of input contains an integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

If \(n \ge 2\), output the maximum product of any two distinct elements. Otherwise, output the exact string "Array must contain at least two elements."

## sample
5
5 6 -2 3 11
66