fun main(args:Array<String>):Unit{
    val n = readLine()!!.toInt()
    val nums = readLine()!!.split(' ').map(String::toInt)
    println(Array(n + 1){0L}.apply {
        var s = 0L
        for (i in 0 .. n){
            this[i] = s
            if (i in 0 until n) s += nums[i]
        }
    }.groupBy { it }.filterValues { it.size >= 2 }.map{ it.value.size * (it.value.size - 1L) / 2 }.sum())
}