def calc(arr, flag)
  (1...arr.size).each{|i| arr[i] += arr[i-1] }
  if flag
    arr.each{ |v| $list[v] ||= 0; $list[v] += 1 }
  else arr.each{ |v| $list[v].nil? ? next : $res += $list[v] }
  end
end
loop do
  $n, $m = gets.split.map(&:to_i)
  break if $n == 0
  $list = {}
  $res = 0
  l = $n.times.map{ gets.to_i }
  k = $m.times.map{ gets.to_i }
  (0...$n).each{|i| calc(l[i..-1], true) }
  (0...$m).each{|i| calc(k[i..-1], false) }
  p $res
end