fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map(String::toLong)
    val aAccumulation = mutableListOf(0L)
    for (i in 1..n) {
        aAccumulation.add(aAccumulation[i - 1] + aList[i - 1])
    }
    var ans = 0L
    aAccumulation.distinct().forEach { it1 ->
        run {
            ans += kaijo(aAccumulation.filter { it == it1 }.size - 1)

        }
    }
    println(ans)
}

fun kaijo(i: Int): Long {
    if (i < 2) return i.toLong()
    var ans = 1L
    for (k in 2..i) {
        ans *= k
    }
    return ans
}