#include int main() { int i, N, A[100001]; scanf("%d", &N); for (i = 1; i <= N; i++) scanf("%d", &(A[i])); int k, sum, num[2][6000001]; long long ans = (long long)N * (N - 1) / 2 + 1; for (k = 1; k <= 30; k++) { for (i = 0; i <= N * 60; i++) { num[0][i] = 0; num[1][i] = 0; } for (i = 1, sum = 0, num[0][N*30] = 1; i <= N; i++) { if (A[i] == k) ans -= num[0][sum + N * 30] - 1; else ans -= num[1][sum + A[i] - k + N * 30]; sum += A[i] - k; num[0][sum + N * 30]++; if (A[i] == k) num[1][sum + N * 30]++; } } printf("%lld\n", ans); fflush(stdout); return 0; }