10
-3 4 -4 1 1 -4 -5 3 -4 -2
 10
8 9 -10 -10 -4 -3 5 9 -9 9
 6
5 -4 2 -1 2 -2
 11
3 0 1 -2 5 -5 -1 0 3 2 2
 10
4 -2 -2 -2 2 0 1 0 -4 -1
 4
2 2 -3 4
 11
-11 -7 -2 -24 30 -26 24 9 -8 -9 23
 6
30 -29 5 5 -29 30
 24
-8 -6 6 -11 -15 -7 10 -19 -6 21 14 -4 -21 -10 12 17 1 -1 5 19 2 0 -4 -23
 10
-9 -6 -1 9 -2 0 0 -1 5 0
 6
10 -8 3 3 -8 10
 10
-2 -3 -1 4 -3 2 0 1 -5 4
 5
30 -29 10 -1 10
 31
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -29 30
 7
30 -20 5 1 3 -20 30
 5
30 -29 4 -3 4
 10
-5 28 -18 -10 9 -2 11 -6 -19 30
 8
4 -10 13 -13 2 2 -11 6
 131
30 -29 29 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 27 -26 27
 10
-4 4 0 -2 3 0 1 2 3 -4
 10
-2 -8 5 4 -1 -6 -9 6 1 -6
 7
25 -17 13 13 -25 25 -24
 10
3 -3 2 1 -4 -2 3 -2 -3 0
 10
4 -5 0 4 0 0 -3 1 1 -4
 10
0 4 4 1 -3 4 2 1 4 -1
 17
15 -13 7 8 8 1 -19 12 8 -23 -4 16 -13 -28 10 -30 -14
 4
1 1 -4 10
 11
3 -2 1 1 1 1 1 1 1 -3 4
 7
30 -29 10 10 10 -29 30
 7
25 -13 17 -23 12 12 9
 7
15 -14 10 10 10 -14 15
 10
3 0 0 -4 3 1 -2 -1 -1 4
 6
8 -7 7 -6 5 5
 10
1 -4 -4 4 -2 -3 3 0 -2 3
 15
1 -26 -6 26 7 10 -2 -4 -6 14 -9 25 9 -12 -28
 6
30 -29 10 10 -29 30
 1
6
 2
1 1
 5
0 5 -4 3 -1
 7
5 -4 3 -1 3 -4 4
 10
16 -15 13 -1 10 -2 -20 26 5 -30
 10
-1 2 0 -1 2 -1 4 3 -5 1
 7
5 -4 1 1 1 -4 5
 5
10 -3 -5 3 5
 10
4 -4 3 -2 3 -4 -2 0 1 0
 10
-5 -5 -3 1 -2 2 0 2 -3 4
 10
2 -4 -2 3 1 1 -2 -1 -3 4
 10
-4 -5 4 -3 2 -2 2 1 -1 0
 10
0 -1 4 -2 3 -2 -1 -5 -5 2
 5
19 -6 1 -11 19
 10
1 0 -4 3 -5 3 -1 2 2 -5
 7
5 -5 3 4 3 -5 5
 10
-5 2 -3 -3 -4 3 3 0 2 4
 4
2 3 -10 11
 10
27 -17 15 -22 18 17 -6 2 16 -14
 6
30 -22 6 7 -22 30
 7
30 -25 0 6 9 -2 10
 9
7 2 -1 1 1 -10 6 -1 6
 4
1 -10 1 10
 5
17 -16 12 -11 15
 35
-23 -22 23 4 -22 29 -4 -6 -28 18 -5 21 -7 -8 -11 -7 30 -25 -1 12 19 5 -8 12 -1 10 -24 -19 24 -17 -7 24 20 -22 16
 10
4 -3 1 -2 1 1 0 -4 4 -2
 10
4 -2 1 0 1 -5 -2 1 0 -5
 2
3 9
 9
11 -5 -5 1 2 3 -5 -5 11

1
 8
 1
 4
 1
 2
 15
 5
 36
 2
 3
 1
 9
 28
 4
 1
 7
 2
 1
 7
 4
 13
 1
 1
 13
 16
 1
 6
 20
 21
 20
 1
 5
 1
 44
 10
 0
 1
 0
 2
 9
 5
 2
 3
 1
 2
 2
 1
 1
 3
 3
 6
 8
 2
 29
 6
 13
 5
 1
 1
 30
 1
 1
 3
 3

