 # Maximum product of an increasing subsequence of size 3

Given an array of integers A of size N.
Your task is to find maximum product of increasing subsequence of size 3
i.e. you need to find maximum value of A[i] * A[j] * A[k] such that A[i] < A[j] < A[k] and i < j < k < N for all
increasing subsequences of size 3.

If there is no increasing subsequence of size 3 return -1,
else return maximum product of increasing subsequence of size 3 modulo 109+7.

Note: All elements of the array A are distinct.

Input Format

``````The only argument given is the integer array A.
``````

Output Format

``````If there is no increasing subsequence of size 3 return -1,
else return the maximum product of increasing subsequence of size 3 modulo 10^9+7.
``````

Constraints

``````1 <= N <= 100000
1 <= A[i] <= 10^6
``````

For Example

``````Input 1:
A = [10, 11, 9, 5, 6, 1, 20]
Output 1:
2200
Explanation 1:
Maximum product is achieved when i=0, j=1, k=6 i.e A * A * A = 10 * 11 * 20 = 2200.

Input 2:
A = [5, 4, 3, 2, 1]
Output 2:
-1
Explanation 2:
There is no increasing subsequence of size 3.
``````
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details. 