Sequence Conversion 2

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

You are given an array of non-negative integers a_1,a_2,,a_Na\_1, a\_2, \dots, a\_N.

You can perform the following operation several times:

  • Choose an index ii. (1i<1 \leq i < length of the array) Then, remove a_i,a_i+1a\_i, a\_{i+1} and replace them with a_ia_i+1a\_i \oplus a\_{i+1}. (The total length of the array decreases by 1)

Expression xyx \oplus y means bitwise xor of two numbers xx and yy. In binary representation, if the ii-th digit of x and y is equal, then the ii-th digit of xyx \oplus y is 00, and if not, it is 11.

The given operation exists in all modern programming languages. For example, in C++ and Java, it is represented as x  yx\ ^{\wedge}\ y.

You want to convert the given array into a zig-zag array.

We say an array of mm integers, z_1,z_2,...,z_mz\_1, z\_2, ..., z\_{m}, is a zig-zag array if no three consecutive elements in the array are either monotonically increasing or monotonically decreasing.

In other words, if there are three elements z_i,z_i+1,z_i+2z\_i, z\_{i+1}, z\_{i+2} in the array such that z_iz_i+1z_i+2z\_i \leq z\_{i+1} \leq z\_{i+2} or z_iz_i+1z_i+2z\_i \geq z\_{i+1} \geq z\_{i+2}, the array is not zig-zag. Otherwise, it is zig-zag array.

Find the minimum number of operations needed to convert a_i\\{a\_i\\} into a zig-zag array.

입력

The first line contains an integer NN, where NN denotes the length of the sequence.

The second line contains NN space-separated non-negative integers a_1,a_2,,a_Na\_1, a\_2, \dots, a\_N.

출력

Print the minimum number of operations needed to change the sequence a_i\\{a\_i\\} into a zig-zag array.

제한

  • 1N3,0001 \leq N \leq 3\\,000
  • 0a_i<2300 \leq a\_i < 2^{30} (1iN)(1 \le i \le N)