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
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, la=0, lb=0, a, b, p;
	cin >> n;
	int last;
	cin >> last;
	for(int i=1; i<n; i++)
	{
		int D;
		cin >> D;
		if(D>last)
		{p=i%2;}
		else if(D<last)
		{p=(i+1)%2;}
		else
		{p=2;}
		if(p==0)
		{la=la+1;
		b=b+((lb-(lb%2))/2)+(lb%2);
		lb=0;}
		else if(p==1)
		{lb=lb+1;
		a=a+((la-(la%2))/2)+(la%2);
		la=0;}
		else
		{la=la+1;
		lb=lb+1;}
		last=D;
	}
	a=a+((la-(la%2))/2)+(la%2);
	b=b+((lb-(lb%2))/2)+(lb%2);
	if(a<b)
	{cout << a;}
	else
	{cout << b;}
}