#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<VL> VVL; typedef long long LL; #define all(a) (a).begin(), (a).end() #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define ALL(a) (a).begin(),(a).end() #define pb push_back int main() { int n;cin>>n; int AA[n]; rep(i,n){cin>>AA[i];} LL ans=LL(n)*(n+1)/2; for(int i=1;i<=30;i++){ //cout<<i<<endl; VI A,B; int a=0,b=0,sum=0; rep(j,n){ //cout<<A[j]<<endl; if(AA[j]==i){ if(sum!=0){ if(b==sum*i){B.pb(1);} else{B.pb(0);} b=0;sum=0; } a++; } else{ if(a!=0){ A.pb(a);a=0; } b+=AA[j];sum++; } //cout<<b<<endl; } if(a!=0){A.pb(a);} int m=A.size(); //cout<<m<<' '<<B.size()<<endl; rep(i,m){ans-=LL(A[i])*(A[i]+1)/2;} rep(i,m-1){ if(B[i]){ans-=LL(A[i])*A[i+1];} } } ans++; cout<<ans<<endl; }