#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	while (1) {
		int n, m; cin >> n >> m;
		if (n==0 && m==0) return 0;
		vector<int> h(n); for (int i=0; i<n; i++) cin >> h[i];
		vector<int> w(m); for (int i=0; i<m; i++) cin >> w[i];
		map<int, int> mh; map<int, int> mw;

		for (int i = 0; i < n; ++i)
		{
			int cum = 0;
			for (int j = i; j < n; ++j)
			{
				cum += h[j];
				mh[cum] += 1;
			}
		}

		for (int i = 0; i < m; ++i)
		{
			int cum = 0;
			for (int j = i; j < m; ++j)
			{
				cum += w[j];
				mw[cum] += 1;
			}
		}
		int ans = 0;
		for (auto it = mh.begin(); it != mh.end(); ++it)
		{
			ans += it->second * mw[it->first];
		}
		cout << ans << endl;
	}
}
