White Rabbit is making milk! Black Rabbit is excited to try the new White Rabbit Milk launched at 7-11 stalls today.
There are N stalls. Black Rabbit wants to choose a contiguous section (of at least size 1) of stores to buy Rabbit Milk, and the satisfaction he gains is the product of quality across all the stores. However, White Rabbit's Milk has inconsistent quality, and may even be zero or negative. Store i has quality Ai. What is the maximum satisfaction he can gain?
It is guaranteed that for any contiguous section of stalls, the absolute value of the product of their quality doesn't exceed 1017.
The first line of input will contain two integers, N.
The next line contains N integers, describing the quality of Rabbit Milk, Ai, of each store.
The output should contain one integer, the maximum number of satisfaction Black Rabbit can gain.
For all subtasks: 1 ≤ N ≤ 1 000 000. -3 ≤ Ai ≤ 3
Subtask 1 (12%): N ≤ 400.
Subtask 2 (36%): N ≤ 4000.
Subtask 3 (8%): Ai ≥ 0.
Subtask 4 (24%): Ai ≠ 0.
Subtask 5 (20%): No additional constraints.
Subtask 6 (0%): Sample.
7 -1 2 -3 1 -2 0 3
12
If he takes the 2nd to 5th stalls, he gets a total of 12 satisfaction.
Subtask | Score |
---|---|
1 | 12 |
2 | 36 |
3 | 8 |
4 | 24 |
5 | 20 |
6 | 0 |