#include<bits/stdc++.h>
#define MAXN 2000000
using namespace std;
int a[MAXN], n;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        int maxch = -1;
        for(int j = i + 1; j < n; j++){
            if(maxch <= a[j]){
                //cout << i << " " << j << "\n";
                maxch = a[j];
                ans ++;
            }else if(maxch <= a[i]){
                //cout << i << " " << j << "\n";
                ans ++;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

