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

   for(unsigned long long i=0; i<c; 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++;
        }
   }

    h=h+d-y;
     cout<<h*2<<endl;
    return 0;
}
