#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 20;
int n, a[MAX], vis[MAX];
long long H[MAX], sH[MAX], sa[MAX];
int main(void) {
  scanf("%d", &n);
  for (register int i = (1); i <= (n); ++i) {
    scanf("%d", &a[i]);
    H[i] = 1ll * rand() * rand();
    sH[i] = sH[i - 1] ^ H[i];
  }
  int ans = 0, col = 0;
  for (register int k = (0); k < (2); ++k) {
    for (register int i = (1); i <= (n); ++i) sa[i] = sa[i - 1] ^ H[a[i]];
    for (register int i = (1); i <= (n); ++i)
      if (a[i] == 1) {
        ans += k == 0;
        vis[1] = ++col;
        int tMax = 1;
        for (int r = i + 1; r <= n; ++r) {
          if (vis[a[r]] == col) break;
          vis[a[r]] = col;
          tMax = max(tMax, a[r]);
          int l = r - tMax + 1;
          if (l <= 0) continue;
          if ((sa[r] ^ sa[l - 1]) == sH[tMax]) {
            ++ans;
          }
        }
      }
    if (!k) reverse(a + 1, a + n + 1);
  }
  printf("%d\n", ans);
  return 0;
}
