#C2544. Maximum Product of Three Distinct Elements

    ID: 45872 Type: Default 1000ms 256MiB

Maximum Product of Three Distinct Elements

Maximum Product of Three Distinct Elements

You are given an array A of N integers. Your task is to find the maximum product obtained by multiplying any three distinct elements from the array. If it is impossible to choose three distinct elements (i.e. when N < 3), you should print -1.

The product of three numbers a, b, c is given by the formula: ( a \times b \times c ).

inputFormat

The input is read from standard input (stdin). The first line contains an integer N, the number of elements in the array. The second line contains N space-separated integers representing the elements of A.

outputFormat

Output a single integer to standard output (stdout) which is the maximum product formed by any three distinct elements from A. If it is not possible to select three elements, output -1.## sample

5
1 2 3 4 5
60

</p>