#include <iostream>
using namespace std;

int main()
{
    int N,counter=0;
    bool high;
    bool low;
    int h[3000];
    cin >> N;
    for(int i=1; i<=N; i++)
    {
        cin >> h[i];
        for(int j=1;j<=N;j++)
    {
        for(int p=2;p<=N;p++)
        {
            if(h[i]>h[i+1]and h[i]>h[i-1])
            {
                high=true;
            }
            if(h[i]<h[i+1]and h[i]<h[i-1])
            {
                low=true;
            }
            if(high==true or low==true)
            {
                counter++;
            }
        }
    }
    }

    cout << counter;
    return 0;
}
