#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const int HWMAX = 1501;
int Hs[1501];
int Ws[1501];
int HW[1501*2002];

int main(){
    while(1){
        memset(Hs,0,sizeof(int)*HWMAX);
        memset(Ws,0,sizeof(int)*HWMAX);
        memset(HW,0,sizeof(int)*HWMAX*2002);
        int N,M;
        int i,j;
        scanf("%d %d",&N,&M);
        if(N == 0) break;
        for(i=1;i<=N;i++){
            int h;
            scanf("%d",&h);
            Hs[i] = (Hs[i-1]+h);
        }

        for(i=0;i<M;i++){
            int w;
            scanf("%d",&w);
            Ws[i] = (Ws[i-1]+w);
        }
        for(i=0;i<N+1;i++){
            for(j=0;j<M+1;j++){
                HW[Hs[i]+Ws[j]]++;
            }
        }
        int cnt = 0;
        for(i=0;i<2002*HWMAX;i++){
            cnt += HW[i]*(HW[i]-1)/2;
        }
        printf("%d\n",cnt);
    }
    return 0;
}