#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;
        }
    }
    cout<<br;
    return 0;
}