#
#    ------------------------------------------------
#         Fast Tests Competitive Python Template
#    ------------------------------------------------
#    Author: prophet "神"
#    Version: 1V3uJkowFG
#    License: GNU Affero General Public License v3.0
#    Location: 218.92.0.135
#    ------------------------------------------------
#

testing_mode = True

import sys, traceback

test_data = ""
final_output = ""

def input(input_format = 0, multi = 0):

    if multi > 0: return [input(input_format) for x in range(multi)]
    else:
        next_line = next(test_data, None).strip() if test_data else sys.stdin.readline()

        if input_format == 0: formatted_input = [next_line]
        elif input_format == 1: formatted_input = list(map(int, next_line.split()))
        elif input_format == 2: formatted_input = list(map(float, next_line.split()))
        elif input_format == 3: formatted_input = next_line.split()
        elif input_format == 4: formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
        elif input_format == 5: formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
        else: formatted_input = [next_line]

        return formatted_input

def log(*args):
    if testing_mode: print(*args)

def out(output_line, output_format = 0, newline = True):

        global final_output

        formatted_output = ""

        if output_format == 0: formatted_output = str(output_line)
        elif output_format == 1: formatted_output = " ".join(map(str, output_line))
        elif output_format == 1: formatted_output = "\n".join(map(str, output_line))

        if testing_mode: final_output += formatted_output + "\n" * newline
        else: print(formatted_output, end = "\n" if newline else "")

test_inputs = [
# Input 1
"""
5
5 -2 10 -1 4

""",
# Input 2
"""
8
5 2 5 3 -30 -30 6 9

""",
# Input 3
"""
3
-10 6 -15

""",
# Input 4
"""
5
20 -10 1 1
"""
]

test_outputs = [
# Output 1
"""
6

""",
# Output 2
"""
10

""",
# Output 3
"""
0

""",
# Output 4
"""
1
"""
]

#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#

def solve():

    n = input(1)[0]
    k = input(1)

    m = -10 ** 10
    b = -10 ** 10
    c = 0

    for i in k:
        b = max(b, i)
        c += i
        m = max(c - b, m)
        print(i, m, b, c)
        if c < 0:
            print("reset")
            b = 0
            c = 0

    b = -10 ** 10
    c = 0

    for i in k:
        b = max(b, i)
        c += i
        m = max(c - b, m)
        print(i, m, b, c)
        if c - b < 0:
            print("reset")
            b = 0
            c = 0

    out(m)

    return

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#

def run_all(overwrite_testing = False):

    global testing_mode, final_output, test_data

    testing_mode = overwrite_testing and testing_mode

    if testing_mode:

        tests_failed = 0

        for test_number, (test_in, test_out) in enumerate(zip(test_inputs, test_outputs)):

            final_output = ""

            if test_in.lstrip()[:3] == "$$$": continue

            test_data = iter([i for i in test_in.split("\n") if i])

            print(f"Test Case #{test_number + 1}:")
            print("<" * 20)

            fail = False
            verdict = "\033[92m\033[1mPASS\033[0m"

            try:
                solve()
                final = final_output.rstrip("\n")
                raw_out = iter(map(str, final.split("\n"))) if final else iter(())
            except Exception:
                raw_out = ""
                fail = True
                print("\033[95m")
                traceback.print_exc()
                print("\033[0m")

            if raw_out:
                if test_out.lstrip()[:3] == "$$$":
                    verdict = "\033[94m\033[1mSKIP\033[0m"
                    print("\033[94m" + '\n'.join(list(raw_out)) + "\033[0m")
                else:
                    for line_out in [i for i in test_out.split("\n") if i]:
                        line_raw = next(raw_out, "% None %")
                        if line_raw == line_out.strip():
                            print(f"\033[92m{line_raw}\033[0m")
                        else:
                            print(f"\033[91m{line_raw}\033[0m")
                            fail = True

                    line_raw = next(raw_out, None)
                    while line_raw:
                        print(f"\033[91m{line_raw}\033[0m")
                        line_raw = next(raw_out, None)
                        fail = True

            print(">" * 20)

            if fail:
                verdict = "\033[91m\033[1mFAIL\033[0m"
                tests_failed += 1

            print(verdict + "\n")

        if tests_failed: print(f"\033[91m\033[1m{tests_failed} TEST{'S' if tests_failed > 1 else ''} FAILED!\033[0m")
        else: print(f"\033[92m\033[1mALL TESTS PASSED!\033[0m")

    else:

        test_data = False
        solve()

run_all(False)

