n = int(input()) num_list = list(map(int, input().split())) dp_table = [0] * (n+1) dp_table[0] = num_list[0] for i in range(1, n+1): dp_table[i] = max(dp_table[i-1] + num_list[i], num_list[i]) print(max(dp_table))