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
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;
vector<int> v;

const int INF = (int)1e9;

int check(int alt, vector<int> cp) {
    int ans = 0;
    for (int i = 1; i < N; i++) {
        if (alt > 0) {
            if (cp[i - 1] >= cp[i]) {
                ans++;
                cp[i] = INF;
            }
        } else {
            if (cp[i - 1] <= cp[i]) {
                ans++;
                cp[i] = -INF;
            }
        }
        alt *= -1;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> N;
    for (int i = 0; i < N; i++) {
        int k;
        cin >> k;
        v.push_back(k);
    }

    int ans = min(check(1, v), check(-1, v));
    cout << ans << "\n";
    return 0;
}