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
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int n;
    int a, b;
    int count1 = 0, count2 = 0;
    bool change = false;

    scanf("%d", &n);

    scanf("%d", &a);

    for(int i = 1; i < n; i++) {
        scanf("%d", &b);

        if(change) {
            change = false;
        }
        else if(b > a) {
            if(i % 2 == 0) {
                count1++;
            } else {
                count2++;
            }
        } else if (a > b) {
            if(i % 2 == 0) {
                count2++;
            } else {
                count1++;
            }
        } else {
            count1++;
            count2++;
            change=true;
        }

        a = b;
    }

    printf("%d\n", min(count1, count2));

    return 0;
}