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
#include <stdio.h>

#include <algorithm>
#include <vector>

int solution(const std::vector<int>& data, bool up) {
  int results = 0;
  for (int i = 0; i < data.size(); ++i) {
    int invalidItemsCount = 1;
    for (; i < data.size() - 1; ++i) {
      if ((up && data[i] >= data[i + 1]) || (!up && data[i] <= data[i + 1])) {
        invalidItemsCount++;
        up = !up;
      } else {
        break;
      }
    }
    results += invalidItemsCount / 2;
    up = !up;
  }
  return results;
}

int main() {
  int n;
  scanf("%d\n", &n);
  std::vector<int> data(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &data[i]);
  }
  printf("%d\n", std::min(solution(data, true), solution(data, false)));
  return 0;
}