fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map { it.toLong() }
    
    val cumsum = Array(n + 1) { 0L }
    val memo = mutableMapOf<Long, Long>()
    memo[0] = 1
    for (i in 0 until an.size) {
        var sum = cumsum[i] + an[i]
        cumsum[i + 1] = sum

        memo[sum] = memo.getOrPut(sum) { 0 } + 1
    }

    val ans = memo.filter { it.value >= 2 }.map { it.value * (it.value - 1) / 2 }.sum();
    println(ans)

}