#include<bits/stdc++.h>
using namespace std;
int a[200000];
int ind[200000];
int maximal(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;
  cin>>a[0];
  ind[0] = 0;
  for(int i = 1; i < n ; i++){
    cin>>a[i];
    if(a[i]> a[ind[i-1]]){
        ind[i] = i;
    }else{
        ind[i] = ind[i-1];
    }
  }
  int br = 0;
  for(int l = 0; l < n - 1 ; l++){
    for(int r = l+1; r < n ; r++){
        //cout<<"I'm here with : ("<<l<<","<<r<<")"<<"   / index = "<<index[r]<<endl;
        if(ind[r]== l || ind[r]==r){
            br++;
            //cout<<"("<<l<<","<<r<<")";//cout<< " /because L or R is maximal of all"<<endl<<endl;
            //cout<<"         BR = " << br<<endl;
            continue;
        }
        if(ind[r] > l && ind[r] < r){
            //cout<<"("<<l<<","<<r<<")";//cout<<" / invalid, because index[r] = "<<index[r]<<endl<<endl;
            //cout<<"         BR = " << br<<endl;
            continue;

        }
        //cout<< " /maximal("<<a[l]<<" "<<a[r]<< ") =" <<maximal(l,r)<<endl;
        if(maximal(l,r) == max(a[l],a[r])){
            //cout<<"("<<l<<","<<r<<")";
            br++;
            //cout<<"         BR = " << br<<endl;
            continue;
        }
        //cout<<"NOTHING? ("<<l<<","<<r<<")"<<"         BR = " << br<<endl;
    }
  }
  cout<<br;
}
