#include using i64 = long long; constexpr int M = 30; int main() { int n; std::cin >> n; std::vector a(n + 1); for (int i = 1; i <= n; ++i) std::cin >> a[i]; i64 res = n * (n + 1LL) / 2; for (int x = 1; x <= M; ++x) { std::vector b(n + 1), s(n + 1); for (int i = 1; i <= n; ++i) b[i] = a[i] - x; std::partial_sum(b.begin(), b.end(), s.begin()); const int DELTA = n * M; auto f = [&](int v) {return DELTA + v;}; std::vector zero(DELTA * 2 + 1); std::vector nzero(DELTA * 2 + 1); for (int i = 1; i <= n; ++i) { if (b[i] == 0) { zero[f(s[i - 1])] += 1; res -= zero[f(s[i])] + nzero[f(s[i])]; } else { nzero[f(s[i - 1])] += 1; res -= zero[f(s[i])]; } } } std::cout << res + 1 << "\n"; return 0; }