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

int nanboku_num;
int tozai_num;
int nanboku[1501];
int tozai[1501];

int nanboku_list[1000001];
int tozai_list[1000001];

int main(void) {
	int i,j;
	int result;
	while(1) {
		scanf("%d%d",&nanboku_num,&tozai_num);
		if(nanboku_num==0 && tozai_num==0)break;
		for(i=1;i<=nanboku_num;i++) {
			scanf("%d",&nanboku[i]);
			nanboku[i]+=nanboku[i-1];
		}
		for(i=1;i<=tozai_num;i++) {
			scanf("%d",&tozai[i]);
			tozai[i]+=tozai[i-1];
		}
		memset(nanboku_list,0,sizeof(nanboku_list));
		memset(tozai_list,0,sizeof(tozai_list));
		for(i=0;i<nanboku_num;i++) {
			for(j=i+1;j<=nanboku_num;j++) {
				nanboku_list[nanboku[j]-nanboku[i]]++;
			}
		}
		for(i=0;i<tozai_num;i++) {
			for(j=i+1;j<=tozai_num;j++) {
				tozai_list[tozai[j]-tozai[i]]++;
			}
		}
		result=0;
		for(i=0;i<=1000000;i++)result+=nanboku_list[i]*tozai_list[i];
		printf("%d\n",result);
	}
	return 0;
}