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

#define f first
#define s second
#define vec vector
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> bool umin(T &a ,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a ,const T &b){return (a<b?a=b,1:0);}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long double ld;
auto rng=bind(uniform_int_distribution<ll>(1,(ll)1e18),mt19937(time(0)));
const int inf = (int)1e9 + 1;

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;

    vec <int> a(n);
    for (auto &z : a)
        cin >> z;
    int mn = inf;
    for (int t = 0; t < 2; ++t) {
         int prv = -inf;
        int ans = 0;
//        cout << t << endl;
        for (int i = 0; i < n; ++i) {
            int x = a[i];
            if (prv == -inf) {
                prv = x;
                continue;
            }
            else {
                if (((i + t) & 1) && !(x > prv)) {
                    prv = -inf;
                    ++ans;
//                    cout << i << endl;
                } else if (!((i + t) & 1) && !(x < prv)) {
                    prv = -inf;
                    ++ans;
//                    cout << i << endl;
                } else prv = x;
            }
//            prv = x;
        }
//        cout << endl;
        umin(mn, ans);
    }
    cout<<mn;
    return 0;
}

/*
1 2
1 7
2 18
7 9
3 18
5 17
3 8
14 18
4 7
7 17
3 20
1 18
4 11
10 11
*/