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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Example program
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

void testcase(int t) {
    int n;
    cin >> n;
    vector <int> S(n);
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    
    // increasing-decreasing
    int ans_incr_decr = 0, prev = S[0], next;
    for (int i = 1; i < n; i++) {
        next = S[i];
        if (i % 2 == 1) {   // incr
            if (!(prev < next)) {
                next = 2000000 + i;
                ans_incr_decr++;
            }
        }
        else {              // decr
            if (!(prev > next)) {
                next = -2000000 - i;
                ans_incr_decr++;
            }
        }
        prev = next;
    }
    
    // decreasing-increasing
    int ans_decr_incr = 0;
    prev = S[0];
    for (int i = 1; i < n; i++) {
        next = S[i];
        if (i % 2 == 0) {   // incr
            if (!(prev < next)) {
                next = 2000000 + i;
                ans_decr_incr++;
            }
        }
        else {              // decr
            if (!(prev > next)) {
                next = -2000000 - i;
                ans_decr_incr++;
            }
        }
        prev = next;
    }
    
    cout << min(ans_incr_decr, ans_decr_incr) <<endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; t++) {
    testcase(t);
  }
  return 0;
}