#include <bits/stdc++.h>

#define MAXN 2000005

using namespace std;

int n;
int a[MAXN];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int curr_max = a[i];

        for (int j = i + 1; j <= n; j++) {
            if (curr_max <= a[i] || curr_max <= a[j]) ans++;
            curr_max = max(curr_max, a[j]);
        }
    }

    cout << ans << endl;

    return 0;
}
