def calc(arr, n)
  (1...n).each{|i| arr[i] += arr[i-1] }
  arr
end
loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0
  l = n.times.map{ gets.to_i }
  k = m.times.map{ gets.to_i }
  list = [0] * ([l.reduce(:+), k.reduce(:+)].max + 1)
  res = 0
  (0...n).each do |i|
    arr = calc(l[i..-1], n - i)
    arr.each{ |v| list[v] += 1 }
  end
  (0...m).each do |i|
    arr = calc(k[i..-1], m - i)
    arr.each{ |v| res += list[v] }
  end
  p res
end