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
#include <stdlib.h>
#include <stdio.h>
#include <vector>

using namespace std;

int n, res = 10000000;
vector<int> dz;

int main(){
    scanf("%d",&n);
    dz.assign(n,0);
    for(int i = 0; i<n; i++){
        scanf("%d",&dz[i]);
    }
    int wyn = 0;
    for(int i = 1; i<n; i++){
        //printf("%d | %d | %d %d\n",i,wyn,dz[i-1],dz[i]);
        if((i%2 && dz[i] <= dz[i-1]) || (!(i%2) && dz[i] >= dz[i-1])){
            wyn++;
            i++;
        }
    }    
    res = min(res,wyn);
    wyn = 0;
    for(int i = 1; i<n; i++){
        //printf("%d | %d | %d %d\n",i,wyn,dz[i-1],dz[i]);
        if((i%2 && dz[i] >= dz[i-1]) || (!(i%2) && dz[i] <= dz[i-1])){
            wyn++;
            i++;
        }
    }
    res = min(res,wyn);
    printf("%d\n",res);
    return 0;
}