// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^63.
// NOTE: This function does not handle error cases.
// Verified: ARC096D
fun fastReadLongs(n: Int): LongArray {
  val xs = LongArray(n)
  val s = readLine()!!
  var currentValue = 0L
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1L else 1L
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1L else 1L
  return xs
}


fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = fastReadLongs(n)
  var sum = 0L
  val countMap = mutableMapOf<Long, Long>()
  countMap[sum] = 1L
  for (x in xs) {
    sum += x
    countMap[sum] = countMap.getOrDefault(sum, 0) + 1L
  }

  var ans = 0L
  for ((key, value) in countMap) {
    if (value >= 2) {
      ans += value * (value - 1) / 2
    }
  }
  println(ans)
}
