#C4417. Highest Product of Three Numbers

    ID: 47953 Type: Default 1000ms 256MiB

Highest Product of Three Numbers

Highest Product of Three Numbers

You are given a list of integers. Your task is to find the highest possible product that can be achieved by multiplying exactly three of the integers from the list.

After sorting the list, one optimal way to obtain the answer is to compute the maximum between the product of the three largest numbers and the product of the two smallest numbers (which could be negative) with the largest number. Formally, if the sorted array is \(nums\), then the answer is given by:

$$ \max(nums[n-1] \times nums[n-2] \times nums[n-3],\; nums[0] \times nums[1] \times nums[n-1]) $$

Note: The input is guaranteed to have at least three integers.

inputFormat

The input consists of two lines:

  1. The first line contains a single integer \(n\) (with \(n \ge 3\)), representing the number of integers in the list.
  2. The second line contains \(n\) space-separated integers.

outputFormat

Output a single integer—the highest possible product obtained by multiplying exactly three of the provided integers.

## sample
5
1 2 3 4 5
60