#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n;
    cin>>n;
    vi d(n);
    REP(i,n)cin>>d[i];
    int ans=0;
    REP(i,n-2){
        int a=0,b=0;
        if(d[i]>d[i+1])a++;
        if(d[i]>d[i+2])a++;
        if(d[i+2]>d[i])b++;
        if(d[i+2]>d[i+1])b++;
        if(a==1||b==1){
            ans++;
        }else if(d[i]!=d[i+1]&&d[i]!=d[i+2]&&d[i+1]!=d[i+2]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}