#include<iostream>
using namespace std;
int main()
{
    int n, middle = 0, result;
    cin>>n;
    int h[n];
    for(int i = 0; i < n; i++)
    {
        cin>>h[i];
    }
    for(int i = 1; i < n-1; i++)
    {
        if((h[i-1] < h[i] && h[i+1] > h[i]) || (h[i-1] > h[i] && h[i+1] < h[i]))
        {
            middle++;
        }
    }
    result = (n-1+middle)*2;
    cout<<result;
    return 0;
}
