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
//Szymon Januszek, 3LO Gdynia
#include <bits/stdc++.h>

using namespace std;

const int N = 50010;

int tab[N];
int t[N];

int calc(int n, int off) {
    int r = 0;
    for(int i = 2; i <= n; i++) {
        int m = (i + off) & 1;
        if(m && t[i - 1] >= t[i]) {
            r++;
            t[i] = 1e9;
        } else if(!m && t[i - 1] <= t[i]) {
            r++;
            t[i] = -1e9;
        }
    }

    return r;
}
int main() {
    int n;
    cin >> n;

    for(int i = 1; i <= n; i++) scanf("%d", tab+ i);


    memcpy(t, tab, sizeof(int)*(n + 1));
    int w = calc(n, 0);
	memcpy(t, tab, sizeof(int)*(n + 1));
    w = min(w,calc(n, 1));
	memcpy(t, tab, sizeof(int)*(n + 1));
    t[1] = 1e9;
	memcpy(t, tab, sizeof(int)*(n + 1));
    t[1] = -1e9;
	memcpy(t, tab, sizeof(int)*(n + 1));

    cout << w << endl;


    return 0;
}