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

using namespace std;

using ll = long long;

int n;
vector<int> a;

int check(bool small) {
  int ret = 0;
  for (int i = 0; i < n - 1; i++) {
    if (i % 2 == small) {
      if (a[i] >= a[i + 1]) {
        ret++;
        i++;
        continue;
      }
    } else {
      if (a[i] <= a[i + 1]) {
        ret++;
        i++;
        continue;
      }
    }
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  cout << min(check(true), check(false)) << "\n";
}