#include <bits/stdc++.h>
using namespace std;
mt19937_64 mt(time(0));
const int N = 4e5;
int A[N], n;
unsigned long long rd[N], pr[N], ans, xL[N];
void solve() {
  for (int i = 1; i <= n; ++i)
    if (A[i] == 1) {
      int j;
      for (j = i - 1; A[j] != 1; --j) xL[i - j] = xL[i - j - 1] ^ rd[A[j]];
      int mx = 1, len = i - j - 1;
      unsigned long long nw = rd[1];
      for (j = i + 1; A[j] != 1; ++j) {
        mx = max(mx, A[j]), nw ^= rd[A[j]];
        if (mx >= j - i + 1 && mx <= j - i + 1 + len &&
            pr[mx] == (nw ^ xL[mx - (j - i + 1)]))
          ++ans;
      }
    }
}
int main() {
  scanf("%d", &n), A[0] = A[n + 1] = 1;
  for (int i = 1; i <= n; ++i)
    scanf("%d", A + i), rd[i] = mt(), pr[i] = pr[i - 1] ^ rd[i],
                        ans += A[i] == 1;
  solve(), reverse(A + 1, A + n + 1), solve();
  printf("%llu\n", ans);
  return 0;
}
