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
#include <bits/stdc++.h>
using namespace std;

int n, a, down, up, night;
bool downskip, upskip;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> a;
    for (int i=0; i<n-1; i++){
        int tmp = a;
        cin >> a;
        
        if (a>tmp) {night=1;}
        else if (a<tmp) {night=0;}
        else {night=-1;}
        if (night != (i+1)%2 && downskip == false){
            down++;
            downskip = true;
        }
        else downskip = false;
        if (night != i%2 && upskip == false){
            up++;
            upskip = true;
        }
        else upskip = false;
    }

    cout << min(down, up);
    return 0;
}