#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, vis[N];
int Log2[N], a[N], st[N][20], lim[N];
void pre() {
  Log2[1] = 0, st[1][0] = a[1];
  for (int i = 2; i <= n; ++i) {
    Log2[i] = Log2[i - 1];
    if (i == 1 << Log2[i - 1] + 1) Log2[i]++;
    st[i][0] = a[i];
  }
  for (int i = n; i >= 1; --i)
    for (int j = 1; i + (1 << j) - 1 <= n; ++j) {
      st[i][j] = max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
    }
}
int ask(int l, int r) {
  int x = Log2[r - l + 1];
  return max(st[l][x], st[r - (1 << x) + 1][x]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  pre();
  lim[n + 1] = n;
  for (int i = n; i >= 1; i--) {
    int x = a[i];
    if (vis[x])
      lim[i] = min(lim[i + 1], vis[x] - 1);
    else
      lim[i] = lim[i + 1];
    vis[x] = i;
  }
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j <= lim[i]) {
      int ma = ask(i, j);
      if (ma == (j - i + 1))
        res++, j++;
      else
        j = i + ma - 1;
    }
  }
  printf("%lld", res);
}
