LogiQuest

241. Maximum Product Subarray

MediumDynamic Programming

Print the largest product of a contiguous subarray.

Input format

Line 1: n Line 2: n integers

Output format

The maximum product.

Example 1

Input

4
2 3 -2 4

Output

6

Example 2

Input

3
-2 0 -1

Output

0

Constraints

1 ≤ n ≤ 2 × 10⁴ −10 ≤ values ≤ 10

Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.

Loading the MyLoginn IDE…