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
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
int tab[50001];
int tab2[50001];
int tab3[50001];
int main(){
    int n;
    scanf("%d", &n);
    int suma1=0;
    int suma2=0;
    int wyn;
    for(int i=0;i<n;i++){
        scanf("%d", &tab[i]);
        tab2[i]=tab[i];
        tab3[i]=tab[i];
    }
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(tab2[i+1]<=tab2[i]){
                tab2[i+1]=1000001;
                suma1++;
                //cerr << i << '\n';
                //cerr << "tab 2 " << tab2[i] << " +1 " << tab2[i+1] << '\n';
            }
        }else{
            if(tab2[i+1]>=tab2[i]){
                tab2[i+1]=-1000001;
                suma1++;
                //cerr << i << '\n';
                //cerr << "tab 2 " << tab2[i] << " +1 " << tab2[i+1] << '\n';
            }
        }
    }
    for(int i=0;i<n;i++){
        if(i%2==1){
            if(tab3[i+1]<=tab3[i]){
                tab3[i+1]=1000001;
                suma2++;
                //cerr << i << '\n';
                //cerr << "tab 3 " << tab3[i] << " +1 " << tab3[i+1] << '\n';
            }
        }else{
            if(tab3[i+1]>=tab3[i]){
                tab3[i+1]=-1000001;
                suma2++;
                //cerr << i << '\n';
                //cerr << "tab 3 " << tab3[i] << " +1 " << tab3[i+1] << '\n';
            }
        }
    }
    wyn=min(suma1,suma2);
    printf("%d",wyn);
}