#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n;
int nums[N];
int main(){
cin >> n;
for (int i = 0; i < n; i ++ )cin >> nums[i];
int ans = 0;
for (int i = 0; i < n; i ++ ){
int maxv = 0,minv = 10010;
for (int j = i; j < n; j ++ ){
maxv = max(maxv,nums[j]);
minv = min(minv,nums[j]);
if((maxv - minv) == (j - i))ans ++;
}
}
cout << ans;
return 0;
}