#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000000LL int main(){ int n; cin>>n; vector a(n); rep(i,n){ cin>>a[i]; } long long ans = n; ans *= n+1; ans /= 2; ans++; for(int i=1;i<=30;i++){ rep(j,2){ map mp; if(a[0]!=i || j==0){ mp[0]++; } long long cur = 0; rep(k,n){ cur += a[k]-i; if(a[k]==i){ ans -= mp[cur]; } if(k!=n-1 && a[k+1]==i){ if(j==0)mp[cur]++; } else mp[cur]++; } reverse(a.begin(),a.end()); } } cout<