#include <bits/stdc++.h>
//#define DEBUG
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> h;
    int tmp;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        h.push_back(tmp);
    }
    vector<int> maxr, maxl;
    int mx = 0;
    for(int i = 0; i < n; i++){
        maxr.push_back(mx);
        maxl.push_back(-1);
        if(h[i] > mx){mx = h[i];}
    }
    mx = 0;
    for(int i = n-1; i >= 0; i--){
        maxl[i] = mx;
        if(h[i] > mx){mx = h[i];}
    }
#ifdef DEBUG
    for(int i = 0;i < n; i++){
        cout << h[i] << ' ';
    }
    cout << '\n';
    for(int i = 0;i < n; i++){
        cout << maxr[i] << ' ';
    }
    cout << '\n';
    for(int i = 0; i < n; i++){
        cout << maxl[i] << ' ';
    }
    cout << '\n';
#endif // DEBUG
    int sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(h[i] != h[j]){
#ifdef DEBUG
                cout << i << ' ' << j << '\n';
#endif // DEBUG
                sum++;
            }
            if(h[j] > h[i] && maxl[j] < h[j]){break;}
        }
    }
    cout << sum;
    return 0;
}
