#include<bits/stdc++.h>
using namespace std;
int a[200000];
int mxm(int l, int r){
    int ans = 0;
    for(int i = l ; i <= r ; i++){
        ans = max(ans,a[i]);
    }
    return ans;
}
int main(){
    int n;
    cin>>n;
    for(int i = 0; i < n ; i++){
        cin>>a[i];
    }
    long long br = n-1;
    for(int l = 0; l < n ; l++){
        for(int r = l+2 ; r < n ; r++){
            if(mxm(l,r) == max(a[l],a[r])){
                //cout<<"("<<l<< ","<<r<<")"<<"   mxm  = "<<mxm(l,r)<<endl;
                br++;
            }
        }
    }
    cout<<br;
}
