#C12501. Maximum Product of Three Numbers

    ID: 41936 Type: Default 1000ms 256MiB

Maximum Product of Three Numbers

Maximum Product of Three Numbers

Given a list of integers, your task is to determine the maximum product achievable by multiplying any three numbers from the list. Note that the maximum product could come either from the three largest numbers or from the combination of the two smallest (most negative) numbers with the largest number.

Formally, if the sorted list is \(a_1 \le a_2 \le \ldots \le a_n\), then the answer is given by:

\(\max(a_{n} \times a_{n-1} \times a_{n-2},\; a_1 \times a_2 \times a_{n})\)

inputFormat

The first line contains an integer \(n\) indicating the number of integers in the list. The second line contains \(n\) space-separated integers.

outputFormat

Output a single integer which is the maximum product of any three numbers from the list.

## sample
3
1 2 3
6