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
#include<bits/stdc++.h>
using namespace std;
int tab[1000005];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a;
	cin>>a;
    for(int x=1;x<=a;x++)
        cin>>tab[x];
    int res1 = 0, res2 = 0;
    for(int x=2;x<=a;x++)
    {
        if(x % 2 == 0 && tab[x] >= tab[x-1])
        {
            res1++;
            x++;
        }
        else if(x % 2 == 1 && tab[x] <= tab[x-1])
        {
            res1++;
            x++;
        }
    }
    for(int x=2;x<=a;x++)
    {
        if(x % 2 == 1 && tab[x] >= tab[x-1])
        {
            res2++;
            x++;
        }
        else if(x % 2 == 0 && tab[x] <= tab[x-1])
        {
            res2++;
            x++;
        }
    }
    //cout<<res1<<" "<<res2<<'\n';
    cout<<min(res1, res2);
	return 0;
}