while true
  n,m = gets.split(" ").map{|s| s.to_i}
  break if n==0 && m==0
  nw = Array.new(n){gets.to_i}
  se = Array.new(m){gets.to_i}

  lnw,lse = [],[]
  
  for i in 1..n  #????????????????????????
    x = nw[0..i-1].inject(:+)
    for j in 0..n-i #?????????????????????????????????
      lnw[x].nil? ? lnw[x] = 1 : lnw[x] += 1
      x += nw[i+j]-nw[j] if j<n-i
    end
  end

  for i in 1..m
    y = se[0..i-1].inject(:+)
    for j in 0..m-i
      lse[y].nil? ? lse[y] = 1 : lse[y] += 1
      y += se[i+j]-se[j] if j<m-i
    end
  end
  
  ans = 0
  for k in [nw.min,se.min].max..[lnw.size,lse.size].min-1
    ans += lnw[k]*lse[k] if !lnw[k].nil? && !lse[k].nil? 
  end

  puts ans
end