#include <iostream>
using namespace std;

int main(){
    int n,br=0;
    cin>>n;
    int tochki[n-1];
    for(int i=0;i<n;i++){
        cin>>tochki[i];
    }
    br=(n-1)*2;
    for(int i=0;i<n;i++){
        if(tochki[i]<tochki[i+1]&& tochki[i+1]<tochki[i+2] && i<n-2){
            br=br+2;
        }if(tochki[i]>tochki[i+1]&& tochki[i+1]>tochki[i+2] && i<n-2){
            br=br+2;
        }
    }
    /*
    for(int i=n/2-1;i<=n;i++){
            for(int j=1;j<n/2;j++){
                if(tochki[i]<tochki[i+j]){
                    br++;
                }
                if(tochki[i-j]<tochki[i]){
                    br++;
                }
                if(tochki[i]>tochki[i+j]){
                    br++;
                }
                if(tochki[i-j]>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;
    return 0;
}