from collections import defaultdict as ddict

def cal_interval(Num):

	interval = ddict(int)

	dp = [int(input()) for i in range(Num)]

	for i in range(Num):

		tmp = dp[i]

		interval[tmp] += 1

		for j in range(i):

			dp[j] += tmp

			interval[dp[j]] += 1

	return interval

while 1:

	N, M = list(map(int,input().split(" ")))

	if (N, M) == (0,0):

		break

	Lon = cal_interval(N)

	Lat = cal_interval(M)

	print(sum(Lon[k] * Lat[k] for k in Lon if k in Lat))
from collections import defaultdict as ddict

def cal_interval(Num):

	interval = ddict(int)

	dp = [int(input()) for i in range(Num)]

	for i in range(Num):

		tmp = dp[i]

		interval[tmp] += 1

		for j in range(i):

			tmp += dp[i-j-1]

			interval[tmp] += 1

	return interval

while 1:

	N, M = list(map(int,input().split(" ")))

	if (N, M) == (0,0):

		break

	Lon = cal_interval(N)

	Lat = cal_interval(M)

	print(sum(Lon[k] * Lat[k] for k in Lon if k in Lat))
from collections import defaultdict as ddict


def cal_interval(Num):
    interval = ddict(int)
    dp = [int(input()) for i in range(Num)]
    for i in range(Num):
        tmp = dp[i]
        interval[tmp] += 1
        for j in range(i):
            dp[j] += tmp
            interval[dp[j]] += 1
    return interval


while 1:
    N, M = list(map(int, input().split(" ")))
    if (N, M) == (0, 0):
        break
    Lon = cal_interval(N)
    Lat = cal_interval(M)
    print(sum(Lon[k] * Lat[k] for k in Lon if k in Lat))

from collections import defaultdict as ddict


def cal_interval(Num):
    interval = ddict(int)
    dp = [int(input()) for i in range(Num)]
    for i in range(Num):
        tmp = dp[i]
        interval[tmp] += 1
        for j in range(i):
            tmp += dp[i - j - 1]
            interval[tmp] += 1
    return interval


while 1:
    N, M = list(map(int, input().split(" ")))
    if (N, M) == (0, 0):
        break
    Lon = cal_interval(N)
    Lat = cal_interval(M)
    print(sum(Lon[k] * Lat[k] for k in Lon if k in Lat))

-            dp[j] += tmp -            interval[dp[j]] += 1 +            tmp += dp[i - j - 1] +            interval[tmp] += 1