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
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main()
{
    std::ios_base::sync_with_stdio(false);
    int k;
    std::cin>>k;
    std::vector<int> tones;
    int x1 =0, x2 =0;
    for(int i =0; i <k; ++i)
    {
        int tone;
        std::cin>> tone;
        tones.push_back(tone);
    }

    std::vector<int> tones2 =tones;
    //first high
    for(int i =0; i <k-1; i+=2)
    {
        if(tones[i] <= tones[i+1]) {++x1; tones[i+1] = -1000001;}
        if( i+2 <k and tones[i+1] >= tones[i+2]) {++x1; tones[i+2] = 1000001;}
    }
    
    //first low
    for(int i =0; i <k-1; i+=2)
    {
        if(tones2[i] >= tones2[i+1]) {++x2; tones2[i+1] = 1000001;}
        if( i+2 <k and tones2[i+1] <= tones2[i+2]) {++x2; tones2[i+2] = -1000001;}
    }

    int result = x1< x2? x1 :x2;
    std::cout<<result<<std::endl;
    return 0;
}