loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0 && m == 0
    h = n.times.map{gets.to_i}
    w = m.times.map{gets.to_i}
    hs = Hash.new(0)
    ws = Hash.new(0)
    n.times do |i|
        height = h[i]
        hs[height] += 1
        (i+1).upto(n-1) do |j|
            height += h[j]
            hs[height] += 1
        end
    end
    m.times do |i|
        width = w[i]
        ws[width] += 1
        (i+1).upto(m-1) do |j|
            width += w[j]
            ws[width] += 1
        end
    end
    ans = 0
    hs.each do |k,v|
        ans += v * ws[k]
    end
    puts ans
end