#include <bits/stdc++.h>
using namespace std;
unsigned long long rnd() {
  static unsigned long long A = 534289562384793132ull;
  static unsigned long long B = 123789571290518103ull;
  static unsigned long long C = 574315680931845710ull;
  static unsigned long long D = 582190571202109013ull;
  unsigned long long tmp = A ^ B ^ C ^ D;
  A ^= B >> 8;
  B ^= C << 3;
  C ^= D >> 5;
  D ^= tmp << 7;
  return tmp;
}
const int N = 300005;
int n, ans, b[N];
unsigned long long a[N], sa[N], sb[N];
void work(int p) {
  int mx = 1;
  for (; p < n && b[p + 1] != 1;) {
    mx = max(mx, b[p + 1]);
    ++p;
    if (mx <= p && sa[mx] == (sb[p] ^ sb[p - mx])) ++ans;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(10000); i++) rnd();
  for (int i = (int)(1); i <= (int)(n); i++)
    a[i] = rnd(), sa[i] = sa[i - 1] ^ a[i];
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &b[i]);
  for (int T = (int)(1); T <= (int)(2); T++) {
    for (int i = (int)(1); i <= (int)(n); i++) sb[i] = sb[i - 1] ^ a[b[i]];
    for (int i = (int)(1); i <= (int)(n); i++)
      if (b[i] == 1) {
        if (T == 1) ++ans;
        work(i);
      }
    reverse(b + 1, b + n + 1);
  }
  printf("%d\n", ans);
}
