#include <cstdio>
#include <algorithm>
#include <stack>

using namespace std;
int cow[80005]={};

int main()
{
    stack<int> stk;
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&cow[i]);
    }
    
    long long vhc=0;
    for(int i=0; i<n; i++)
    {
        int a=cow[i];
        while(!stk.empty() && stk.top()<=a)
        {
            stk.pop();
        }
        vhc+=stk.size();
        stk.push(a);
    }
    
    printf("%lld",vhc);
    return 0;
}
    

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: