Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
while (n != 0 or m != 0):
    nlist = [] 
    mlist = []
    for i in range(n):
        t = int(input()) 
        nlist.append(t) 
    for i in range(m): 
        t = int(input())
        mlist.append(t)
    nsum = [] 
    for i in range(n):
        for k in range(n-i):
            c = 0 
            for l in range(i+1):
                c += nlist[k+l]
            nsum.append(c)
    msum = [] 
    for i in range(m): 
        for k in range(m-i):
            c = 0
            for l in range(i+1):
                c += mlist[k+l]
            msum.append(c)
    count = 0
    for i in nsum:
        count += msum.count(i)
    print(count) 
    n,m = map(int, input().split())


Fixed submission:
while True:
    n,m = map(int, input().split())
    if n == 0 and m == 0:
        break
    nlist = [0]
    mlist = [0]
    for i in range(n):
        nlist += [nlist[-1] + int(input())]
    for i in range(m):
        mlist += [mlist[-1] + int(input())]

    l = [0for i in range(1000*1501)]
    for i in range(n):
        t = 0
        for k in range(i+1,n+1):
            t = nlist[k] - nlist[i]
            l[t] += 1
    count = 0
    for i in range(m):
        for k in range(i+1,m+1):
            t = mlist[k] - mlist[i]
            count += l[t]
    
    print(count)

Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
while (n != 0 or m != 0):
    nlist = [int(input())for i in range(n)]
    mlist = [int(input())for i in range(m)]
    nsum = [] 
    for i in range(n):
        for k in range(n-i):
            c = 0 
            for l in range(i+1):
                c += nlist[k+l]
            nsum.append(c)
    count = 0
    for i in range(m):
        for k in range(m-i):
            c = 0
            for l in range(i+1):
                c += mlist[k+l]
            if (c in nsum):
                count += nsum.count(c)       
    print(count) 
    n,m = map(int, input().split())


Fixed submission:
while True:
    n,m = map(int, input().split())
    if n == 0 and m == 0:
        break
    nlist = [0]
    mlist = [0]
    for i in range(n):
        nlist += [nlist[-1] + int(input())]
    for i in range(m):
        mlist += [mlist[-1] + int(input())]

    l = [0for i in range(1000*1501)]
    for i in range(n):
        t = 0
        for k in range(i+1,n+1):
            t = nlist[k] - nlist[i]
            l[t] += 1
    count = 0
    for i in range(m):
        for k in range(i+1,m+1):
            t = mlist[k] - mlist[i]
            count += l[t]
    
    print(count)

Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
while (n != 0 or m != 0):
    nlist = [0]
    mlist = [0]
    for i in range(n):
        nlist += [nlist[-1] + int(input())]
    for i in range(m):
        mlist += [mlist[-1] + int(input())]
    nsum = []
    msum = []
    
    for i in range(n):
        for k in range(i+1,n+1):
            c = nlist[k] - nlist[i]
            nsum.append(c)
    for i in range(m):
        for k in range(i+1,m+1):
            c = mlist[k] - mlist[i]
            msum.append(c)
    count = 0
    for i in nsum:
        count += msum.count(i)
    print(count) 
    n,m = map(int, input().split())


Fixed submission:
while True:
    n,m = map(int, input().split())
    if n == 0 and m == 0:
        break
    nlist = [0]
    mlist = [0]
    for i in range(n):
        nlist += [nlist[-1] + int(input())]
    for i in range(m):
        mlist += [mlist[-1] + int(input())]

    l = [0for i in range(1000*1501)]
    for i in range(n):
        t = 0
        for k in range(i+1,n+1):
            t = nlist[k] - nlist[i]
            l[t] += 1
    count = 0
    for i in range(m):
        for k in range(i+1,m+1):
            t = mlist[k] - mlist[i]
            count += l[t]
    
    print(count)

Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
while (n != 0 or m != 0):
    nlist = [0]
    mlist = [0]
    for i in range(n):
        nlist += [nlist[-1] + int(input())]
    for i in range(m):
        mlist += [mlist[-1] + int(input())]
    nsum = []
    msum = []
    count = 0
    for i in range(n):
        for k in range(i+1,n+1):
            c = nlist[k] - nlist[i]
            nsum.append(c)
    for i in range(m):
        for k in range(i+1,m+1):
            c = mlist[k] - mlist[i]
            if (c in nsum):
                count += nsum.count(c)
    print(count) 
    n,m = map(int, input().split())


Fixed submission:
while True:
    n,m = map(int, input().split())
    if n == 0 and m == 0:
        break
    nlist = [0]
    mlist = [0]
    for i in range(n):
        nlist += [nlist[-1] + int(input())]
    for i in range(m):
        mlist += [mlist[-1] + int(input())]

    l = [0for i in range(1000*1501)]
    for i in range(n):
        t = 0
        for k in range(i+1,n+1):
            t = nlist[k] - nlist[i]
            l[t] += 1
    count = 0
    for i in range(m):
        for k in range(i+1,m+1):
            t = mlist[k] - mlist[i]
            count += l[t]
    
    print(count)

Buggy python submission (verdict: Runtime Error):
while True:
    n,m = map(int, input().split())
    if n == 0 and m == 0:
        break
    nlist = [0]
    mlist = [0]
    for i in range(n):
        nlist += [nlist[-1] + int(input())]
    for i in range(m):
        mlist += [mlist[-1] + int(input())]
    nsum = []
    msum = []
    count = 0
    for i in range(n):
        for k in range(i+1,n+1):
            c = nlist[k] - nlist[i]
            nsum.append(c)
    for i in range(m):
        for k in range(i+1,m+1):
            c = mlist[k] - mlist[i]
            if (c in nsum):
                count += nsum.count(c)
    print(count) 


Fixed submission:
while True:
    n,m = map(int, input().split())
    if n == 0 and m == 0:
        break
    nlist = [0]
    mlist = [0]
    for i in range(n):
        nlist += [nlist[-1] + int(input())]
    for i in range(m):
        mlist += [mlist[-1] + int(input())]

    l = [0for i in range(1000*1501)]
    for i in range(n):
        t = 0
        for k in range(i+1,n+1):
            t = nlist[k] - nlist[i]
            l[t] += 1
    count = 0
    for i in range(m):
        for k in range(i+1,m+1):
            t = mlist[k] - mlist[i]
            count += l[t]
    
    print(count)