// AOJ 2015: Square Route
// 2017.11.04 bal4u@uu

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

int h[1502], w[1502];
int f[1500001];
char buf[20], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, s, ans;

	while (fgets(p=buf, 20, stdin) && *buf != '0') {
		n = getint(), p++, m = getint();
		for (i = 0; i < n; i++)	fgets(p=buf, 10, stdin), h[i] = getint();
		for (i = 0; i < m; i++)	fgets(p=buf, 10, stdin), w[i] = getint();

		memset(f, 0, sizeof(f));
		for (i = 0; i < n; i++) {
			for (s = 0, j = i; j < n; j++) s += h[j], f[s]++;
		}
		ans = 0;
		for (i = 0; i < m; i++) {
			for (s = 0, j = i; j < m; j++) s += w[j], ans += f[s];
		}
		printf("%d\n", ans);
	}
	return 0;
}