#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
int n;
int a[MAXN];
int freq[MAXN];
long long solve() {
  long long ret = 0;
  for (int i = (0); i < (n); ++i)
    if (a[i] == 0) ++ret;
  for (int i = (0); i < (n); ++i) freq[i] = 0;
  for (int rep = (0); rep < (2); ++rep) {
    for (int i = (0); i < (n); ++i)
      if (a[i] == 0) {
        int l = i, r = i, mx = a[i], cnt = 0;
        if (++freq[a[i]] == 1) ++cnt;
        while (r + 1 < n) {
          ++r;
          if (++freq[a[r]] == 1) ++cnt;
          mx = max(mx, a[r]);
          while (freq[a[r]] > 1 && l < i) {
            if (--freq[a[l]] == 0) --cnt;
            ++l;
          }
          if (freq[a[r]] > 1) {
            --freq[a[r]];
            --r;
            break;
          }
          while (l - 1 >= 0 && a[l - 1] <= mx && freq[a[l - 1]] == 0) {
            --l;
            if (++freq[a[l]] == 1) ++cnt;
          }
          if (cnt == mx + 1) ++ret;
        }
        for (int j = (l); j <= (r); ++j) assert(--freq[a[j]] == 0);
      }
    reverse(a, a + n);
  }
  return ret;
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]), --a[i];
  printf("%lld\n", solve());
}
int main() {
  run();
  return 0;
}
