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

#include <stdio.h>
#include <string.h>
#define TM 0
#if TM
#include <time.h>
#endif

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, v, sh, sw, s, ans;
#if TM
	clock_t start, end;
	start = clock();
#endif
	while (fgets(p=buf, 20, stdin) && *buf != '0') {
		n = getint(), p++, m = getint();
		for (sh = 0, i = 0; i < n; i++)	{
			fgets(p=buf, 10, stdin), v = getint();
			h[i] = v, sh += v;
		}
		for (sw = 0, i = 0; i < m; i++) {
			fgets(p=buf, 10, stdin), v = getint();
			w[i] = v, sw += v;
		}
		if (sh > sw) sh = sw;

		memset(f, 0, sizeof(f));
		for (i = 0; i < n; i++) {
			for (s = 0, j = i; s <= sh && j < n; j++) s += h[j], f[s]++;
		}
		ans = 0;
		for (i = 0; i < m; i++) {
			for (s = 0, j = i; s <= sh && j < m; j++) s += w[j], ans += f[s];
		}
		printf("%d\n", ans);
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}