1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;

constexpr int N = 50009;

int n, a, b;
int p[N];
int res, res1, curr;

int main() {
	scanf("%d", &n);
	scanf("%d", p);
	for (int i = 1; i < n; ++i) {
		scanf("%d", p + i);
		p[i - 1] -= p[i];
	}
	--n;
	
	res = 0, res = 0, curr = 1;
	for (int i = 0; i < n; ++i) {
		if (p[i] == 0 || ((p[i] > 0) == (i & 1))) {
			++curr;
		}
		else {
			res += (curr >> 1);
			curr = 1;
		}
	}
	res += (curr >> 1);
	res1 = res;
	
	res = 0, res = 0, curr = 1;
	for (int i = 0; i < n; ++i) {
		if (p[i] == 0 || ((p[i] < 0) == (i & 1))) {
			++curr;
		}
		else {
			res += (curr >> 1);
			curr = 1;
		}
	}
	res += (curr >> 1);
	res = min(res, res1);
	
	printf("%d\n", res);
	
	return 0;
}