#include<iostream>
using namespace std;
int main(){
    int c;
    cin>>c;
    int h=c-1;
    int y=0;
   int a[c]={};
   for(int i=0; i<c; i++){cin>>a[i];}

   for(int i=0; i<c-1; i++){
        if((a[i+1]<a[i] && a[i+1]<a[i+2]) || (a[i+1]>a[i] && a[i+1]>a[i+2])){
            y++;
        }
   }


     cout<<(h+(c-2-y))*2<<endl;
    return 0;
}
