#include <bits/stdc++.h>
using namespace std;
int a[300005], n;
long long bs[300005], BIT[300005], target[300005];
void update(int idx, long long val) {
  for (; idx < 300005; idx += idx & -idx) BIT[idx] ^= val;
}
long long query(int idx) {
  long long res(0);
  for (; idx; idx -= idx & -idx) res ^= BIT[idx];
  return res;
}
long long query(int l, int r) { return query(r) ^ query(l - 1); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  target[0] = 0;
  for (int i = 1; i <= n; ++i) {
    bs[i] = rng();
    target[i] = target[i - 1] ^ bs[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    update(i, bs[a[i]]);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] == 1) {
      int L = i, R = i;
      while (L > 1 && a[L - 1] != 1) --L;
      while (R < n && a[R + 1] != 1) ++R;
      for (int l = i, mx = 0; l >= L; --l) {
        mx = max(mx, a[l]);
        int r = mx + l - 1;
        ans += (r <= R && query(l, r) == target[r - l + 1]);
      }
      for (int r = i + 1, mx = 0; r <= R; ++r) {
        mx = max(mx, a[r]);
        int l = r - mx + 1;
        ans += (l >= L && query(l, r) == target[r - l + 1]);
      }
    }
  cout << ans;
}
