Rikka with Maximum Subsegment Sum

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

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 xx of length mm, its maximum subsegment sum mss(A)\operatorname{mss}(A) is defined as: mss(A)=max_1ijm(_k=ijx_k).\operatorname{mss}(A) = \max\_{1\leq i \leq j \leq m} \left(\sum\_{k=i}^j x\_k \right) .

Now, given an integer array AA of length nn, Rikka wants you to calculate the sum of the maximum subsegment sums of all subsegments of AA, i.e. _1ijnmss(\[A_i,,A_j]).\sum\_{1 \leq i \leq j \leq n} \operatorname{mss}(\[A\_i, \dots, A\_j]) .

입력

The first line contains a single integer n (1n105)n\ (1 \leq n \leq 10^5).

The second line contains nn integers A_i (109A_i109)A\_i\ (-10^9 \leq A\_i \leq 10^9).

출력

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 2642^{64}.

More formally, suppose the answer is xx, you are required to find the smallest non-negative integer yy satisfying y=x+k×264y = x + k \times 2^{64} for some integer kk.