#include<stdio.h>
int length_h[1500000],length_w[1500000];
int main(void){
	int N,M,h[1501],w[1501],i,j,k,hh,ww,score;

	while(1){
		scanf("%d %d",&N,&M);
		if(N==0&&M==0){break;}
		for(i=1;i<=N;i++){scanf("%d",&h[i]);}
		for(i=1;i<=M;i++){scanf("%d",&w[i]);}

		score=0;
		for(i=1;i<=1500000;i++){length_h[i]=0;length_w[i]=0;}
		
		for(i=1;i<=N;i++){
			for(j=0;j<=N-i;j++){
				hh=0;
				for(k=1;k<=i;k++){
					hh+=h[j+k];
				}
				length_h[hh]++;
			}
		}

		for(i=1;i<=M;i++){
			for(j=0;j<=M-i;j++){
				ww=0;
				for(k=1;k<=i;k++){
					ww+=w[j+k];
				}
				length_w[ww]++;
			}
		}

		for(i=1;i<=1500000;i++){
			score+=(length_h[i]*length_w[i]);
		}
		printf("%d\n",score);
	}
	return 0;
}