Maximum Product Subarray

MEDIUM-HARD · C · 3000ms

For a bonus scheme, Antu wants the maximum PRODUCT of ticket sales over any contiguous stretch of days, even though some days had negative (refunded) totals. Given N integers (can be negative or zero), print the maximum product of a contiguous subarray.

Input

Line1: N. Line2: N integers.

Output

Maximum product.

Constraints

1 ≤ N ≤ 10^5, |a_i| ≤ 20

Sample Input

5
2 3 -2 4 -1

Sample Output

48
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

Maximum Product Subarray · DIU ContestHub