#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;

const int MAX = 1500 * 1000;
int cnt[MAX + 1];

inline void input(vector<int>& vec, int size) {
	vec.reserve(size + 1);
	vec.push_back(0);
	for(int i = 0; i < size; ++i) {
		int in;
		scanf("%d", &in);
		vec.push_back(vec[i] + in);
	}
}

int main() {
	for(int n, m; scanf("%d %d", &n, &m), n;) {
		vector<int> vertical, horizontal;
		input(vertical, n);
		input(horizontal, m);

		memset(cnt, 0, sizeof(cnt));
		for(int i = 0; i < n; ++i)
			for(int j = i + 1; j <= n; ++j)
				++cnt[vertical[j] - vertical[i]];

		int ans = 0;
		for(int i = 0; i < m; ++i)
			for(int j = i + 1; j <= m; ++j)
				ans += cnt[horizontal[j] - horizontal[i]];

		printf("%d\n", ans);
	}

	return EXIT_SUCCESS;
}