#include using namespace std; #include using namespace atcoder; using mint=modint998244353; //1000000007; using ll=long long; using pp=pair; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(int i=0;i<(int)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) int main(){ int n;cin>>n; ll ans=(ll)n*(n+1)/2; int t=30; vc>v(t); vc>x(t); vcvv(n); rep(i,n)cin>>vv[i],vv[i]--; rep(i,t)v[i][0]=1; rep(i,t)if(vv[0]!=i)x[i][0]=1; vcs(t,0); rep(j,n){ int a=vv[j]; rep(i,t){ s[i]+=a-i; ans-=v[i][s[i]]; if(a!=i)ans+=x[i][s[i]]; v[i][s[i]]++; if(j+1