Snuke is standing on a number line and will walk under specific conditions. He has L ears and is allowed to walk continuously, but he must adhere to the following rules:
Snuke never visits a point with a coordinate less than 0 or greater than L.
He starts and finishes walking at integer coordinates.
He changes direction only at integer coordinates.
Every time Snuke passes a point with a coordinate of i - 0.5, where i is an integer, he places a stone in his i-th ear.
After Snuke completes his walk, Ringo performs a series of operations in any order until each ear i contains A[i] stones:
Add a stone to one of Snuke's ears.
Remove a stone from one of Snuke's ears.
Your task is to determine the minimum number of operations required for Ringo to achieve the desired distribution of stones in Snuke's ears, given that Ringo can choose how Snuke walks.
Input Format
The first line contains two integers, L (the number of ears) and N (the total number of stones Snuke has placed).
The second line contains N space-separated integers representing the counts of stones initially placed in each of Snuke's ears.
Output Format
Output a single integer indicating the minimum number of operations required to match the desired stone distribution.
Examples
Example 1
Input:
text
3 4
2 0 1
Output:
text
3
Explanation: Ringo needs to remove 2 stones from the first ear and add 1 stone to the third ear to achieve the desired distribution.
Example 2
Input:
text
5 5
0 0 0 5 0
Output:
text
5
Explanation: Ringo can directly add 5 stones to the fourth ear since all other ears need stones.
Constraints
1 ≤ L ≤ 1000
0 ≤ N ≤ 1000
0 ≤ A[i] ≤ 1000 for all valid i.
Solution
The solution should be implemented in the /app/ directory.