#include <iostream>
using namespace std;

long long n,a[2000000],br;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>> n;
    for(long long i=0;i<n;i++){
        cin>> a[i];
    }
    for(long long i=0;i<n;i++){
        for(long long j=i+1;j<n;j++){
            bool f=true;
            for(long long l=i+1;l<j;l++){
                if(a[l]>a[i] && a[l]>a[j]){
                    f=false;
                    break;
                }
            }
            if(f){
                br++;
                //cout<< i << " " << j << endl;
            }
        }
    }
    cout<< br;






    return 0;
}