Sawtooth approximation
A sequence of N integers B[0], B[1], ..., B[N-1] is defined as a sawtooth sequence if it satisfies the following conditions:
For all even indices i from 0 to N-1, B[i] < B[i+1].
For all odd indices i from 0 to N-1, B[i] > B[i+1].
You are provided with a sequence of N integers A[0], A[1], ..., A[N-1]. Your task is to approximate this sequence as closely as possible with a sawtooth sequence B[0], B[1], ..., B[N-1]. The degree of approximation is measured by the sum |B[0] - A[0]| + |B[1] - A[1]| + ... + |B[N-1] - A[N-1]|. The goal is to achieve the smallest possible degree of approximation.
Input
The first line contains the integer N (3 ≤ N ≤ 100), representing the size of the array. The next N lines describe the sequence A[0], A[1], ..., A[N-1] (1 ≤ A[i] ≤ 1000000000), which needs to be approximated by a sawtooth sequence.
Output
Output a single integer, which is the minimal possible degree of approximation of the sequence A[0], A[1], ..., A[N-1] using the sawtooth sequence B[0], B[1], ..., B[N-1].