def calc(arr, n)
  (1...n).each{|i| arr[i] += arr[i-1] }
  arr.each{ |v| $list[v] ||= 0; $list[v] += 1 }
end
def calc2(arr, n)
  (1...n).each{|i| arr[i] += arr[i-1] }
  arr.each{ |v| $list[v].nil? ? next : $res += $list[v] }
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], n) }
  (0...m).each{ |i| calc2(k[i..-1], m) }
  p $res
end