#include<iostream>
using namespace std;
int main(){
    long long c;
    cin>>c;
    long long h=c-1;
    long long y=0;
    long long d=c-2;
   long long 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++;
        }
   }

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