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

int tab[50001];

int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> tab[i];
    }

    int count = 0;
    for (int i = 1;i < n - (!(n % 2)); i += 2) {
        if (!((tab[i] > tab[i - 1] && tab[i] > tab[i + 1]) || (tab[i] < tab[i - 1] && tab[i] < tab[i + 1]))) {
            count++;
        }
    }
    if (n % 2 == 0) {
        if (tab[n - 1] == tab[n - 2]) {
            count++;
        }
    }
    std::cout << count;
    return 0;
}