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
#include<bits/stdc++.h>
 
#define pb push_back
#define f first
#define s second
#define turbo ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vll vector<pll>
#define vii vector<pii>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vb>
#define mid (l+r)/2
#define endl '\n'
#define inf 1000000000
 
using namespace std;

int main() {
    turbo
    int n; cin >> n;
    int r1 = 0, r2 = 0;
    int l1, l2;
    cin >> l1;
    l2 = l1;
    for(int i = 1; i < n; i++) {
        int x; cin >> x;
        int cr1 = r1, cr2 = r2, cl1 = l1, cl2 = l2;
        if(cl2 < x) {
            r1 = cr2;
            l1 = x;
        }
        else {
            r1 = cr2+1;
            l1 = inf;
        }

        if(cl1 > x) {
            r2 = cr1;
            l2 = x;
        }
        else {
            r2 = cr1+1;
            l2 = -inf;
        }
    }
    cout << min(r1, r2);
}