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
//
//  main.cpp
//  Ornitolog 2
//
//  Created by Mikołaj Małysz on 12/12/2022.
//

#include <iostream>
#include <vector>
#include <limits>

using namespace std;

int imin = std::numeric_limits<int>::min(); // minimum value
int imax = std::numeric_limits<int>::max();

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, temp = 0;
    cin >> n;
    vector<int> v = {};
    for (int i = 0; i<n; i++) {
        cin >> temp;
        v.push_back(temp);
    }
    bool rise = !(v[0]>v[1]);
    int count = 0;
    if (v[0] == v[1]) {
        if (v[2] > v[1]) {
            v[1] = imin;
        } else {
            v[1] = imax;
        }
        count++;
    }
    for (int i = 0; i<n-1; i++) {
        if (rise) {
            if (!(v[i] < v[i+1])) {
                v[i+1] = imax;
                count++;
                rise = true;
            }
        } else {
            if (!(v[i] > v[i+1])) {
                v[i+1] = imin;
                count++;
                rise = false;
            }
        }
        rise = !rise;
    }
    cout << count << '\n';
    return 0;
}