#include <iostream>
using namespace std;

int main (){
    int n,br=0;
    cin>>n;
    int tochki[n];
    for(int i=0;i<n;i++){
        cin>>tochki[i];
    }
    for(int i=2;i<n-2;i++){
        if(tochki[i]<tochki[i+1]){
            br++;
        }
        if(tochki[i-1]<tochki[i]){
            br++;
        }
        if(tochki[i]>tochki[i+1]){
            br++;
        }
        if(tochki[i-1]>tochki[i]){
            br++;
        }
        if(tochki[i]<tochki[i+2]){
            br++;
        }
        if(tochki[i-2]<tochki[i]){
            br++;
        }
        if(tochki[i]>tochki[i+2]){
            br++;
        }
        if(tochki[i-2]>tochki[i]){
            br++;
        }if(tochki[i]<tochki[i+3]){
            br++;
        }
        if(tochki[i-3]<tochki[i]){
            br++;
        }
        if(tochki[i]>tochki[i+3]){
            br++;
        }
        if(tochki[i-3]>tochki[i]){
            br++;
        }
    }
    cout<<br+2;
    return 0;
}
