#P1006C. Three Parts of the Array
Three Parts of the Array
No submission language available for this problem.
Description
You are given an array consisting of integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be , the sum of elements of the second part be and the sum of elements of the third part be . Among all possible ways to split the array you have to choose a way such that and is maximum possible.
More formally, if the first part of the array contains elements, the second part of the array contains elements and the third part contains elements, then:
The sum of an empty array is .
Your task is to find a way to split the array such that and is maximum possible.
The first line of the input contains one integer () — the number of elements in the array .
The second line of the input contains integers () — the elements of the array .
Print a single integer — the maximum possible value of , considering that the condition must be met.
Obviously, at least one valid way to split the array exists (use and ).
Input
The first line of the input contains one integer () — the number of elements in the array .
The second line of the input contains integers () — the elements of the array .
Output
Print a single integer — the maximum possible value of , considering that the condition must be met.
Obviously, at least one valid way to split the array exists (use and ).
Samples
Note
In the first example there is only one possible splitting which maximizes : .
In the second example the only way to have is: .
In the third example there is only one way to split the array: .