#include <bits/stdc++.h>
using namespace std;
const long long P = 1e9 + 7;
const int N = 3e5 + 5;
const long long INF = 1e16;
const double pi = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, a[N];
long long ans = 0, h[N], hsum[N], sum[N];
void solve() {
  for (int i = (1); i <= (n); ++i) sum[i] = sum[i - 1] ^ h[a[i]];
  int j;
  for (int i = (1); i <= (n); ++i)
    if (a[i] == 1) {
      j = 1;
    } else {
      j = max(j, a[i]);
      if (i - j >= 0 && (sum[i] ^ sum[i - j]) == hsum[j]) ++ans;
    }
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%d", a + i), ans += (a[i] == 1);
  for (int i = (1); i <= (n); ++i) {
    h[i] = rng(), h[i] = (h[i] << 31) + rng();
    hsum[i] = hsum[i - 1] ^ h[i];
  }
  solve();
  reverse(a + 1, a + n + 1);
  solve();
  cout << ans << endl;
  return 0;
}
