cswork / OAOpen practice workspace

AmazonOA #198

Get Max Aggregate Temperature Change

Estimated EasyJudge-ready

Topics (AI-labelled)Prefix & Ranges

The aggregate temperature change of day i is the larger of the prefix sum from day 1 to day i and the suffix sum from day i to the last day; both parts include day i. Return the maximum aggregate temperature change over all days; an empty prefix or suffix is not allowed.

Input

The first line contains n; the second line contains n temperature changes. 1≤n≤100000, −10^9≤change≤10^9.

Output

Output a single integer, the answer.

Example 1

Input:

3
6 -2 5

Output:

9

Example 2

Input:

3
-1 2 3

Output:

5

Example 3

Input:

3
-5 -2 -8

Output:

-5

Example notes

The answers are 9, 5 and −5; in the last example you cannot choose an empty segment to get 0.

Editorial

Loading solution…