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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

 
int main(){ 
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    // freopen("input.in", "r", stdin);
    ll wyn1=0;
    ll wyn2=0;
    ll n;
    cin>>n; 
    ll x,y;
    cin>>y;
    ll p1=0;
    ll p2=0;
    vector <ll> t;
    t.push_back(y);
 
    for (ll i=1; i<n; i++){
        cin>>x;
        t.push_back(x);
        if (i%2==1){
            if (x>=y){
                wyn1++;
                p1=1;
            }

        }
        else{
            if(x<=y){
                wyn1++;
                p2=1;
            }
        }
        if (p1) y=-INT_MAX;
        if (p2) y=INT_MAX;
        if (!p1 and !p2) y=x;
        p1=0;
        p2=0;
        // p1=0;

    }
   
    y=t[0];
    for (ll i=1; i<=n-1; i++){
        x=t[i];
        if (i%2==1){
            if (x<=y){
                wyn2++;
                p1=1;
            }

        }
        else{
            if(x>=y){
                wyn2++;
                p2=1;
            }
        }
        if (p2) y=-INT_MAX;
        if (p1) y=INT_MAX;
        if (!p1 and !p2) y=x;
        p1=0;
        p2=0;
        // p1=0;

    }

   

//    cout<<wyn1<<" "<<wyn2<<" "<<wyn3<<"\n";
    cout<<min(wyn1,wyn2);
    return 0;
}