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
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  array<int, 2> count;
  array<int, 2> last;
  count[0] = count[1] = 0;
  char state = 0;
  int len;
  int curr;
  cin >> len;
  cin >> curr;
  last[0] = last[1] = curr;
  for (int i = 1; i < len; i++) {
    cin >> curr;
    //  cerr << curr << '\n';
    if (last[state] >= curr) {
      count[state]++;
      last[state] = 10000000;
    } else {
      last[state] = curr;
    }
    //  cerr << (int)state << ' ' << count[state] << ' ' << last[state] << '\n';
    state ^= 1;
    if (last[state] <= curr) {
      count[state]++;
      last[state] = -10000000;
    } else {
      last[state] = curr;
    }
    //  cerr << (int)state << ' ' << count[state] << ' ' << last[state] << '\n';
  }
  cout << min(count[0], count[1]) << '\n';
}