#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
int a[N], f[N][25], n, mx[N], last[N];
int rmq(int l, int r) {
  int k = 0;
  while ((1 << (k + 1)) <= r - l + 1) k++;
  return max(f[l][k], f[r - (1 << k) + 1][k]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) f[i][0] = a[i];
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
    }
  }
  mx[n + 1] = n;
  for (int i = n; i > 0; i--) {
    if (last[a[i]])
      mx[i] = min(mx[i + 1], last[a[i]] - 1);
    else
      mx[i] = mx[i + 1];
    last[a[i]] = i;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j <= mx[i]) {
      if (rmq(i, j) == j - i + 1)
        ans++, j++;
      else
        j = i + rmq(i, j) - 1;
    }
  }
  printf("%d", ans);
}
