loop {
	n, m = gets.split.map &:to_i
	break if n == 0
	hs = (1..n).map { gets.to_i }
	ws = (1..m).map { gets.to_i }
	h_hash = Hash.new(0)
	(0..hs.size-1).each{|i|
		s = 0
		(i..hs.size-1).each{|j|
			s += hs[j]
			h_hash[s] += 1
		}
	}
	w_hash = Hash.new(0)
	(0..ws.size-1).each{|i|
		s = 0
		(i..ws.size-1).each{|j|
			s += ws[j]
			w_hash[s] += 1
		}
	}
	hs = h_hash.to_a.sort_by(&:first)
	ws = w_hash.to_a.sort_by(&:first)
	i = 0
	j = 0
	count = 0
	while i < hs.size && j < ws.size
		if hs[i][0] == ws[j][0]
			count += hs[i][1] * ws[i][1]
			i += 1
			j += 1
		elsif hs[i][0] < ws[j][0]
			i += 1
		else
			j += 1
		end
	end
	p count
}