#abc182d. [abc182_d]Wandering
[abc182_d]Wandering
Problem Statement
Given is a number sequence , which may contain negative elements.
On a number line, there is a robot at coordinate . It will do the following actions in order:
- Move in the positive direction.
- Move in the positive direction, and then move in the positive direction.
- Move in the positive direction, then move in the positive direction, and then move in the positive direction.
- Move in the positive direction, then move in the positive direction, then move in the positive direction, , , and then move in the positive direction.
Find the greatest coordinate occupied by the robot from the beginning to the end of the process.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$A_1 \\hspace{7pt} A_2 \\hspace{7pt} A_3 \\hspace{5pt} \\dots \\hspace{5pt} A_N$
Output
Print the greatest coordinate occupied by the robot from the beginning to the end of the process.
Sample Input 1
3
2 -1 -2
Sample Output 1
5
The robot moves as follows:
- Move in the positive direction, to coordinate .
- Move in the positive direction, to coordinate . Then move in the positive direction, to coordinate .
- Move in the positive direction, to coordinate . Then move in the positive direction, to coordinate . Then move in the positive direction, to coordinate .
The greatest coordinate occupied during the process is , so we should print .
Sample Input 2
5
-2 1 3 -1 -1
Sample Output 2
2
Sample Input 3
5
-1000 -1000 -1000 -1000 -1000
Sample Output 3
0
In this case, the initial coordinate is the greatest coordinate occupied.