#include <bits/stdc++.h>
using namespace std;
const int N=3e5+5;
typedef unsigned long long ull;
int n, a[N], ans=0, flag=0, Max=0, st=0;
ull b[N], h[N], h2[N];
ull Rand(ull L, ull R)
{
return rand()%(R-L+1)+L;
}
bool check(int L, int R)
{
return (h2[R]^h2[L-1])==(h[R-L+1]);
}
void get()
{
int pos=1;
for (int i=1; i<=n; i++) h2[i]=h2[i-1]^b[a[i]];
while (a[pos]!=1 && pos<=n) pos++;
while (pos<=n)
{
int Max=a[++pos];
while (a[pos]!=1 && pos<=n)
{
Max=max(Max, a[pos]);
if (check(pos-Max+1, pos)) ans++;
pos++;
}
}
}
int main()
{
srand(time(0));
scanf("%d", &n);
for (int i=1; i<=n; i++) b[i]=Rand(1e9, 1e18);
for (int i=1; i<=n; i++) h[i]=h[i-1]^b[i];
for (int i=1; i<=n; i++)
{
scanf("%d", &a[i]);
ans+=(a[i]==1);
}
get();
reverse(a+1, a+1+n);
get();
printf("%d", ans);
return 0;
}
/*
8
2 4 1 3 4 2 1 2
*/
RT,蒟蒻实在是不知道哪儿出问题了,求调 QAQ