#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, static_modint& a) {long long x; is >> x; a = x; return is;} template istream& operator>>(istream& is, dynamic_modint& a) {long long x; is >> x; a = x; return is;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template ostream& operator<<(ostream& os, const set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const unordered_set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const atcoder::segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const atcoder::lazy_segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} int main(){ int n; cin >> n; vector a(n); cin >> a; const int M = 30; const int R = n * M; vector cnt_zero(2 * R + 1); vector cnt_non_zero(2 * R + 1); long long ans = (long long)n * (n + 1) / 2; for(int x = 1; x <= M; x++){ vector b(n); rep(i, n) b[i] = a[i] - x; vector s(n + 1); rep(i, n) s[i + 1] = s[i] + b[i]; rep(i, n){ if(b[i] == 0){ cnt_zero[R + s[i]]++; ans -= cnt_zero[R + s[i + 1]] + cnt_non_zero[R + s[i + 1]]; }else{ cnt_non_zero[R + s[i]]++; ans -= cnt_zero[R + s[i + 1]]; } } rep(i, n){ if(b[i] == 0) cnt_zero[R + s[i]] = 0; else cnt_non_zero[R + s[i]] = 0; } } ans++; cout << ans << "\n"; return 0; }