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

int h[1600], w[1600], H[1500001], W[1500001];

int main(void)
{
    int n, m;
    while (scanf("%d%d", &n, &m), n) {
        int i, j, res;
        for(i=1;i<=n;++i) scanf("%d", h+i);
        for(i=1;i<=m;++i) scanf("%d", w+i);

        memset(H, 0, sizeof(H));
        for(i=1;i<=n;++i) for(j=i;j<=n;++j) H[h[j]-h[i-1]]++;
        memset(W, 0, sizeof(W));
        for(i=1;i<=m;++i) for(j=i;j<=m;++j) W[w[j]-w[i-1]]++;

        res=0;
        for(i=1;i<=1500000;++i) res+=H[i]*W[i];
        printf("%d\n", res);
    }
    return 0;
}