fun main(args: Array<String>) {
    agc023a()
}

fun agc023a() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()

    val cumulativeSum = LongArray(n + 1)
    for (i in aList.indices) cumulativeSum[i + 1] = cumulativeSum[i] + aList[i]

    val map = mutableMapOf<Long, Int>()

    for (i in 0..aList.lastIndex + 1) {
        map[cumulativeSum[i]] = (map[cumulativeSum[i]] ?: 0) + 1
    }

    val answer = map.map { nCk(it.value, 2) }.sum()

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()

private const val MAX = 1000000
private val fac = LongArray(MAX)
private val fInv = LongArray(MAX)
private val inv = LongArray(MAX)
private var isNCkInit = false

private fun nCk(n: Int, k: Int): Long {
    if (!isNCkInit) {
        isNCkInit = true
        fac[0] = 1
        fac[1] = 1
        fInv[0] = 1
        fInv[1] = 1
        inv[1] = 1
        for (i in 2 until MAX) {
            fac[i] = fac[i - 1] * i % MOD
            inv[i] = MOD - inv[(MOD % i).toInt()] * (MOD / i) % MOD
            fInv[i] = fInv[i - 1] * inv[i] % MOD
        }
    }
    if (n < k) return 0
    if (n < 0 || k < 0) return 0
    return fac[n] * (fInv[k] * fInv[n - k] % MOD) % MOD
}
