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

int n, w1, w2;//3<=n<=5e4

void deb() {
    cout<<"\n---------deb--------\n";
    cout<<"W1; W2: "<<w1<<" "<<w2<<"\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    int a, b, d1=0, d2=0;
    cin>>a;
    for(int i=1; i<n; i++) {
        cin>>b;
        if(b>=a&&(i%2)||b<=a&&!(i%2)) {
            d1++;
        }
        else {
            w1+=(d1+1)/2;
            d1=0;
        }
        if(b<=a&&(i%2)||b>=a&&!(i%2)) {
            d2++;
        }
        else {
            w2+=(d2+1)/2;
            d2=0;
        }
        swap(a, b);
    }
    w1+=(d1+1)/2;
    w2+=(d2+1)/2;
    cout<<min(w1, w2);
    //deb();
}