#include <bits/stdc++.h>
const int N = 4 * (300000 + 100), E = 25;
int rmq[N][E], pos[N];
int v[N];
int seg_max(int l, int r) {
  r++;
  int e = (int)log2(r - l);
  return std::max(rmq[l][e], rmq[r - (1 << e)][e]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", v + i);
    v[i]--;
  }
  for (int i = 0; i < n; i++) rmq[i][0] = v[i];
  for (int j = 1; (1 << (j - 1)) < n; j++)
    for (int i = 0; i < n; i++)
      rmq[i][j] = std::max(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
  for (int i = 0; i < n; i++) pos[i] = 0;
  int nxt = 0, nw, cnt = 0;
  for (int i = 0; i < n; i++) {
    nxt = std::max(nxt, pos[v[i]]);
    pos[v[i]] = i + 1;
    for (int p = i; p >= nxt; p--) {
      if (seg_max(p, i) == i - p)
        cnt++;
      else
        p = i - seg_max(p, i) + 1;
    }
  }
  printf("%d\n", cnt);
}
