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

const int joker = 1e9+100;
int t[1000111], t2[1000111];
int main() {
  int n;
  scanf("%d", &n);

  int result = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t[i]);
    t2[i] = t[i];
  }

  int res1 = 0, res2 = 0; // res1 = 1szy rosnie
  for (int i = 2; i <= n; i++) {
    if (i%2 == 1) {
      if (t[i] < t[i-1]) {}
      else {
        t[i] = -joker;
        res1 ++;
      }
    }
    else {
      if (t[i] > t[i-1]) {}
      else {
        t[i] = joker;
        res1 ++;
      }
    }
  }

  for (int i = 2; i <= n; i++) {
    if (i%2 == 1) {
      if (t2[i] > t2[i-1]) {}
      else {
        t2[i] = joker;
        res2 ++;
      }
    }
    else {
      if (t2[i] < t2[i-1]) {}
      else {
        t2[i] = -joker;
        res2 ++;
      }
    }
  }

  printf("%d\n", std::min(res1, res2));

  return 0;
}