#include <iostream>
using namespace std;
int main ()
{
    int n;
    int prev;
    int curr;
    int po_prev;
    int cnt = 0;
    cin >> n;
     if (n >= 3)
    {
      for (int j = 1; j <= 3; j++)
      {
          prev = curr;
          cin >> curr;
if (prev >= curr and prev <= po_prev) cnt++;
        if (prev <= curr and prev >= po_prev) cnt++;
      }
    }

    for (int i = 4; i <= n; i++)
    {
        po_prev = prev;
        prev = curr;
        cin >> curr;
        if (prev >= curr and prev <= po_prev) cnt++;
        if (prev <= curr and prev >= po_prev) cnt++;

    }
    cout << cnt + (n - 1) * 2;
    return 0;
}

