#include <stdio.h>
#define MIN(a,b) ((a) < (b) ? (a) : (b))

int h[1500],w[1500];

void scaning(int n,int m){
	int i;
	for(i=0;i<n;i++) scanf("%d",&h[i]);
	for(i=0;i<m;i++) scanf("%d",&w[i]);
}

int setting_value(int s,int l,int *ar){
	int i,result=0;
	for(i=s;i<s+l;i++){
		result += ar[i];
	}
	return result;
}

void count_square(int n,int m){
	int i,j,p,q,cnt_sq,base,a,b;
	cnt_sq = 0;
	base = MIN(n,m);
	scaning(n,m);
	for(p=1;p<=base;p++){
		for(i=0;i<n-p+1;i++){
			a = setting_value(i,p,h);
			for(q=1;q<=base;q++){
				for(j=0;j<m-q+1;j++){
					b = setting_value(j,q,w);
					if(a == b){
						cnt_sq++; 
					}
				}
			}
		}
	}
	printf("%d\n",cnt_sq);
}

int main(void) {
	int n,m;
	scanf("%d %d",&n,&m);
	while(n != 0){
		count_square(n,m);
		scanf("%d %d",&n,&m);
	}
	return 0;
}