Snuke stands on a number line with length ( L ). He has ( L ) ears, and he will walk along the line under the following conditions:
He never visits a point with coordinates less than 0 or greater than ( L ).
He starts and finishes walking at integer coordinates.
He only changes direction at integer coordinates.
While walking, each time Snuke passes a point with coordinates ( i - 0.5 ) (where ( i ) is an integer), he places a stone in his ( i )-th ear.
After walking, Ringo will perform a series of operations to ensure that each of Snuke's ears contains a specified number of stones ( A[i] ):
Place a stone in one of Snuke's ears.
Remove a stone from one of Snuke's ears.
Your task is to find the minimum number of operations required for Ringo to achieve the desired arrangement of stones in Snuke's ears.
Input Format
The first line contains an integer ( L ) (1 ≤ ( L ) ≤ 1000), representing the number of ears (and also the maximum coordinate on the number line).
The second line contains ( L ) integers ( A[1], A[2], \ldots, A[L] ) (0 ≤ ( A[i] ) ≤ 1000), where ( A[i] ) indicates the desired number of stones in the ( i )-th ear.
Output Format
Print a single integer, the minimum number of operations required.
Example
Input
text
5
1 2 1 0 2
Output
text
4
Explanation
In this example:
Snuke can walk in such a way that he passes the points ( 0.5, 1.5, 2.5, 3.5, 4.5 ).
He finishes with ( [1, 1, 1, 0, 0] ) stones in his ears.
Ringo must perform operations to achieve ( [1, 2, 1, 0, 2] ): he can add 1 stone to ear 2 and 2 stones to ear 5.
Thus, the total minimum operations required are 4 (2 add operations and 2 remove operations).
Constraints
Ensure to consider the maximum limits for ( L ) and the values in ( A ).
Your solution should be efficient to handle the upper limits of the constraints.
Solution Submission
Please implement your solution in the /app/ directory.