#include <bits/stdc++.h>
using namespace std;
unsigned long long val[300003];
int n, a[300003], ans;
unsigned long long xorsum[300003], oksum[300003];
bool check(int l, int r) {
  return (xorsum[l - 1] ^ xorsum[r]) == oksum[r - l + 1];
}
int main() {
  srand(time(NULL));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    val[i] = rand() * 32768ull * 32768 * 32768 + rand() * 32768ull * 32768 +
             rand() * 32768ull + rand();
    scanf("%d", &a[i]);
    a[i]--;
  }
  for (int i = 1; i <= n; i++) xorsum[i] = xorsum[i - 1] ^ val[a[i] + 1];
  for (int i = 1; i <= n; i++) oksum[i] = oksum[i - 1] ^ val[i];
  for (int i = 1; i <= n; i++) {
    if (a[i]) continue;
    ans++;
    int mxn = 1;
    for (int j = i + 1; j <= n && a[j]; j++) {
      mxn = max(mxn, a[j]);
      ans += check(j - mxn, j);
    }
    mxn = 1;
    for (int j = i - 1; j >= 1 && a[j]; j--) {
      mxn = max(mxn, a[j]);
      ans += check(j, j + mxn);
    }
  }
  cout << ans;
}
