#include <bits/stdc++.h>
using namespace std;
int n, p[10001], ans;
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> p[i];
for (int i = 1; i <= n; ++i) {
int mn = 100001, mx = 0;
for (int j = i; j <= n; ++j) {
mn = min(mn, p[j]), mx = max(mx, p[j]);
if (mx - mn == j - i) ans++;
}
}
cout << ans << endl;
return 0;
}