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

long long sm[2000005], bg[2000005], ans, r[2000005], n;

int main(){

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

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

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

    cout << ans;

    return 0;
}
