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
#define make_pair mp
#define emplace_back pb
#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 5e4+5;
int n;
int tab[N], dp[N];
int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d", &tab[i]);
    for(int i=2;i<=n;i++) {
        if((i % 2 == 0 && tab[i] <= tab[i-1]) || (i % 2 == 1 && tab[i] >= tab[i-1])) dp[i] = 1 + dp[i-2];    
        else dp[i] = dp[i-1];
    }
    int res = dp[n];
    for(int i=2;i<=n;i++) {
        if((i % 2 == 0 && tab[i] >= tab[i-1]) || (i % 2 == 1 && tab[i] <= tab[i-1])) dp[i] = 1 + dp[i-2];    
        else dp[i] = dp[i-1];
    }
    res = min(res, dp[n]);
    printf("%d\n", res);
	return 0;
}