单调栈
#include <iostream>
#include <cstdio>
using namespace std;
long long n, a1[80010], p1[80010], p, ans;
int main(){
scanf("%lld", &n);
for(int i = 1; i <= n; i ++) scanf("%lld", &a1[i]);
a1[++n] = 1e9+10;
for(int i = 1; i <= n; i ++){
while(p && a1[p1[p]] <= a1[i]) ans += (i-p1[p]-1), p --;
p1[++p] = i;
}
printf("%lld", ans);
return 0;
}