fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val AArr = readInputLine().split(" ").map { it.toLong() }.toLongArray()
    val sumArr = LongArray(N)
    val sumArrCnt = mutableMapOf<Long, Long>()
    sumArr[0] = AArr[0]
    sumArrCnt.put(sumArr[0], 1L)
    
    for (i in 1 until N) {
        sumArr[i] = sumArr[i - 1] + AArr[i]
        sumArrCnt.put(sumArr[i], (sumArrCnt.get(sumArr[i]) ?: 0L) + 1L)
    }
    
    var ans = 0L
    var sum = 0L

    for (i in 0 until N) {
        ans += sumArrCnt.get(sum) ?: 0L
        sumArrCnt.put(sumArr[i], sumArrCnt.get(sumArr[i])!! - 1L)
        sum += AArr[i]
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}
