#include<iostream>
#include<algorithm>
using namespace std;
const int N = 10010;
int A[N];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> A[i];
}
int res = 0;
for(int i = 1; i <= n; i ++){
int maxn = -1, minn = 100000010;
for(int j = i; j <= n; j ++){
maxn = max(maxn, A[j]);
minn = min(minn, A[j]);
if(maxn - minn == j - i) res ++;
}
}
cout << res << endl;
return 0;
}