Rikka with Maximum Segment Sum
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Maximum Subsegment Sum is a classical problem. When Rikka first saw this problem, she was still an outsider of competitive programming, and now, she has become a problem setter of this grand event.
Therefore, Rikka decides to set a problem about Maximum Subsegment Sum. Given an array x of length m, its maximum subsegment sum is defined as:

Now, given an integer array A of length n, Rikka wants you to calculate the sum of the maximum subsegment sums of all subsegments of A, i.e.

输入描述:

The first line contains a single integer .
The second line contains n integers .

输出描述:

Output a single line with a single integer, the answer. The answer can be very large, therefore, you are only required to output the answer modulo .
More formally, suppose the answer is x, you are required to find the smallest non-negative integer y satisfying for some integer k.
示例1

输入

复制
5
1 -1 1 -1 1

输出

复制
11
示例2

输入

复制
5
1 -2 3 -4 5

输出

复制
39
示例3

输入

复制
10
1 -3 -5 7 -9 10 8 -6 -4 2

输出

复制
555
示例4

输入

复制
4
-1 -2 -3 -4

输出

复制
18446744073709551596