from collections import defaultdict

while True:

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

    if N==M==0:break

    H=[eval(input()) for i in range(N)]

    W=[eval(input()) for i in range(M)]

    dh=defaultdict(int)

    dw=defaultdict(int)

    for i in range(N):

        s=H[i]

        dh[s]+=1

        for j in range(i+1,N):

            s+=H[j]

            dh[s]+=1

    for i in range(M):

        s=W[i]

        dw[s]+=1

        for j in range(i+1,M):

            s+=W[j]

            dw[s]+=1

    print(sum(dh[h]*dw[h] for h in dh if h in dw))
from collections import defaultdict

def getDic(L,n):

    d=defaultdict(int)

    for i in range(n):

        s=L[i]

        d[s]+=1

        for j in range(i+1,n):

            s+=L[j]

            d[s]+=1

    return d



while True:

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

    if N==M==0:break

    H=[eval(input()) for i in range(N)]

    W=[eval(input()) for i in range(M)]

    dh=getDic(H,N)

    dw=getDic(W,M)

    print(sum(dh[h]*dw[h] for h in dh if h in dw))
from collections import defaultdict

while True:
    N, M = list(map(int, input().split()))
    if N == M == 0:
        break
    H = [eval(input()) for i in range(N)]
    W = [eval(input()) for i in range(M)]
    dh = defaultdict(int)
    dw = defaultdict(int)
    for i in range(N):
        s = H[i]
        dh[s] += 1
        for j in range(i + 1, N):
            s += H[j]
            dh[s] += 1
    for i in range(M):
        s = W[i]
        dw[s] += 1
        for j in range(i + 1, M):
            s += W[j]
            dw[s] += 1
    print(sum(dh[h] * dw[h] for h in dh if h in dw))

from collections import defaultdict


def getDic(L, n):
    d = defaultdict(int)
    for i in range(n):
        s = L[i]
        d[s] += 1
        for j in range(i + 1, n):
            s += L[j]
            d[s] += 1
    return d


while True:
    N, M = list(map(int, input().split()))
    if N == M == 0:
        break
    H = [eval(input()) for i in range(N)]
    W = [eval(input()) for i in range(M)]
    dh = getDic(H, N)
    dw = getDic(W, M)
    print(sum(dh[h] * dw[h] for h in dh if h in dw))

+ + +def getDic(L, n): +    d = defaultdict(int) +    for i in range(n): +        s = L[i] +        d[s] += 1 +        for j in range(i + 1, n): +            s += L[j] +            d[s] += 1 +    return d + -    dh = defaultdict(int) -    dw = defaultdict(int) -    for i in range(N): -        s = H[i] -        dh[s] += 1 -        for j in range(i + 1, N): -            s += H[j] -            dh[s] += 1 -    for i in range(M): -        s = W[i] -        dw[s] += 1 -        for j in range(i + 1, M): -            s += W[j] -            dw[s] += 1 +    dh = getDic(H, N) +    dw = getDic(W, M)