#include using namespace std; random_device rnd; mt19937 mt(rnd()); int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N; cin >> N; while(true){ vector A(N); for(auto &a : A) cin >> a;//a = mt()%30+1; vector> sepa(31); for(long long i=0; i M; for(auto &p : sepa.at(i)){ while(pos < p) M[zero]++,zero -= A.at(pos++)-i; answer += p-M[zero]; } } long long inf = 1001001001; for(long long i=1; i<=30; i++){ long long pos = N-1,zero = 0; reverse(sepa.at(i).begin(),sepa.at(i).end()); map M; map M2; for(auto &p : sepa.at(i)){ while(pos > p) M[zero]++,M2[zero+inf*A.at(pos)]++,zero -= A.at(pos--)-i; answer -= M[zero]-M2[zero+inf*A.at(p)]; } } cout << answer << endl; return 0; long long answer2 = 1; set>> S; for(int l=0; l> B(N); for(int i=0; i