Sum Over Zero

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

문제

You are given an array a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n of nn integers. Consider SS as a set of segments satisfying the following conditions.

  • Each element of SS should be in form \[x,y]\[x, y], where xx and yy are integers between 11 and nn, inclusive, and xyx \leq y.
  • No two segments in SS intersect with each other. Two segments \[a,b]\[a, b] and \[c,d]\[c, d] intersect if and only if there exists an integer xx such that axba \leq x \leq b and cxdc \leq x \leq d.
  • For each \[x,y]\[x, y] in SS, a_x+a_x+1++a_y0a\_x+a\_{x+1}+ \ldots +a\_y \geq 0.

The length of the segment \[x,y]\[x, y] is defined as yx+1y-x+1. f(S)f(S) is defined as the sum of the lengths of every element in SS. In a formal way, f(S)=_\[x,y]S(yx+1)f(S) = \sum\_{\[x, y] \in S} (y - x + 1). Note that if SS is empty, f(S)f(S) is 00.

What is the maximum f(S)f(S) among all possible SS?

입력

The first line contains one integer nn (1n21051 \leq n \leq 2 \cdot 10^5).

The next line is followed by nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n (109a_i109-10^9 \leq a\_i \leq 10^9).

출력

Print a single integer, the maximum f(S)f(S) among every possible SS.