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

int sm[2000005], bg[2000005], idx[2000005], ans, r[2000005], n;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; i++) cin >> r[i];

    for(int i = n-1; i >= 0; i--){
        for(int j = i+1; j < n; j++){
            if(r[j] <= r[i]) sm[i]++;
            else{
                idx[i] = j;
                bg[i] = bg[j]+1;
                break;
            }
        }
        //cout << r[i] << " " << sm[i] << " " << idx[i] << " " << bg[i] << "\n";
        ans += sm[i]+bg[i];
    }

    cout << ans;

    return 0;
}
