A. Faking Data
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are a researcher at Chime Labs, a premier private-sector facility operating under the wing of a major telecommunications giant. The fiscal year is ending, the market is down, and your department is facing massive layoffs. To save your career, you have "discovered" a revolutionary copper wire formulation that supposedly eliminates signal noise.

According to your falsified white paper, a series of electrical signals $$$e_1, e_2, \dots, e_n$$$ is considered "perfectly clean" if it follows a strict alternating pattern. Specifically, the signals must satisfy one of the following two conditions:

  • $$$e_1 \lt e_2 \gt e_3 \lt e_4 \gt \dots$$$
  • $$$e_1 \gt e_2 \lt e_3 \gt e_4 \lt \dots$$$

The issue is that your actual prototype produces a standard, noisy signal that doesn't follow these rules. To maintain the facade during the live demonstration for the board of directors, you intend to manually calibrate the equipment. You can perform a single type of operation: select any signal $$$i$$$ and decrease the value of $$$e_i$$$ by 1. You can perform this operation as many times as you like on the same $$$i$$$, and you may perform it on any number of different $$$i$$$.

Because the board is watching closely, you want to minimize the total number of operations performed so the adjustments aren't noticed. Find the minimum number of operations required to transform the initial signal into a "perfectly clean" one.

Input

The first line contains a single integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^5)$$$, representing the number of signals recorded. The second line contains $$$n$$$ space-separated integers $$$e_1, e_2, \dots, e_n$$$ $$$(1 \le e_i \le 10^7)$$$, representing the initial values of the signals.

Output

Print a single integer, the minimum number of operations required to make the signal clean.

Example
Input
5
8 2 10 10 8
Output
3