#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, a[N];
int rval[N], pxor[N], axor[N];
int rnd() { return rand() << 15 | rand(); }
int main() {
  srand(int(time(0)));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) rval[i] = rnd(), pxor[i] = pxor[i - 1] ^ rval[i];
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i), axor[i] = axor[i - 1] ^ rval[a[i]];
  int64_t ans = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) {
      ++ans;
      int mx = 1;
      for (int j = i + 1; j <= n && a[j] != 1; j++) {
        mx = max(mx, a[j]);
        if (j - mx + 1 > 0 && pxor[mx] == (axor[j] ^ axor[j - mx])) ans++;
      }
    }
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) axor[i] = axor[i - 1] ^ rval[a[i]];
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) {
      int mx = 1;
      for (int j = i + 1; j <= n && a[j] != 1; j++) {
        mx = max(mx, a[j]);
        if (j - mx + 1 > 0 && pxor[mx] == (axor[j] ^ axor[j - mx])) ans++;
      }
    }
  printf("%lld\n", ans);
  return 0;
}
