#include<bits/stdc++.h>
using namespace std ;
stack <int> s ;
int n;
int a[80005] ;
long long ans=0 ;
int main()
{
cin>>n;
for(int i=1 ;i<=n ;++i) scanf("%d",&a[i]) ;
s.push(1);
for(int i=2 ;i<=n ;++i)
{
while(!s.empty() && a[s.top()] <= a[i])
{
ans += i-1-s.top() ;
s.pop() ;
}
s.push(i) ;
}
int i=0;
while(!s.empty())
{
ans+=i;
++i;
s.pop() ;
}
cout<< ans;
}
使用了蒟蒻的方法统计每头牛能看多少头牛,但是偏偏不过