#include <iostream>
using namespace std;
const int N = 1E4 + 10;
int a[N];
int main(){
int n; cin >> n;
for(int i = 0; i < n; i ++ ) cin >> a[i];
int cnt = 0;
for(int i = 0; i < n; i ++ ){
int maxv = -1;
int minv = 0x3f3f3f;
for(int j = i; j < n; j ++ ){
maxv = max(maxv, a[j]);
minv = min(minv, a[j]);
int amount = j - i + 1;
if(amount == maxv - minv + 1) cnt ++ ;
}
}
cout << cnt << endl;
return 0;
}