#include <iostream>
#include <algorithm>
using namespace std;
int a[50010];
int main()
{
int n,res=0;cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++){
int minn = a[i];
int maxx = a[i];
for(int j=i;j<n;j++){
if(a[j]<minn)minn=a[j];
if(a[j]>maxx)maxx=a[j];
if(maxx-minn==j-i)res++;
}
}
cout<<res<<endl;
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-32997.html