#include<bits/stdc++.h>
using namespace std;

int a[2000001];

int main() {
    int n;
    cin>>n;
    for(int i = 0; i < n; i++) {
        cin>>a[i];
    }

    long long ans = 0;
    for(int i = 0; i < n-1; i++) {
        int biggest = -1;
        for(int j = i + 1; j < n; j++) {
            biggest = max(biggest, a[j]);
            if(a[i] >= biggest || a[j] >= biggest) {
                ans++;
            }
        }
    }

    cout<<ans<<endl;


    return 0;
}
