The largest sawtooth subsequence#2211

The largest sawtooth subsequence

1 secondo
64 megabyte
Facile

A sequence of numbers is called a sawtooth sequence if every element (except the first and last) is either greater than both its neighbors or less than both its neighbors. For example, the sequence \textbf{1}, \textbf{2}, \textbf{1}, \textbf{3}, \textbf{2} is a sawtooth sequence, while \textbf{1}, \textbf{2}, \textbf{3}, \textbf{1}, \textbf{2} is not, because \textbf{1} < \textbf{2} < \textbf{3}. Any sequence consisting of a single element is considered a sawtooth sequence. A sequence with two elements is a sawtooth sequence if its two elements are not equal.

Input

The first line contains a single integer (1 \leq N \leq 100\,000) — the number of elements in the sequence.

The second line contains natural numbers, each not exceeding — the elements of the sequence.

Output

Output a single integer: the minimum number of elements that need to be removed to obtain a sawtooth subsequence.

Esempi

Esempio 1

Loading
Loading