Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/massiv-eng-katta-qism-yigindi

Maximum sum subarray

Medium 1000 ms 128 MB 59%
Share

A positive integer $n$ and an array of $n$ integers are given. Find the largest sum among the non-empty contiguous subarrays of the array.

The contiguous part of the array with the largest sum

Input

The first line contains a positive integer $n$. The second line contains $n$ integers separated by spaces.

Output

One integer — the largest subarray sum.

Note

$1 \le n \le 2 * 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$

Examples

Input #1
6
-2 1 -3 4 -1 2
Output #1
5
Input #2
3
-5 -1 -8
Output #2
-1

Sign in to submit a solution

Signing up is free and takes a minute.