#C13657. Maximum Product of Three

    ID: 43219 Type: Default 1000ms 256MiB

Maximum Product of Three

Maximum Product of Three

You are given a list of integers. Your task is to determine the maximum product that can be obtained by multiplying any three distinct integers from the list. This maximum product is defined as the maximum value between the product of the three largest numbers and the product of the two smallest numbers (which may be negative) with the largest number.

If the list contains fewer than three elements, output an error message: (\text{List must have at least three elements.}).

For valid inputs, print the maximum product followed by a space and the word Success.

inputFormat

The first line contains a single integer (n) which is the number of elements in the list. The second line contains (n) space-separated integers.

outputFormat

If (n < 3), print a single line with the message: List must have at least three elements. Otherwise, print a single line containing the maximum product of any three integers, followed by a space and the word Success.## sample

4
1 2 3 4
24 Success