#C578. Maximum Magical Power
Maximum Magical Power
Maximum Magical Power
You are given a sequence of n positive integers representing the values engraved on magical rings. Your task is to select a contiguous subsequence of these rings such that the product of their values is maximized. Formally, if the rings have values \(a_1, a_2, \dots, a_n\), you must choose indices \(1 \leq i \leq j \leq n\) to maximize:
\(P = \prod_{k=i}^{j} a_k\)
The challenge is to compute this maximum product. Note that since all values are positive, the product of a contiguous subsequence will always be valid without concern for sign changes. However, considering that many rings and their combinations are possible, an efficient brute-force approach is acceptable given the constraints.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains a single integer \(n\) representing the number of rings.
- The second line contains \(n\) space-separated positive integers representing the values on the rings.
outputFormat
Output to stdout a single integer that is the maximum possible magical power calculated as the product of a contiguous subsequence of rings.
## sample5
2 3 4 5 1
120