#include <iostream>
using namespace std;
int main ()
{
long long N, i, br=0, j, t;
cin>>N;
long long wisochina[N];
bool masiw[N];
for (i=0;i<N;i++) {
    cin>>wisochina[i];
}
for (i=1;i<N-1;i++) {
    if (wisochina[N-1]<wisochina[N] && wisochina[N+1]<wisochina[N] || wisochina[N-1]>wisochina[N] && wisochina[N+1]>wisochina[N]) {
        masiw[N]=false;
    }
    else {
        masiw[N]=true;
    }
}
for (i=0;i<N;i++) {
    for (j=1;j<=N;j++) {
        for (t=i+1;t<j;t++) {
            if (masiw[t]==false) {
                t=j;
                br--;
            }
        }
    br++;
    }
}
cout<<br*2;
return 0;
}
