#C13661. Highest Product of Three
Highest Product of Three
Highest Product of Three
Given a list of integers, your task is to compute the highest product obtainable by multiplying any three numbers from the list. This problem becomes interesting when negative numbers are included, as the product of two negatives can become positive.
One way to solve this problem is to sort the list and then consider two cases:
- The product of the three largest numbers, i.e. \(a_{n-2} \times a_{n-1} \times a_n\).
- The product of the two smallest numbers and the largest number, i.e. \(a_1 \times a_2 \times a_n\), which can be larger if the smallest numbers are negative.
If the list contains fewer than three numbers, output the error message "Less than three numbers provided".
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains an integer \(n\) (where \(n \geq 1\)) representing the number of integers in the list.
- The second line contains \(n\) space-separated integers.
outputFormat
Output the highest product obtained by multiplying any three numbers from the given list on stdout. If \(n < 3\), output the error message "Less than three numbers provided".
## sample4
1 2 3 4
24
</p>