fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toLong() }
    val count = hashMapOf<Long,Int>()
    count[0] = 1

    var ans = 0L
    var sum = 0L
    a.map {
        sum += it
        ans += count.getOrDefault(sum, 0)
        count[sum] = count.getOrDefault(sum, 0) + 1
    }
    println(ans)
}