#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a, b;
  int i, j, k, l;
  int h_now = 0, w_now = 0;
  int h[1505], w[1505];
  while (1) {
    w_now = 0;
    h_now = 0;
    h[0] = 0;
    w[0] = 0;
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    for (i = 1; i <= n; i++) {
      cin >> a;
      h_now = h_now + a;
      h[i] = h_now;
    }
    for (i = 1; i <= m; i++) {
      cin >> b;
      w_now = w_now + b;
      w[i] = w_now;
    }
    int length_h, length_w;
    int counter = 0;
    for (i = 0; i < n; i++) {
      for (j = i + 1; j <= n; j++) {
        length_h = h[j] - h[i];
        for (k = 0; k < m; k++) {
          for (l = k; l <= m; l++) {
            length_w = w[l] - w[k];
            if (length_h == length_w) {
              counter++;
            }
          }
        }
      }
    }
    cout << counter << endl;
  }
  return 0;
}
