
fun main(args:Array<String>):Unit {
    while(true){
        val (n, m) = readLine()!!.split(' ').map(String::toInt)
        if (n == 0 && m == 0) return
        val heights = Array(n){readLine()!!.toInt()}
        val widths = Array(m){readLine()!!.toInt()}
        for (i in 1 until n) heights[i] += heights[i - 1]
        for (j in 1 until m) widths[j] += widths[j - 1]
        val memoHeight = Array(1000 * n + 1){0}
        val memoWidth = Array(1000 * m + 1){0}
        for (height in heights) memoHeight[height]++
        for (width in widths) memoWidth[width]++
        for (i in 0 until n) for (j in (i + 1) until n) memoHeight[heights[j] - heights[i]]++
        for (i in 0 until m) for (j in (i + 1) until m) memoWidth[widths[j] - widths[i]]++
        println(
                memoHeight.zip(memoWidth).map{(a, b) -> a * b}.sum()
        )
    }
}
