Point = Struct.new(:x, :y) do
  def square?(other)
    (other.x - x) == (other.y - y) && self != other
  end
end

Points = Struct.new(:h, :w) do
  def initialize(h, w)
    super(h, w)
    @x = 0
    @y = 0
  end

  def searching
    pts = self.clone
    pts.instance_variable_set(:@y, @y + 1)
    pts
  end

  def next_point
    result = nil
    if @y <= h.length
      result = Point.new(w[0...@x].sum, h[0...@y].sum)
      if @x < w.length
        @x += 1
      else
        @x = 0
        @y += 1
      end
    end

    result
  end
end

loop do
  n, m = gets.split(' ').map(&:to_i)
  # n >= 1
  # m <= 1500

  exit if n.zero? && m.zero?

  h = n.times.map { gets.to_i }
  w = m.times.map { gets.to_i }

  count = 0
  points = Points.new(h, w)

  while point = points.next_point
    rest = points.searching
    while other = rest.next_point
      #p [point, other] if point.square?(other)
      count += 1 if point.square?(other)
    end
    #puts "-------"
  end
  puts count
end

