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
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include<vector>
int t[50001];
int main()
{
    int n;
    scanf("%d",&n);
    std::vector<int> v(n);
    for(int i=0;i<n;i++)
    {
	scanf("%d",&v[i]);
    }


    auto v2 =v;
    int res5=0;


    for(int i=0;i<v.size()-1;i++)
    {

	if(i%2==0  && v[i] <= v[i+1])
	{
	    res5++;
	    if(i==v.size()-2)
		break;
	    v[i+1] = std::min(v[i+2], v[i]) -1;
	}
	if(i%2 == 1 && v[i] >= v[i+1])
	{
	    res5++;
	    if(i==v.size()-2)
		break;

	    v[i+1] = std::max(v[i], v[i+2]) + 1;
	}
    }

    int res6= 0;

    v=v2;
     for(int i=0;i<v.size()-1;i++)
    {

        if(i%2  ==0 && v[i] >= v[i+1])
        {
            res6++;
	    if(i==v.size()-2)
		break;

            v[i+1] =  std::max(v[i], v[i+2]) +1;
        }
        if(i%2 == 1 && v[i] <= v[i+1])
        {
            res6++;
	    if(i==v.size()-2)
		break;

            v[i+1] = std::min(v[i+2],v[i]) - 1;
        }
    }

    printf("%d\n", std::min(res5,res6));









    


}