#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n, m;
    while (cin >> n >> m, n) {
        vector <int> h(n + 1, 0), w(m + 1, 0);
        rep (i, n) cin >> h[i + 1];
        rep (i, m) cin >> w[i + 1];

        rep (i, n) h[i + 1] += h[i];
        rep (i, m) w[i + 1] += w[i];

        map <int, int> lengthToCnt;

        rep (i, n + 1) range (j, i + 1, n + 1) lengthToCnt[h[j] - h[i]]++;

        int cnt = 0;
        rep (i, m + 1) range (j, i + 1, m + 1) cnt += lengthToCnt[w[j] - w[i]];
        cout << cnt << endl;
    }
    return 0;
}
