loop do
  n,m = gets.split.map(&:to_i)
  exit if n == 0 and m == 0
  hs = n.times.map{gets.to_i}
  ws = m.times.map{gets.to_i}
  hss = hs.inject([0]){|s,hi| s << s.last + hi; s}
  allh = hs.inject([hss]){|s,hi| s << s.last.map{|x| x - hi}; s}.flatten.select{|x| x > 0}
  wss = ws.inject([0]){|s,wi| s << s.last + wi; s}
  allw = ws.inject([wss]){|s,wi| s << s.last.map{|x| x - wi}; s}.flatten.select{|x| x > 0}
  puts (allh | allw).inject(0){|s,x| s += allh.count(x) * allw.count(x)}
end