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 <iostream>
#include <vector>
using namespace std;

int sol(const vector<int>&A, bool dir) {
    int n = A.size();
    int result = 0;

    for (int i = 1; i < n; i++) {
        bool problem = (A[i - 1] == A[i]) || (bool((int(dir) + i) % 2) == (A[i - 1] < A[i]));
        if (problem) {
            result++;
            i++;
        }
    }

    return result;
}

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

    int n;
    cin >> n;
    vector<int>A(n);
    for (int &x : A)
        cin >> x;

    cout << min(sol(A, false), sol(A, true)) << "\n";

    return 0;
}