Sequence Conversion 2
시간 제한2초메모리 제한1024 MB
인접한 두 원소를 xor로 합쳐 지그재그 배열로 만들 때 필요한 최소 연산 횟수를 구한다.
문제
You are given an array of non-negative integers .
You can perform the following operation several times:
- Choose an index . ( length of the array) Then, remove and replace them with . (The total length of the array decreases by 1)
Expression means bitwise xor of two numbers and . In binary representation, if the -th digit of x and y is equal, then the -th digit of is , and if not, it is .
The given operation exists in all modern programming languages. For example, in C++ and Java, it is represented as .
You want to convert the given array into a zig-zag array.
We say an array of integers, , 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 in the array such that or , the array is not zig-zag. Otherwise, it is zig-zag array.
Find the minimum number of operations needed to convert into a zig-zag array.
입력
The first line contains an integer , where denotes the length of the sequence.
The second line contains space-separated non-negative integers .
출력
Print the minimum number of operations needed to change the sequence into a zig-zag array.