#include<bits/stdc++.h>
int n,m,i,j,h[1500],w[1500],p[1<<21],q[1<<21],x;
int main(){
  while(scanf("%d%d",&n,&m),n){
    for(i=0;i<n;)scanf("%d",h+i++);
    for(i=0;i<m;)scanf("%d",w+i++);
    for(i=0;i<n;++i)for(x=0,j=i;j<n;++p[x])x+=h[j++];
    for(i=0;i<m;++i)for(x=0,j=i;j<m;++q[x])x+=w[j++];
    for(x=i=0;i<1<<21;p[i]=q[i++]=0)x+=p[i]*q[i];
    printf("%d\n",x);
  }
}