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
#include <iostream>
#include <stdio.h>

using namespace std;

int n,x;

int main()
{
    scanf("%d",&n);
    int r0=0,r1=0;
    int p0=1000000000;
    int p1=-1000000000;

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

        if(p0<=x) {
            r0++;
            p0=-1000000000;
        }
        else p0=x;
        if(p1>=x) {
            r1++;
            p1=1000000000;
        }
        else p1=x;

        swap(p0,p1);
        swap(r0,r1);
    }

    printf("%d\n",min(r0,r1));

    return 0;
}