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