def calc(arr, flag)
  (1...arr.size).each{|i| arr[i] += arr[i-1] }
  if flag
    arr.each{ |v| $list[v].nil? ? $list[v] = 1 : $list[v] += 1 }
  else arr.each{ |v| $list[v].nil? ? next : ($list[v].class == Array ? $list[v][1] += 1 : $list[v] = [$list[v], 1]) }
  end
end
loop do
  $n, $m = gets.split.map(&:to_i)
  break if $n == 0
  $list = {}
  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 $list.reduce(0){ |s, v| s += (v[1].class == Array ? v[1][0]*v[1][1] : 0) }
end