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
//Patryk Górski LO XIV Wrocław
#include<iostream>
using namespace std;
int tab[50007];
int main(){
    int n,wyn1 = 0,wyn2 = 0,wyn4 = 0,wyn3 = 0;
    cin>>n;
    //tab[0][0] = -1e9;
    //tab[1][0] = 1e9;
    for(int i=1;i<=n;i++)cin>>tab[i];
    for(int i=1;i<=n;i++){
//        cin>>tab[i];
        //tab[1][i] = tab[0][i];
        if(i%2==1){
            if((i!=1 && tab[i-1]>=tab[i]) || (i!=n && tab[i+1]>=tab[i]))wyn1++;
            if((i!=1 && tab[i-1]<=tab[i]) || (i!=n && tab[i+1]<=tab[i]))wyn2++;
        }
        else{
            if((i!=1 && tab[i-1]>=tab[i]) || (i!=n && tab[i+1]>=tab[i]))wyn3++;
            if((i!=1 && tab[i-1]<=tab[i]) || (i!=n && tab[i+1]<=tab[i]))wyn4++;
        }
//        cout<<wyn1<<" "<<wyn2<<" "<<tab[i]<<" "<<tab[i-1]<<" "<<tab[i+1]<<"\n";
    }
    cout<<min(min(wyn1,wyn2),min(wyn3,wyn4))<<"\n";
    return 0;
}