Score of a Subsequence

Find the maximum over all contiguous subarrays of the weighted sum where the k-th element from the subarray start contributes k times its value.

Medium5Dynamic programmingArrayGreedyPrefix sumInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

The score of a sequence s=s1,s2,,sns = s_1, s_2, \dots, s_n is i=1ni×si\sum_{i=1}^{n} i \times s_i.

A contiguous subsequence is a sequence of its own, so the weights 1,2,3,1, 2, 3, \dots count again from its first term. The score of the contiguous subsequence sl,sl+1,,srs_l, s_{l+1}, \dots, s_r is i=lr(il+1)×si\sum_{i=l}^{r} (i - l + 1) \times s_i.

Write a program that finds the largest score among the contiguous subsequences of ss. A subsequence of length 0 can be chosen, and its score is 0.

Input

The first line contains nn (1n2000001 \le n \le 200\,000).

The second line contains s1,s2,,sns_1, s_2, \dots, s_n. (si107|s_i| \le 10^7)

Output

Print the largest score among the contiguous subsequences of ss on the first line.