package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	count := make([]int, n+1)
	for i := n - 1; i >= 0; i-- {
		sum := 0
		for j := i; j < n; j++ {
			sum += a[j]
			if sum == 0 {
				count[i] += count[j+1] + 1
				break
			}
		}
	}

	ans := 0
	for _, c := range count {
		ans += c
	}
	fmt.Println(ans)
}
