#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int w[2][8390000], h[1500];
int main() {
  int n[2];
  int numsum = 0;
  while (true) {
    cin >> n[0] >> n[1];
    if (n[0] == 0 && n[1] == 0)
      break;
    for (int f = 0; f < 2; f++) {
      for (int i = 0; i < n[f]; i++)
        cin >> h[i];
      int wcount = 0;
      for (int start = 0; start < n[f]; start++) {
        int count = 0;
        for (int len = start; len < n[f]; len++) {
          count += h[len];
          w[f][wcount] = count;
          wcount++;
        }
      }
      numsum += wcount - 1;
      w[f][wcount] = 10000000;
      sort(w[f], w[f] + wcount);
    }
    int ans = 0;
    int top[2] = {0};
    for (int i = 0; i < numsum; i++) {
      if (w[0][top[0]] < w[1][top[1]])
        top[0]++;
      if (w[0][top[0]] > w[1][top[1]])
        top[1]++;
      if (w[0][top[0]] == w[1][top[1]]) {
        ans++;
        top[0]++;
      }
    }
    cout << ans - 1 << endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int w[10000000], h[1500];
int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> h[i];
    int wcount = 0;
    for (int start = 0; start < n; start++) {
      int count = 0;
      for (int len = start; len < n; len++) {
        count += h[len];
        w[wcount] = count;
        wcount++;
      }
    }
    sort(w, w + wcount);
    for (int i = 0; i < m; i++)
      cin >> h[i];
    int key, ans = 0;
    for (int start = 0; start < m; start++) {
      int count = 0;
      for (int len = start; len < m; len++) {
        count += h[len];
        key = count;
        int left = 0, right = wcount;
        int mid;
        while (true) {
          if (left >= right)
            break;
          mid = (left + right) / 2;
          if (w[mid] == key) {
            ans++;
            int q = mid - 1;
            while (true) {
              if (q < 0)
                break;
              if (w[q] == w[mid])
                ans++;
              else
                break;
              q--;
            }
            q = mid + 1;
            while (true) {
              if (q == wcount)
                break;
              if (w[q] == w[mid])
                ans++;
              else
                break;
              q++;
            }
            break;
          }
          if (key > w[mid])
            left = mid + 1;
          if (key < w[mid])
            right = mid;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


#include <iostream>

using namespace std;

int y[1501], x[1501];
int main() {
  int N, M;
  while (cin >> N >> M && (N > 0 && M > 0)) {
    for (int i = 1, s = 0; i <= N; ++i) {
      int h;
      cin >> h;
      s += h;
      y[i] = s;
    }
    for (int i = 1, s = 0; i <= M; ++i) {
      int w;
      cin >> w;
      s += w;
      x[i] = s;
    }

    long num = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < M; ++j) {
        for (int k = i + 1; k <= N; ++k) {
          for (int l = j + 1; l <= M; ++l) {
            if (x[l] - x[j] == y[k] - y[i])
              num++;
          }
        }
      }
    }
    cout << num << endl;
  }
}

#include <iostream>
#include <map>

using namespace std;

int y[1501], x[1501];
int main() {
  int N, M;
  while (cin >> N >> M && (N > 0 && M > 0)) {
    for (int i = 1, s = 0; i <= N; ++i) {
      int h;
      cin >> h;
      s += h;
      y[i] = s;
    }
    for (int i = 1, s = 0; i <= M; ++i) {
      int w;
      cin >> w;
      s += w;
      x[i] = s;
    }

    map<int, int> hmap, wmap;
    for (int i = 0; i < N; ++i) {
      for (int j = i + 1; j <= N; ++j) {
        hmap[y[j] - y[i]]++;
      }
    }
    for (int i = 0; i < M; ++i) {
      for (int j = i + 1; j <= M; ++j) {
        wmap[x[j] - x[i]]++;
      }
    }

    long num = 0;
    for (const auto &p : hmap) {
      num += wmap[p.first] * p.second;
    }
    cout << num << endl;
  }
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

void solve() {
  int N, M;
  while (cin >> N >> M, N || M) {
    vector<int> Vech(N);
    vector<int> Vecw(M);
    vector<int> width;
    for (int i = 0; i < N; ++i) {
      cin >> Vech[i];
    }
    for (int i = 0; i < M; ++i) {
      cin >> Vecw[i];
    }
    for (int i = 0; i < M; ++i) {
      int w = Vecw[i];
      width.push_back(w);
      for (int j = i + 1; j < M; ++j) {
        w += Vecw[j];
        width.push_back(w);
      }
    }

    int count = 0;
    int wsize = width.size();
    for (int a = 0; a < wsize; ++a) {
      for (int i = 0; i < N; ++i) {
        int h = Vech[i];
        if (h == width[a]) {
          count++;
          continue;
        } else if (h > width[a]) {
          continue;
        }
        for (int j = i + 1; j < N; ++j) {
          h += Vech[j];
          if (h == width[a]) {
            count++;
            break;
          } else if (h > width[a]) {
            break;
          }
        }
      }
    }
    cout << count << endl;
  }
}

int main() {
  solve();
  return (0);
}

#include <iostream>
#include <map>
#include <vector>

using namespace std;

void solve() {
  int N, M;
  while (cin >> N >> M, N || M) {
    vector<int> Vech(N);
    vector<int> Vecw(M);
    map<int, int> Map;
    for (int i = 0; i < N; ++i) {
      cin >> Vech[i];
    }
    for (int i = 0; i < M; ++i) {
      cin >> Vecw[i];
    }
    for (int i = 0; i < M; ++i) {
      int w = Vecw[i];
      Map[w]++;
      for (int j = i + 1; j < M; ++j) {
        w += Vecw[j];
        Map[w]++;
      }
    }

    int count = 0;
    for (int i = 0; i < N; ++i) {
      int h = Vech[i];
      count += Map[h];
      for (int j = i + 1; j < N; ++j) {
        h += Vech[j];
        count += Map[h];
      }
    }
    cout << count << endl;
  }
}

int main() {
  solve();
  return (0);
}


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

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<int> x(n);
    vector<int> y(m);

    for (auto &i : x) {
      cin >> i;
    }

    for (auto &i : y) {
      cin >> i;
    }

    vector<int> dis_x;
    for (int i = 0; i < n; i++) {
      int dis = x[i];
      dis_x.push_back(dis);
      if (i + 1 == n)
        continue;
      for (int j = i + 1; j < n; j++) {
        dis += x[j];
        dis_x.push_back(dis);
      }
    }

    vector<int> dis_y;
    for (int i = 0; i < m; i++) {
      int dis = y[i];
      dis_y.push_back(dis);
      if (i + 1 == m)
        continue;
      for (int j = i + 1; j < m; j++) {
        dis += y[j];
        dis_y.push_back(dis);
      }
    }

    int res = 0;
    for (int i = 0; i < dis_x.size(); i++) {
      for (int j = 0; j < dis_y.size(); j++) {
        if (dis_x[i] == dis_y[j]) {
          res++;
        }
      }
    }

    cout << res << endl;
  }

  return 0;
}

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

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<int> x(n);
    vector<int> y(m);

    for (auto &i : x) {
      cin >> i;
    }

    for (auto &i : y) {
      cin >> i;
    }

    vector<int> dis_x;
    for (int i = 0; i < n; i++) {
      int dis = 0;
      for (int j = i; j < n; j++) {
        dis += x[j];
        dis_x.push_back(dis);
      }
    }

    vector<int> dis_y;
    for (int i = 0; i < m; i++) {
      int dis = 0;
      for (int j = i; j < m; j++) {
        dis += y[j];
        dis_y.push_back(dis);
      }
    }

    sort(dis_x.begin(), dis_x.end());
    sort(dis_y.begin(), dis_y.end());

    int res = 0;
    for (int i = 0; i < dis_x.size(); i++) {
      int count_x = 1;
      while (dis_x[i + count_x] == dis_x[i])
        count_x++;

      auto up = upper_bound(dis_y.begin(), dis_y.end(), dis_x[i]);
      auto lo = lower_bound(dis_y.begin(), dis_y.end(), dis_x[i]);
      if (up != dis_y.end() || lo != dis_y.end())
        res += count_x * (up - lo);

      i += count_x - 1;
    }

    cout << res << endl;
  }

  return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;

template <typename T> void dump(T a, int n) {
  for (int i = 0; i < n; i++)
    cout << a[i] << (i == n - 1 ? '\\n' : ' ');
}

template <typename T> void dump(T a) { dump<T>(a, a.size()); }

int main(void) {
  for (int N, M; cin >> N >> M, N;) {
    VI hs(N), ws(M);
    for (auto &h : hs) {
      cin >> h;
    }
    for (auto &w : ws) {
      cin >> w;
    }

    VI sum(M + 1);
    partial_sum(ws.begin(), ws.end(), sum.begin() + 1);

    int cnt = 0;
    for (int y1 = 0; y1 < N; y1++) {
      int h = 0;
      for (int y2 = y1; y2 < N; y2++) {
        h += hs[y2];

        int x = 0;
        for (int x1 = 0; x1 < M; x1++) {
          bool found = binary_search(sum.begin(), sum.end(), h + x);
          cnt += found;

          x += ws[x1];
        }
      }
    }

    cout << cnt << endl;
  }

  return 0;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;

template <typename T> void dump(T a, int n) {
  for (int i = 0; i < n; i++)
    cout << a[i] << (i == n - 1 ? '\\n' : ' ');
}

template <typename T> void dump(T a) { dump<T>(a, a.size()); }

constexpr int LIM = 1000 * 1500;

int main(void) {
  for (int N, M; cin >> N >> M, N;) {
    VI hs(N), ws(M);
    for (auto &h : hs) {
      cin >> h;
    }
    for (auto &w : ws) {
      cin >> w;
    }

    VI hsum(LIM + 1), wsum(LIM + 1);

    for (int i = 0; i < N; i++) {
      int sum = 0;

      for (int j = i; j < N; j++) {
        sum += hs[j];
        hsum[sum]++;
      }
    }

    for (int i = 0; i < M; i++) {
      int sum = 0;

      for (int j = i; j < M; j++) {
        sum += ws[j];
        wsum[sum]++;
      }
    }

    int cnt = 0;
    for (int i = 0; i <= LIM; i++) {
      cnt += hsum[i] * wsum[i];
    }

    cout << cnt << endl;
  }

  return 0;
}


#include <iostream>
using namespace std;
int main() {
  while (1) {
    int N, M, count = 0, j, k;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    int h[N], w[M];
    for (int i = 0; i < N; ++i)
      cin >> h[i];
    for (int i = 0; i < M; ++i)
      cin >> w[i];
    for (j = 0; j < N; ++j) {
      int wsum = 0;
      int hsum = 0;
      for (int i = j; i < N; ++i) {
        hsum += h[i];
        for (k = 0; k < M; ++k) {
          wsum = 0;
          for (int i = k; i < M; ++i) {
            wsum += w[i];
            if (wsum == hsum)
              ++count;
            if (wsum > hsum)
              break;
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T> using vv = vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int main() {
  while (1) {
    int n = 0, m = 0;
    int h[1550] = {}, w[1550] = {};
    int l[1500000] = {};
    cin >> n >> m;
    if (n == 0) {
      break;
    }
    int t = 0;
    FOR(i, 1, n + 1) {
      cin >> h[i];
      t += h[i];
      h[i] = t;
    }
    int s = 0;
    FOR(i, 1, m + 1) {
      cin >> w[i];
      s += w[i];
      w[i] = s;
    }
    sort(h, &h[n]);
    sort(w, &w[m]);
    ull sum = 0;
    rep(i, n) {
      FOR(j, i + 1, n + 1) { l[h[j] - h[i]] += 1; }
    }
    rep(i, m) {
      FOR(j, i + 1, m + 1) { sum += (ull)l[w[j] - w[i]]; }
    }
    cout << sum << endl;
  }
  return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

int num[2000 * 1500];

int main() {
  int N, M;
  while (cin >> N >> M && N != 0) {
    memset(num, 0, sizeof(num));
    int h[1501], w[1501];
    h[0] = w[0] = 0;

    for (int i = 1; i <= N; i++) {
      cin >> h[i];
      h[i] += h[i - 1];
    }

    for (int i = 1; i <= M; i++) {
      cin >> w[i];
      w[i] += w[i - 1];
    }

    for (int i = 0; i <= N; i++) {
      for (int j = i + 1; j <= N; j++) {
        num[h[i] - h[j]]++;
      }
    }

    int ans = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = i + 1; j <= M; j++) {
        ans += num[w[i] - w[j]];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

#include <iostream>
#include <string.h>
using namespace std;

int num[2000 * 1500];

int main() {
  int N, M;
  while (cin >> N >> M && N != 0) {
    memset(num, 0, sizeof(num));
    int h[1501], w[1501];
    h[0] = w[0] = 0;

    for (int i = 1; i <= N; i++) {
      cin >> h[i];
      h[i] += h[i - 1];
    }

    for (int i = 1; i <= M; i++) {
      cin >> w[i];
      w[i] += w[i - 1];
    }

    for (int i = 0; i <= N; i++) {
      for (int j = i + 1; j <= N; j++) {
        num[h[j] - h[i]]++;
      }
    }

    int ans = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = i + 1; j <= M; j++) {
        ans += num[w[j] - w[i]];
      }
    }
    cout << ans << endl;
  }
  return 0;
}


#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M, !(N == 0 && M == 0)) {
    long long h[N + 1], w[M + 1];
    h[0] = 0;
    w[0] = 0;
    for (int i = 1; i <= N; i++) {
      int k;
      cin >> k;
      h[i] = (h[i - 1] + k);
    }
    for (int i = 1; i <= M; i++) {
      int l;
      cin >> l;
      w[i] = (w[i - 1] + l);
    }
    long long H[(N + 1) * (N + 1)], W[(M + 1) * (M + 1)];
    int p = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j <= N; j++) {
        if (h[i] < h[j]) {
          H[p] = h[j] - h[i];
          p++;
        }
      }
    }
    sort(H, H + p);
    int q = 0;
    for (int i = 0; i < M; i++) {
      for (int j = i + 1; j <= M; j++) {
        if (w[i] < w[j]) {
          W[q] = w[j] - w[i];
          q++;
        }
      }
    }
    sort(W, W + q);
    long long ans = 0;
    int flag = 0;
    for (int i = 0; i < p; i++) {
      for (int j = flag; W[j] <= H[i] && j < q; j++) {
        if (W[j] == H[i]) {
          ans++;
        }
        if (W[j] < H[i]) {
          flag++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M, !(N == 0 && M == 0)) {
    long long h[N + 1], w[M + 1];
    h[0] = 0;
    w[0] = 0;
    for (int i = 1; i <= N; i++) {
      int k;
      cin >> k;
      h[i] = (h[i - 1] + k);
    }
    for (int i = 1; i <= M; i++) {
      int l;
      cin >> l;
      w[i] = (w[i - 1] + l);
    }
    vector<long long> H((N + 1) * (N + 1)), W((M + 1) * (M + 1));
    for (int i = 0; i < H.size(); i++) {
      H[i] = 1000000007;
    }
    for (int i = 0; i < W.size(); i++) {
      W[i] = 1000000007;
    }
    int p = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j <= N; j++) {
        if (h[i] < h[j]) {
          H[p] = h[j] - h[i];
          //      cout << H[p]<<endl;
          p++;
        }
      }
    }
    // cout << "^^^^";
    sort(H.begin(), H.end());
    int q = 0;
    for (int i = 0; i < M; i++) {
      for (int j = i + 1; j <= M; j++) {
        if (w[i] < w[j]) {
          W[q] = w[j] - w[i];
          //   cout << W[q]<<endl;
          q++;
        }
      }
    }
    // cout << "----";
    sort(W.begin(), W.end());
    for (int i = 0; i < N; i++) {
      // cout << W[i]<<",";
    }
    // cout <<endl;
    for (int i = 0; i < M; i++) {
      // cout << H[i];
    }
    // cout <<endl;
    long long ans = 0;
    int flag = 0;
    for (int i = 0; i < p; i++) {
      for (int j = flag; W[j] <= H[i] && j < q; j++) {
        if (W[j] == H[i]) {
          ans++;
        }
        if (W[j] < H[i]) {
          flag++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}
int h[1500 + 1], w[1500 + 1];
signed main() {
  bool flag = false;
  while (true) {
    int N = read(), M = read();
    if (N == 0 && M == 0)
      break;
    if (flag)
      cout << endl;
    flag = true;
    int cntH[1000 * 1500 + 1], cntW[1000 * 1500 + 1];
    int maxh = 0, maxw = 0;
    REP(i, N) {
      h[i] = read();
      maxh += h[i];
    }
    REP(i, M) {
      w[i] = read();
      maxw += w[i];
    }

    int MIN = min(maxh, maxw);

    REP(i, MIN + 1) {
      cntH[i] = 0;
      cntW[i] = 0;
    }

    int length;
    REP(i, N) {
      length = 0;
      FOR(j, i, N) {
        length += h[j];
        cntH[length]++;
      }
    }

    REP(i, M) {
      length = 0;
      FOR(j, i, M) {
        length += w[j];
        cntW[length]++;
      }
    }
    int ans = 0;
    FOR(i, 1, MIN + 1) ans += cntH[i] * cntW[i];

    cout << ans;
  }
}

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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}
int h[1500 + 1], w[1500 + 1];
signed main() {
  bool flag = false;
  while (true) {
    int N = read(), M = read();
    if (N == 0 && M == 0)
      break;
    int maxh = 0, maxw = 0;
    REP(i, N) {
      h[i] = read();
      maxh += h[i];
    }
    REP(i, M) {
      w[i] = read();
      maxw += w[i];
    }

    int MIN = min(maxh, maxw);

    int cntH[maxh + 1], cntW[maxw + 1];

    REP(i, MIN + 1) {
      cntH[i] = 0;
      cntW[i] = 0;
    }

    int length;
    REP(i, N) {
      length = 0;
      FOR(j, i, N) {
        length += h[j];
        cntH[length]++;
      }
    }

    REP(i, M) {
      length = 0;
      FOR(j, i, M) {
        length += w[j];
        cntW[length]++;
      }
    }
    int ans = 0;
    FOR(i, 1, MIN + 1) ans += cntH[i] * cntW[i];

    cout << ans << endl;
  }
}


// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1167
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

#define MAX 1000000
int const MOD = 1e9 + 7;
int main(void) {
  int N, M;
  while (cin >> N >> M, N || M) {
    vector<int> h(N), w(M);
    for (int i = 0; i < N; ++i)
      cin >> h[i];
    for (int i = 0; i < M; ++i)
      cin >> w[i];

    int sh[1510] = {0}, sw[1510] = {0};
    for (int i = 0; i < N; ++i) {
      sh[i + 1] = sh[i] + h[i];
    }
    for (int i = 0; i < M; ++i) {
      sw[i + 1] = sw[i] + w[i];
    }
    map<int, int> nh, nw;
    for (int i = 0; i < N + 1; ++i) {
      for (int j = 0; j < i; ++j) {
        nh[sh[i] - sh[j]]++;
      }
    }
    for (int i = 0; i < M + 1; ++i) {
      for (int j = 0; j < i; ++j) {
        nw[sw[i] - sw[j]]++;
      }
    }
    ll sum = 0;
    for (int i = 1; i <= 1500 * 1000; ++i) {
      sum += nh[i] * nw[i];
    }
    cout << sum << endl;
  }
  return 0;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1167
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

#define MAX 1000000
int const MOD = 1e9 + 7;
int main(void) {
  int N, M;
  while (cin >> N >> M, N || M) {
    vector<int> h(N), w(M);
    for (int i = 0; i < N; ++i)
      cin >> h[i];
    for (int i = 0; i < M; ++i)
      cin >> w[i];

    int sh[1510] = {0}, sw[1510] = {0};
    for (int i = 0; i < N; ++i) {
      sh[i + 1] = sh[i] + h[i];
    }
    for (int i = 0; i < M; ++i) {
      sw[i + 1] = sw[i] + w[i];
    }
    map<ll, int> nh, nw;
    for (int i = 0; i < N + 1; ++i) {
      for (int j = 0; j < i; ++j) {
        nh[sh[i] - sh[j]]++;
      }
    }
    for (int i = 0; i < M + 1; ++i) {
      for (int j = 0; j < i; ++j) {
        nw[sw[i] - sw[j]]++;
      }
    }
    ll sum = 0;
    for (auto itr = nh.begin(); itr != nh.end(); ++itr) {
      sum += (*itr).second * nw[(*itr).first];
    }
    cout << sum << endl;
  }
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    int h[1510];
    int w[1510];
    for (int i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (int j = 0; j < m; j++) {
      cin >> w[j];
    }
    int sq = 0;
    vector<vector<int>> dp(n, vector<int>(n, 0));
    vector<vector<int>> dp2(m, vector<int>(m, 0));
    dp[0][0] = h[0];
    dp2[0][0] = w[0];
    for (int i = 1; i < n; i++) {
      dp[0][i] = dp[0][i - 1] + h[i];
    }
    for (int i = 1; i < n; i++) {
      for (int j = i; j < n; j++) {
        dp[i][j] = dp[i][j - 1] + h[j];
      }
    }
    for (int i = 1; i < m; i++) {
      dp2[0][i] = dp2[0][i - 1] + w[i];
    }
    for (int i = 1; i < m; i++) {
      for (int j = i; j < m; j++) {
        dp2[i][j] = dp2[i][j - 1] + w[j];
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        for (int k = 0; k < m; k++) {
          for (int l = k; l < m; l++) {
            if (dp[i][j] == dp2[k][l]) {
              sq++;
            }
          }
        }
      }
    }
    cout << sq << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
  long long int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    vector<long long int> nn(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      cin >> nn[i];
    }

    for (long long int i = 1; i <= n; i++) {
      nn[i] += nn[i - 1];
    }
    set<long long int> stn;
    map<long long int, long long int> mpn;
    for (long long int i = 0; i <= n; i++) {
      for (long long int j = i + 1; j <= n; j++) {
        stn.insert(nn[j] - nn[i]);
        mpn[nn[j] - nn[i]]++;
      }
    }
    nn.clear();
    // cout << ' ' << stn.size() << endl;
    vector<long long int> mm(m + 1, 0);
    for (long long int i = 1; i <= m; i++) {
      cin >> mm[i];
    }
    for (long long int i = 1; i <= m; i++) {
      mm[i] += mm[i - 1];
    }
    set<long long int> stm;
    map<long long int, long long int> mpm;
    for (long long int i = 0; i <= m; i++) {
      for (long long int j = i + 1; j <= m; j++) {
        stm.insert(mm[j] - mm[i]);
        mpm[mm[j] - mm[i]]++;
      }
    }
    mm.clear();
    long long int ans = 0;
    vector<long long int> vm;
    for (set<long long int>::iterator ite = stm.begin(); ite != stm.end();
         ite++) {
      vm.push_back(*(ite));
    }
    for (set<long long int>::iterator ite = stn.begin(); ite != stn.end();
         ite++) {
      vector<long long int>::iterator ite2 =
          lower_bound(vm.begin(), vm.end(), *(ite));
      // cout << *(ite) << ' ' << *(ite2) << endl;
      if (ite2 != vm.end() && *(ite) == *(ite2)) {
        ans += mpn[*(ite)] * mpm[*(ite2)];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
  long long int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    vector<long long int> nn(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      cin >> nn[i];
    }

    for (long long int i = 1; i <= n; i++) {
      nn[i] += nn[i - 1];
    }
    set<long long int> stn;
    map<long long int, long long int> mpn;
    for (long long int i = 0; i <= n; i++) {
      for (long long int j = i + 1; j <= n; j++) {
        stn.insert(nn[j] - nn[i]);
        mpn[nn[j] - nn[i]]++;
      }
    }
    nn.clear();
    // cout << ' ' << stn.size() << endl;
    vector<long long int> mm(m + 1, 0);
    for (long long int i = 1; i <= m; i++) {
      cin >> mm[i];
    }
    for (long long int i = 1; i <= m; i++) {
      mm[i] += mm[i - 1];
    }
    vector<long long int> vm;
    map<long long int, long long int> mpm;
    for (long long int i = 0; i <= m; i++) {
      for (long long int j = i + 1; j <= m; j++) {
        vm.push_back(mm[j] - mm[i]);
        mpm[mm[j] - mm[i]]++;
      }
    }
    sort(vm.begin(), vm.end());
    mm.clear();
    long long int ans = 0;
    for (set<long long int>::iterator ite = stn.begin(); ite != stn.end();
         ite++) {
      vector<long long int>::iterator ite2 =
          lower_bound(vm.begin(), vm.end(), *(ite));
      // cout << *(ite) << ' ' << *(ite2) << endl;
      if (ite2 != vm.end() && *(ite) == *(ite2)) {
        ans += mpn[*(ite)] * mpm[*(ite2)];
      }
    }
    cout << ans << endl;
  }
  return 0;
}


// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2015

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list)                                                             \\
  cout << "{ ";                                                                \\
  for (auto nth : list) {                                                      \\
    cout << nth << " ";                                                        \\
  }                                                                            \\
  cout << "}" << endl;

using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M && N) {
    vector<int> h(N);
    vector<int> w(M);

    rep(i, N) { cin >> h[i]; }

    rep(i, M) { cin >> w[i]; }

    vector<int> vertical;
    rep(i, h.size()) {
      int tmp = 0;
      REP(j, i, h.size()) {
        tmp += h[j];
        vertical.push_back(tmp);
      }
    }

    vector<int> horizontal;
    rep(i, w.size()) {
      int tmp = 0;
      REP(j, i, w.size()) {
        tmp += w[j];
        horizontal.push_back(tmp);
      }
    }

    int ans = 0;
    rep(i, vertical.size()) {
      rep(j, horizontal.size()) {
        if (vertical[i] == horizontal[j]) {
          ans++;
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2015

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list)                                                             \\
  cout << "{ ";                                                                \\
  for (auto nth : list) {                                                      \\
    cout << nth << " ";                                                        \\
  }                                                                            \\
  cout << "}" << endl;

using namespace std;

const int MAX = 1500001;

int main() {
  int N, M;
  while (cin >> N >> M && N) {
    vector<int> h(N);
    vector<int> w(M);

    rep(i, N) { cin >> h[i]; }

    rep(i, M) { cin >> w[i]; }

    vector<int> vertical(MAX, 0);
    rep(i, h.size()) {
      int tmp = 0;
      REP(j, i, h.size()) {
        tmp += h[j];
        vertical[tmp]++;
      }
    }

    vector<int> horizontal(MAX, 0);
    rep(i, w.size()) {
      int tmp = 0;
      REP(j, i, w.size()) {
        tmp += w[j];
        horizontal[tmp]++;
      }
    }

    int ans = 0;
    rep(i, MAX) { ans += vertical[i] * horizontal[i]; }

    cout << ans << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9 : 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
  return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
  auto inner = vectors(tail...);
  return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T a) {
  int b = 0;
  for (auto itr : a) {
    if (b++ != 0)
      cout << " ";
    cout << itr;
  }
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
#define int ll
signed main() {
  int a, b;
  while (cin >> a >> b, a + b) {
    vector<int> h, w;
    h.push_back(1);
    w.push_back(1);
    map<int, int> v, u;
    rep(i, a) {
      int t;
      cin >> t;
      int temp = h.back();
      h.push_back(temp + t);
      v[temp + t] = 1;
    }
    v[1] = u[1] = 0;
    rep(i, b) {
      int t;
      cin >> t;
      int temp = w.back();
      w.push_back(temp + t);
      u[temp + t] = 1;
    }
    int ans = 0;
    for (int i = 0; i < h.size(); i++) {
      for (int j = i + 1; j < h.size(); j++) {
        for (int k = 0; k < w.size(); k++) {
          if (h[j] - h[i] + w[k] <= w.back() and u[h[j] - h[i] + w[k]] == 1)
            ans++;
        }
      }
    }
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9 : 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
  return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
  auto inner = vectors(tail...);
  return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T a) {
  int b = 0;
  for (auto itr : a) {
    if (b++ != 0)
      cout << " ";
    cout << itr;
  }
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
#define int ll
signed main() {
  int a, b;
  while (cin >> a >> b, a + b) {
    vector<int> h, w;
    h.push_back(1);
    w.push_back(1);
    map<int, int> v, u;
    rep(i, a) {
      int t;
      cin >> t;
      int temp = h.back();
      h.push_back(temp + t);
      v[temp + t] = 1;
    }
    v[1] = u[1] = 0;
    rep(i, b) {
      int t;
      cin >> t;
      int temp = w.back();
      w.push_back(temp + t);
      u[temp + t] = 1;
    }
    map<int, int> mp;
    for (int i = 0; i < w.size(); i++) {
      for (int j = i + 1; j < w.size(); j++) {
        mp[w[j] - w[i]]++;
      }
    }
    int ans = 0;
    for (int i = 0; i < h.size(); i++) {
      for (int j = i + 1; j < h.size(); j++) {
        ans += mp[h[j] - h[i]];
      }
    }
    cout << ans << endl;
  }
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

bool check(int &y1, int w, vector<int> &H) {
  int l = y1 + 1, r = (int)(H.size());
  while (r - l > 1) {
    int y2 = (l + r) / 2, res = H[y2] - H[y1];
    if (res == w)
      return true;
    else if (res > w)
      r = y2;
    else
      l = y2;
  }
  if (l >= 0 && l < (int)H.size() && w == H[l] - H[y1])
    return true;
  if (r >= 0 && r < (int)H.size() && w == H[r] - H[y1])
    return true;
  return false;
}

int main() {
  int N, M;
  while (scanf("%d %d", &N, &M) && N) {
    vector<int> H(N + 1, 0), W(M + 1, 0);
    REP(i, N) {
      scanf("%d", &H[i + 1]);
      H[i + 1] += H[i];
    }
    REP(i, M) {
      scanf("%d", &W[i + 1]);
      W[i + 1] += W[i];
    }
    ++N;
    ++M;
    int ans = 0;
    REP(y, N)
    REP(x1, M) FOR(x2, x1 + 1, M) if (check(y, W[x2] - W[x1], H))++ ans;
    printf("%d\\n", ans);
  }
  return 0;
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int N, M;
  while (scanf("%d %d", &N, &M) && N) {
    vector<int> _H(N + 1, 0), _W(M + 1, 0);
    REP(i, N) {
      scanf("%d", &_H[i + 1]);
      _H[i + 1] += _H[i];
    }
    REP(i, M) {
      scanf("%d", &_W[i + 1]);
      _W[i + 1] += _W[i];
    }
    ++N;
    ++M;
    vector<int> H, W;
    REP(i, N) FOR(j, i + 1, N) H.push_back(_H[j] - _H[i]);
    REP(i, M) FOR(j, i + 1, M) W.push_back(_W[j] - _W[i]);
    SORT(H);
    SORT(W);
    int ans = 0;
    REP(i, H.size())
    ans += upper_bound(W.begin(), W.end(), H[i]) -
           lower_bound(W.begin(), W.end(), H[i]);
    printf("%d\\n", ans);
  }
  return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y)                                                            \\
  (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z)                                                         \\
  (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y  \\
        << ", " << z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int N, M;
vector<int> hh, ww;

int main(void) {
  while (cin >> N >> M, N | M) {
    hh = vector<int>(N + 1, 0);
    ww = vector<int>(M + 1, 0);

    REPI(i, 1, N) {
      cin >> hh[i];
      hh[i] += hh[i - 1];
    }
    REPI(i, 1, M) {
      cin >> ww[i];
      ww[i] += ww[i - 1];
    }

    int cnt = 0;
    rep(i, hh.size()) REP(j, i + 1, hh.size()) rep(k, ww.size()) {
      int r = ww[k] + hh[j] - hh[i];
      if (binary_search(ww.begin() + k, ww.end(), r))
        cnt++;
    }
    cout << cnt << endl;
  }

  return 0;
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y)                                                            \\
  (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z)                                                         \\
  (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y  \\
        << ", " << z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int N, M;
vector<int> hh, ww;

#define MAX 1500001

int main(void) {
  while (cin >> N >> M, N | M) {
    hh = vector<int>(N + 1, 0);
    ww = vector<int>(M + 1, 0);

    REPI(i, 1, N) {
      cin >> hh[i];
      hh[i] += hh[i - 1];
    }
    REPI(i, 1, M) {
      cin >> ww[i];
      ww[i] += ww[i - 1];
    }

    int cnt = 0;
    int wd[MAX];

    memset(wd, 0, sizeof(wd));
    rep(i, ww.size()) REP(j, i + 1, ww.size()) wd[ww[j] - ww[i]]++;

    rep(i, hh.size()) REP(j, i + 1, hh.size()) cnt += wd[hh[j] - hh[i]];

    cout << cnt << endl;
  }

  return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define pb push_back
using namespace std;
int n, m;

int mitih[1500000], mitiw[1500000];

int main(void) {
  int i, j, x, tmp, res;
  vector<int> h, w;
  while (scanf("%d %d", &n, &m), n | m) {
    h.clear(), w.clear();
    for (i = 1; i <= n; i++) {
      cin >> x;
      h.pb(x);
    }
    for (i = 1; i <= m; i++) {
      cin >> x;
      w.pb(x);
    }
    // set<int> st1,st2;
    vector<int> s1, s2;
    for (i = 0; i < n; i++) {
      tmp = 0;
      for (j = i; j < n; j++) {
        tmp += h[j];
        // st1.insert(tmp);
        s1.pb(tmp);
      }
    }
    for (i = 0; i < m; i++) {
      tmp = 0;
      for (j = i; j < m; j++) {
        tmp += w[j];
        // st2.insert(tmp);
        s2.pb(tmp);
      }
    }
    // printf("3\\n");
    h.clear();
    w.clear();
    // for(auto itr=st1.begin();itr!=st1.end();++itr) h.pb(*itr);
    // for(auto itr=st2.begin();itr!=st2.end();++itr) w.pb(*itr);
    i = j = res = 0;

    sort(s1.begin(), s1.end());
    sort(s2.begin(), s2.end());
    // printf("5\\n");
    tmp = -1;
    /*
    for(i=0;i<7;i++){
      printf("%d %d\\n",s1[i],s2[i]);
    }
    */
    map<int, int> mp1, mp2;
    for (i = 0; i <= max(s1.size(), s2.size()); i++) {
      mp1[i] = mp2[i] = 0;
    }
    for (i = 0; i <= s1.size(); i++) {
      mp1[s1[i]]++;
    }
    for (i = 0; i <= s2.size(); i++) {
      mp2[s2[i]]++;
    }

    for (i = 1; i <= max(s1.size(), s2.size()); i++) {
      // printf("%d %d %d\\n",i,mp1[i],mp2[i]);
      res += mp1[i] * mp2[i];
    }

    printf("%d\\n", res);
  }
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define pb push_back
using namespace std;
int n, m;

int mitih[1500000], mitiw[1500000];

int main(void) {
  int i, j, x, tmp, res;
  vector<int> h, w;
  while (scanf("%d %d", &n, &m), n | m) {
    h.clear(), w.clear();
    for (i = 1; i <= n; i++) {
      cin >> x;
      h.pb(x);
    }
    for (i = 1; i <= m; i++) {
      cin >> x;
      w.pb(x);
    }
    // set<int> st1,st2;
    vector<int> s1, s2;
    for (i = 0; i < n; i++) {
      tmp = 0;
      for (j = i; j < n; j++) {
        tmp += h[j];
        s1.pb(tmp);
      }
    }
    for (i = 0; i < m; i++) {
      tmp = 0;
      for (j = i; j < m; j++) {
        tmp += w[j];
        s2.pb(tmp);
      }
    }
    h.clear();
    w.clear();
    // for(auto itr=st1.begin();itr!=st1.end();++itr) h.pb(*itr);
    // for(auto itr=st2.begin();itr!=st2.end();++itr) w.pb(*itr);
    i = j = res = 0;
    sort(s1.begin(), s1.end());
    sort(s2.begin(), s2.end());
    tmp = max(s1[s1.size() - 1], s2[s2.size() - 1]);
    /*
    for(i=0;i<s1.size();i++) printf("%d ",s1[i]);
    printf("\\n");
    for(i=0;i<s2.size();i++) printf("%d ",s2[i]);
    printf("\\n");
    */
    // printf("5\\n");

    map<int, int> mp1, mp2;
    // tmp=max(s1.size(),s2.size());
    for (i = 0; i < tmp; i++) {
      mp1[i] = mp2[i] = 0;
    }
    for (i = 0; i < s1.size(); i++)
      mp1[s1[i]]++;
    for (i = 0; i < s2.size(); i++)
      mp2[s2[i]]++;
    for (i = 0; i <= tmp; i++) {
      // printf("%d : %d %d\\n",i,mp1[i],mp2[i]);
      res += mp1[i] * mp2[i];
    }

    printf("%d\\n", res);
  }
  return 0;
}

/*
int solveninaritakattananika(){
  int i,j,k,n;
  int res=0;
  n=max(h[h.size()-1],w[w.size()-1]);
  for(k=1;k<=n;k++){
    for(i=0;i<h[h.size()-1]-k+1;i++){
      for(j=0;j<w[w.size()-1]-k+1;j++){
        if(mitih[i]==1&&mitih[i+k]==1&&mitiw[j]==1&&mitiw[j+k]==1) res++;
        //printf("%d %d %d %d : ",mitih[i],mitiw[j+k],mitih[i+k],mitiw[j]);
        //printf("(%d,%d) k=%d  res=%d\\n",i,j,k,res);
      }
    }
  }
  return res;
}
*/


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  vector<int> answer;
  while (cin >> N >> M && N != 0) {
    vector<int> h(N), w(M);
    vector<int> h_all, w_all;
    int square = 0;
    for (int i = 0; i < N; i++) {
      cin >> h.at(i);
      if (i != 0) {
        h.at(i) += h.at(i - 1);
      }
    }
    for (int i = 0; i < M; i++) {
      cin >> w.at(i);
      if (i != 0) {
        w.at(i) += w.at(i - 1);
      }
    }
    h_all.push_back(h.at(0));
    for (int i = 0; i < N - 1; i++) {
      for (int j = i; j < N; j++) {
        h_all.push_back(h.at(j) - h.at(i));
      }
    }
    w_all.push_back(w.at(0));
    for (int i = 0; i < M - 1; i++) {
      for (int j = i; j < M; j++) {
        w_all.push_back(w.at(j) - w.at(i));
      }
    }
    sort(h_all.begin(), h_all.end());
    sort(w_all.begin(), w_all.end());
    for (int i = 0; i < h_all.size(); i++) {
      for (int j = 0; j < w_all.size(); j++) {
        if (h_all.at(i) < w_all.at(j)) {
          break;
        }
        if (h_all.at(i) == w_all.at(j)) {
          square++;
        }
      }
    }
    answer.push_back(square);
  }
  for (int i = 0; i < answer.size(); i++) {
    cout << answer.at(i) << endl;
  }
  return 0;
}

#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int N, M;
  vector<int> answer;
  while (cin >> N >> M && N != 0) {
    vector<int> h(N + 1, 0), w(M + 1, 0);
    int square = 0;
    map<int, int> length;
    for (int i = 0; i < N; i++) {
      cin >> h.at(i + 1);
      h.at(i + 1) += h.at(i);
    }
    for (int i = 0; i < M; i++) {
      cin >> w.at(i + 1);
      w.at(i + 1) += w.at(i);
    }
    for (int i = 0; i < N + 1; i++) {
      for (int j = 0; j < M + 1; j++) {
        length[h.at(i) - w.at(j)]++;
      }
    }
    for (auto x = length.begin(); x != length.end(); x++) {
      // cout << x->first << " " << x->second << endl;
      square += (x->second * (x->second - 1)) / 2;
    }
    answer.push_back(square);
  }
  for (int i = 0; i < answer.size(); i++) {
    cout << answer.at(i) << endl;
  }
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define vec vector

int main(void) {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    vec<int> h(n + 1), w(m + 1);
    h[0] = 0;
    w[0] = 0;
    rep(i, n) {
      int l;
      cin >> l;
      h[i + 1] = h[i] + l;
    }
    rep(i, m) {
      int l;
      cin >> l;
      w[i + 1] = w[i] + l;
    }

    vec<int> x(1001, 0);
    vec<int> y(1001, 0);
    rep(i, n) {
      for (int j = i + 1; j <= n; j++) {
        x[h[j] - h[i]]++;
      }
    }
    rep(i, m) {
      for (int j = i + 1; j <= m; j++) {
        y[w[j] - w[i]]++;
      }
    }
    int ans = 0;
    rep(i, 1000) { ans += x[i + 1] * y[i + 1]; }
    cout << ans << endl;
  }
  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define vec vector

int main(void) {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    vec<int> h(n + 1), w(m + 1);
    h[0] = 0;
    w[0] = 0;
    rep(i, n) {
      int l;
      cin >> l;
      h[i + 1] = h[i] + l;
    }
    rep(i, m) {
      int l;
      cin >> l;
      w[i + 1] = w[i] + l;
    }

    int K = 1500 * 1000;
    vec<int> x(K + 1, 0);
    vec<int> y(K + 1, 0);
    rep(i, n) {
      for (int j = i + 1; j <= n; j++) {
        x[h[j] - h[i]]++;
      }
    }
    rep(i, m) {
      for (int j = i + 1; j <= m; j++) {
        y[w[j] - w[i]]++;
      }
    }
    int ans = 0;
    rep(i, K) { ans += x[i + 1] * y[i + 1]; }
    cout << ans << endl;
  }
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

int N, M;
int h[2048];
int w[2048];

void load() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < (int)N; ++i) {
    scanf("%d", &h[i]);
  }
  for (int i = 0; i < (int)M; ++i) {
    scanf("%d", &w[i]);
  }
}

class Solve_ {
public:
  long operator()() {
    init();
    sub_h();
    sub_w();
    for (int i = 0; i <= N; ++i) {
      for (int j = i + 1; j <= N; ++j) {
        counth[sumh[j] - sumh[i]] += 1;
      }
    }
    for (int i = 0; i <= M; ++i) {
      for (int j = i + 1; j <= M; ++j) {
        countw[sumw[j] - sumw[i]] += 1;
      }
    }
    long res = 0;
    for (int i = 1; i < 2048; ++i) {
      res += counth[i] * countw[i];
    }
    return res;
  }
  void init() {
    for (long &I : countw)
      I = 0;
    for (long &I : counth)
      I = 0;
  }
  void sub_h() {
    sumh[0] = 0;
    for (int i = 0; i < N; ++i) {
      sumh[i + 1] = h[i];
    }
    long t = 0;
    for (int i = 0; i <= N; ++i) {
      t += sumh[i];
      sumh[i] = t;
    }
  }
  void sub_w() {
    sumw[0] = 0;
    for (int i = 0; i < M; ++i) {
      sumw[i + 1] = w[i];
    }
    long t = 0;
    for (int i = 0; i <= M; ++i) {
      t += sumw[i];
      sumw[i] = t;
    }
  }

private:
  long countw[2048];
  long counth[2048];
  long sumw[2048];
  long sumh[2048];
};
Solve_ Solve;

int main() {
  for (;;) {
    load();
    if (N == 0 and M == 0)
      break;
    long res = Solve();
    printf("%ld\\n", res);
  }

  return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

int N, M;
int h[2048];
int w[2048];

void load() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < (int)N; ++i) {
    scanf("%d", &h[i]);
  }
  for (int i = 0; i < (int)M; ++i) {
    scanf("%d", &w[i]);
  }
}

class Solve_ {
public:
  long operator()() {
    init();
    sub_h();
    sub_w();
    for (int i = 0; i <= N; ++i) {
      for (int j = i + 1; j <= N; ++j) {
        counth[sumh[j] - sumh[i]] += 1;
      }
    }
    for (int i = 0; i <= M; ++i) {
      for (int j = i + 1; j <= M; ++j) {
        countw[sumw[j] - sumw[i]] += 1;
      }
    }
    long res = 0;
    for (int i = 1; i < 2048 * 1024; ++i) {
      res += counth[i] * countw[i];
    }
    return res;
  }
  void init() {
    for (long &I : countw)
      I = 0;
    for (long &I : counth)
      I = 0;
  }
  void sub_h() {
    sumh[0] = 0;
    for (int i = 0; i < N; ++i) {
      sumh[i + 1] = h[i];
    }
    long t = 0;
    for (int i = 0; i <= N; ++i) {
      t += sumh[i];
      sumh[i] = t;
    }
  }
  void sub_w() {
    sumw[0] = 0;
    for (int i = 0; i < M; ++i) {
      sumw[i + 1] = w[i];
    }
    long t = 0;
    for (int i = 0; i <= M; ++i) {
      t += sumw[i];
      sumw[i] = t;
    }
  }

private:
  long countw[2048 * 1024];
  long counth[2048 * 1024];
  long sumw[2048];
  long sumh[2048];
};
Solve_ Solve;

int main() {
  for (;;) {
    load();
    if (N == 0 and M == 0)
      break;
    long res = Solve();
    printf("%ld\\n", res);
  }

  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF INT_MAX / 3
#define LINF LLONG_MAX / 3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cout << #x << ":" << x << endl
#define debug2(x, y) cout << #x << "," << #y ":" << x << "," << y << endl
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void solve(int N, int M) {
  vector<int> h(N), w(M);
  rep(i, N) cin >> h[i];
  rep(i, M) cin >> w[i];

  map<int, int> hh, ww;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = i + 1; j <= N; j++) {
      sum += h[j - 1];
      hh[sum]++;
    }
  }

  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = i + 1; j <= M; j++) {
      sum += w[j - 1];
      ww[sum]++;
    }
  }

  //    cout << "hh" << endl;
  //    for(auto x:hh){
  //        debug2(x.first,x.second);
  //    }
  //
  //    cout << "ww" << endl;
  //    for(auto y:ww){
  //        debug2(y.first,y.second);
  //    }

  ll ans = 0;
  for (auto x : hh)
    for (auto y : ww) {
      if (x.first == y.first) {
        ans += (ll)x.second * (ll)y.second;
      }
    }

  cout << ans << endl;
}

int main() {
  int N, M;
  while (cin >> N >> M) {
    if (N == 0 and M == 0)
      break;
    solve(N, M);
  }
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF INT_MAX / 3
#define LINF LLONG_MAX / 3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cout << #x << ":" << x << endl
#define debug2(x, y) cout << #x << "," << #y ":" << x << "," << y << endl
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void solve(int N, int M) {
  vector<int> h(N), w(M);
  rep(i, N) cin >> h[i];
  rep(i, M) cin >> w[i];

  map<int, int> hh, ww;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = i + 1; j <= N; j++) {
      sum += h[j - 1];
      hh[sum]++;
    }
  }

  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = i + 1; j <= M; j++) {
      sum += w[j - 1];
      ww[sum]++;
    }
  }

  ll ans = 0;
  for (auto x : hh) {
    ans += (ll)x.second * ww[x.first];
  }
  cout << ans << endl;
}

int main() {
  int N, M;
  while (cin >> N >> M) {
    if (N == 0 and M == 0)
      break;
    solve(N, M);
  }
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pi 3.141592653589793

#define max 1500 * 1501 / 2

int solve(int n, int m, int h[], int w[]) {
  vector<long long int> wsize, hsize;
  long long int size = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; i + j < n + 2; j++) {
      size = 0;
      for (int k = 0; k < i; k++) {
        size += w[j + k];
      }
      wsize.push_back(size);
    }
  }
  // i : 何マスか j: 最初のマス目
  sort(wsize.begin(), wsize.end());
  for (int i = 1; i < m + 1; i++) {
    for (int j = 1; i + j < m + 2; j++) {
      size = 0;
      for (int k = 0; k < i; k++) {
        size += w[j + k];
      }
      hsize.push_back(size);
    }
  }
  sort(hsize.begin(), hsize.end());
  int cnt = 0;
  for (int i = 0; i < hsize.size(); i++) {
    for (int j = 0; j < wsize.size(); j++) {
      if (hsize[i] == wsize[j]) {
        cnt++;
        break;
      } else if (wsize[j] > hsize[i])
        break;
    }
  }
  return cnt;
}

int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int h[1501] = {}, w[1501] = {};
    for (int i = 1; i < n + 1; i++) {
      cin >> h[i];
    }
    for (int i = 1; i < m + 1; i++) {
      cin >> w[i];
    }
    int ans = solve(n, m, h, w);
    cout << ans << endl;
  }
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int h[1500], w[1500];
    int sumh = 0, sumw = 0;
    for (int i = 0; i < n; i++) {
      cin >> h[i];
      sumh += h[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> w[i];
      sumw += w[i];
    }
    int resulth[sumh + 1], resultw[sumw + 1];
    for (int i = 0; i < sumh + 1; i++) {
      resulth[i] = 0;
    }
    for (int i = 0; i < sumw + 1; i++) {
      resultw[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int tmp = 0;
      for (int j = i; j < n; j++) {
        tmp += h[j];
        resulth[tmp]++;
      }
    }
    for (int i = 0; i < m; i++) {
      int tmp = 0;
      for (int j = i; j < m; j++) {
        tmp += w[j];
        resultw[tmp]++;
      }
    }
    int ans = 0;
    for (int i = 1; i < min(sumh, sumw) + 1; i++) {
      ans += resultw[i] * resulth[i];
    }
    cout << ans << endl;
  }
  return 0;
}


// 2017-02-04
#include <iostream>
using namespace std;

int main() {
  int n, m, h[1500 + 1], w[1500 + 1];
  while (cin >> n >> m, n) {
    for (int i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> w[i];
    }
    h[n] = 0;
    w[m] = 0;
    int c = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int k = i;
        int l = j;
        int u = h[i];
        int v = w[j];
        while (k < n && l < m) {
          if (u < v) {
            k++;
            u += h[k];
          } else if (u > v) {
            l++;
            v += w[l];
          } else {
            c++;
            k++;
            u += h[k];
          }
        }
      }
    }
    cout << c << endl;
  }
  return 0;
}


#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(v, c) for (auto &v : c)

#define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end()

#define PB(n) push_back(n)
#define MP(a, b) make_pair((a), (b))
#define EXIST(c, e) ((c).find(e) != (c).end())

#define fst first
#define snd second

#define DUMP(x) cerr << #x << " = " << (x) << endl
#define DEBUG(x)                                                               \\
  cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    int h, w;
    cin >> h >> w;

    if (!(h | w)) {
      break;
    }

    VI hs(h), ws(w);
    FOR(a, hs) { cin >> a; }
    FOR(a, ws) { cin >> a; }

    multiset<int> widths;
    {
      VI csum(1, 0);
      partial_sum(ALL(ws), back_inserter(csum));

      REP(i, 0, w) {
        REP(j, i + 1, w + 1) { widths.insert(csum[j] - csum[i]); }
      }
    }

    VI csum(1, 0);
    partial_sum(ALL(hs), back_inserter(csum));

    int res = 0;
    REP(i, 0, h) {
      REP(j, i + 1, h + 1) { res += widths.count(csum[j] - csum[i]); }
    }

    cout << res << endl;
  }

  return 0;
}

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(v, c) for (auto &v : c)

#define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end()

#define PB(n) push_back(n)
#define MP(a, b) make_pair((a), (b))
#define EXIST(c, e) ((c).find(e) != (c).end())

#define fst first
#define snd second

#define DUMP(x) cerr << #x << " = " << (x) << endl
#define DEBUG(x)                                                               \\
  cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    int h, w;
    cin >> h >> w;

    if (!(h | w)) {
      break;
    }

    VI hs(h), ws(w);
    FOR(a, hs) { cin >> a; }
    FOR(a, ws) { cin >> a; }

    VI widths;
    {
      VI csum(1, 0);
      partial_sum(ALL(ws), back_inserter(csum));

      REP(i, 0, w) {
        REP(j, i + 1, w + 1) { widths.PB(csum[j] - csum[i]); }
      }
    }
    sort(ALL(widths));

    VI csum(1, 0);
    partial_sum(ALL(hs), back_inserter(csum));

    int res = 0;
    REP(i, 0, h) {
      REP(j, i + 1, h + 1) {
        auto pos = equal_range(ALL(widths), csum[j] - csum[i]);
        res += distance(pos.fst, pos.snd);
      }
    }

    cout << res << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M && N) {
    vector<int> h(N + 1), w(M + 1);
    h[0] = 0, w[0] = 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];
    vector<int> hs(h.back() + 1, 0), ws(w.back() + 1, 0);
    rep(i, N) REP(j, i + 1, N + 1) hs[h[j] - h[i]]++;
    rep(i, M) REP(j, i + 1, M + 1) ws[w[j] - w[i]]++;
    int ans = 0;
    rep(i, max(h.back(), w.back()) + 1) ans += hs[i] * ws[i];
    cout << ans << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M && N) {
    vector<int> h(N + 1), w(M + 1);
    h[0] = 0, w[0] = 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];
    vector<int> hs(h.back() + 1, 0), ws(w.back() + 1, 0);
    rep(i, N) REP(j, i + 1, N + 1) hs[h[j] - h[i]]++;
    rep(i, M) REP(j, i + 1, M + 1) ws[w[j] - w[i]]++;
    int ans = 0;
    rep(i, min(h.back(), w.back()) + 1) ans += hs[i] * ws[i];
    cout << ans << endl;
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int i = (s); i <= (e); i++)

int n;
int m;

int hmp[1500 * 1000 + 1];
int wmp[1500 * 1000 + 1];

int main() {
  while (cin >> n >> m, n) {
    fill(hmp, hmp + 1 + 1500 * 1000, 0);
    fill(wmp, wmp + 1 + 1500 * 1000, 0);

    vector<int> h(n + 1, 0), w(n + 1, 0);

    for (int i = 1; i <= n; i++) {
      cin >> h[i];
      h[i] += h[i - 1];
    }
    for (int i = 1; i <= m; i++) {
      cin >> w[i];
      w[i] += w[i - 1];
    }

    for (int i = 0; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        int len = h[j] - h[i];
        hmp[len]++;
      }
    }
    for (int i = 0; i <= m; i++) {
      for (int j = i + 1; j <= m; j++) {
        int len = w[j] - w[i];
        wmp[len]++;
      }
    }

    i64 result = 0;

    for (int i = 1; i <= 1500 * 1000; i++) {
      result += hmp[i] * wmp[i];
    }
    cout << result << endl;
  }
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int i = (s); i <= (e); i++)

int n;
int m;

int hmp[1500 * 1000 + 1];
int wmp[1500 * 1000 + 1];

int main() {
  while (cin >> n >> m, n) {
    fill(hmp, hmp + 1 + 1500 * 1000, 0);
    fill(wmp, wmp + 1 + 1500 * 1000, 0);

    vector<int> h(n + 1, 0), w(m + 1, 0);

    for (int i = 1; i <= n; i++) {
      cin >> h[i];
      h[i] += h[i - 1];
    }
    for (int i = 1; i <= m; i++) {
      cin >> w[i];
      w[i] += w[i - 1];
    }

    for (int i = 0; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        int len = h[j] - h[i];
        hmp[len]++;
      }
    }
    for (int i = 0; i <= m; i++) {
      for (int j = i + 1; j <= m; j++) {
        int len = w[j] - w[i];
        wmp[len]++;
      }
    }

    i64 result = 0;

    for (int i = 1; i <= 1500 * 1000; i++) {
      result += hmp[i] * wmp[i];
    }
    cout << result << endl;
  }
}


#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n, m, i, j;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int h[1501] = {}, w[1501] = {};
    for (i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (i = 0; i < m; i++) {
      cin >> w[i];
    }

    int cnt = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m;) {
        if (h[i] == w[j])
          cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m, i, j, cnt, hsum, wsum, tmp, cnti, cntj;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int h[1502], w[1502];
    vector<int> sh, sw;
    hsum = wsum = 0;
    h[0] = 0;
    for (i = 1; i <= n; i++) {
      cin >> tmp;
      hsum += tmp;
      h[i] = hsum;
    }
    w[0] = 0;
    for (i = 1; i <= m; i++) {
      cin >> tmp;
      wsum += tmp;
      w[i] = wsum;
    }

    for (i = 0; i <= n - 1; i++) {
      for (j = i + 1; j <= n; j++) {
        sh.push_back(h[j] - h[i]);
      }
    }
    for (i = 0; i <= m - 1; i++) {
      for (j = i + 1; j <= m; j++) {
        sw.push_back(w[j] - w[i]);
      }
    }

    sort(sh.begin(), sh.end());
    sort(sw.begin(), sw.end());

    i = j = 0;
    cnt = 0;
    int maxi = sh.size(), maxj = sw.size();
    while (i < maxi && j < maxj) {
      if (sh[i] == sw[j]) {
        cnti = cntj = 1;
        while (i < maxi - 1 && sh[i] == sh[i + 1]) {
          cnti++;
          i++;
        }
        while (j < maxj - 1 && sw[j] == sw[j + 1]) {
          cntj++;
          j++;
        }
        cnt += cnti * cntj;
        i++;
        j++;
      } else if (sh[i] < sw[j]) {
        i++;
      } else {
        j++;
      }
    }

    cout << cnt << endl;
  }

  return 0;
}


////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

//// MACRO ////
#define countof(a) (sizeof(a) / sizeof(a[0]))

#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define pos(c, i) c.being() + (i)
#define allof(c) c.begin(), c.end()
#define aallof(a) a, countof(a)
#define partof(c, i, n) c.begin() + (i), c.begin() + (i) + (n)
#define apartof(a, i, n) a + (i), a + (i) + (n)
#define long long long

#define EPS 1e-9
#define INF (1L << 30)
#define LINF (1LL << 60)

#define PREDICATE(t, a, exp) [&](const t &a) -> bool { return exp; }
#define COMPARISON_T(t) bool (*)(const t &, const t &)
#define COMPARISON(t, a, b, exp)                                               \\
  [&](const t &a, const t &b) -> bool { return exp; }
#define CONVERTER(TSrc, t, TDest, exp)                                         \\
  [&](const TSrc &t) -> TDest { return exp; }

inline int sign(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
inline bool inRange(double val, double min, double max) {
  return val - min > -EPS && val - max < EPS;
}

//// i/o helper ////

struct _Reader {
  template <class T> _Reader operator,(T &rhs) {
    cin >> rhs;
    return *this;
  }
};
struct _Writer {
  bool f;
  _Writer() : f(false) {}
  template <class T> _Writer operator,(const T &rhs) {
    cout << (f ? " " : "") << rhs;
    f = true;
    return *this;
  }
};
#define READ(t, ...)                                                           \\
  t __VA_ARGS__;                                                               \\
  _Reader(), __VA_ARGS__
#define WRITE(...)                                                             \\
  _Writer(), __VA_ARGS__;                                                      \\
  cout << endl

template <class T> struct vevector : public vector<vector<T>> {
  vevector(int n = 0, int m = 0, const T &initial = T())
      : vector<vector<T>>(n, vector<T>(m, initial)) {}
};
template <class T> struct vevevector : public vector<vevector<T>> {
  vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T())
      : vector<vevector<T>>(n, vevector<T>(m, l, initial)) {}
};
template <class T> struct vevevevector : public vector<vevevector<T>> {
  vevevevector(int n = 0, int m = 0, int l = 0, int k = 0,
               const T &initial = T())
      : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) {}
};
template <class T> T read() {
  T t;
  cin >> t;
  return t;
}
template <class T> vector<T> read(int n) {
  vector<T> v;
  REP(i, n) { v.push_back(read<T>()); }
  return v;
}
template <class T> vevector<T> read(int n, int m) {
  vevector<T> v;
  REP(i, n) v.push_back(read<T>(m));
  return v;
}
template <class T> vevector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) {
  vevector<T> v;
  REP(i, n) v.push_back(readjag<T>());
  return v;
}

template <class T1, class T2>
inline istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <class T1, class T2>
inline ostream &operator<<(ostream &out, pair<T1, T2> &p) {
  out << p.first << p.second;
  return out;
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &v) {
  ostringstream ss;
  for (auto x : v)
    ss << x << ' ';
  auto s = ss.str();
  out << s.substr(0, s.length() - 1) << endl;
  return out;
}

//// start up ////
void solve();
inline void readfrom(string filename) { freopen(filename.c_str(), "r", stdin); }
inline void writeto(string filename) { freopen(filename.c_str(), "w", stdout); }
int main() {
  solve();
  return 0;
}

////////////////////
/// template end ///
////////////////////

inline int setbit(int n) { return (1 << n) - 1; }
inline bool contains(int x, int min, int max) {
  return x >= min && x < max;
} // max含まない

void solve() {
  int testcases = INF;
  REP(testcase, testcases) {
    READ(int, N, M);
    if (!(N | M)) {
      break;
    }

    auto hs = read<int>(N);
    hs.insert(hs.begin(), 0);
    partial_sum(allof(hs), hs.begin());
    N++;
    auto ws = read<int>(M);
    ws.insert(ws.begin(), 0);
    partial_sum(allof(ws), ws.begin());
    M++;

    auto a = vector<int>();
    REP(i, N) FOR(j, i + 1, N) { a.push_back(hs[j] - hs[i]); }
    auto b = vector<int>();
    REP(i, M) FOR(j, i + 1, M) { b.push_back(ws[j] - ws[i]); }

    sort(allof(a));
    sort(allof(b));

    int i = 0, j = 0, r = 0;
    while (i < a.size() && j < b.size()) {
      int x = i;
      int y = j;
      if (a[i] == b[j]) {
        while (i < a.size() && a[i] == a[x])
          x++;
        while (j < b.size() && b[j] == b[y])
          y++;
        r += (i - x) * (j - y);
      } else if (a[i] < b[j]) {
        while (i < a.size() && a[i] == a[x])
          i++;
      } else {
        while (j < b.size() && b[j] == b[y])
          j++;
      }
    }
    WRITE(r);
  }
}

////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

//// MACRO ////
#define countof(a) (sizeof(a) / sizeof(a[0]))

#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define pos(c, i) c.being() + (i)
#define allof(c) c.begin(), c.end()
#define aallof(a) a, countof(a)
#define partof(c, i, n) c.begin() + (i), c.begin() + (i) + (n)
#define apartof(a, i, n) a + (i), a + (i) + (n)
#define long long long

#define EPS 1e-9
#define INF (1L << 30)
#define LINF (1LL << 60)

#define PREDICATE(t, a, exp) [&](const t &a) -> bool { return exp; }
#define COMPARISON_T(t) bool (*)(const t &, const t &)
#define COMPARISON(t, a, b, exp)                                               \\
  [&](const t &a, const t &b) -> bool { return exp; }
#define CONVERTER(TSrc, t, TDest, exp)                                         \\
  [&](const TSrc &t) -> TDest { return exp; }

inline int sign(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
inline bool inRange(double val, double min, double max) {
  return val - min > -EPS && val - max < EPS;
}

//// i/o helper ////

struct _Reader {
  template <class T> _Reader operator,(T &rhs) {
    cin >> rhs;
    return *this;
  }
};
struct _Writer {
  bool f;
  _Writer() : f(false) {}
  template <class T> _Writer operator,(const T &rhs) {
    cout << (f ? " " : "") << rhs;
    f = true;
    return *this;
  }
};
#define READ(t, ...)                                                           \\
  t __VA_ARGS__;                                                               \\
  _Reader(), __VA_ARGS__
#define WRITE(...)                                                             \\
  _Writer(), __VA_ARGS__;                                                      \\
  cout << endl

template <class T> struct vevector : public vector<vector<T>> {
  vevector(int n = 0, int m = 0, const T &initial = T())
      : vector<vector<T>>(n, vector<T>(m, initial)) {}
};
template <class T> struct vevevector : public vector<vevector<T>> {
  vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T())
      : vector<vevector<T>>(n, vevector<T>(m, l, initial)) {}
};
template <class T> struct vevevevector : public vector<vevevector<T>> {
  vevevevector(int n = 0, int m = 0, int l = 0, int k = 0,
               const T &initial = T())
      : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) {}
};
template <class T> T read() {
  T t;
  cin >> t;
  return t;
}
template <class T> vector<T> read(int n) {
  vector<T> v;
  REP(i, n) { v.push_back(read<T>()); }
  return v;
}
template <class T> vevector<T> read(int n, int m) {
  vevector<T> v;
  REP(i, n) v.push_back(read<T>(m));
  return v;
}
template <class T> vevector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) {
  vevector<T> v;
  REP(i, n) v.push_back(readjag<T>());
  return v;
}

template <class T1, class T2>
inline istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <class T1, class T2>
inline ostream &operator<<(ostream &out, pair<T1, T2> &p) {
  out << p.first << p.second;
  return out;
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &v) {
  ostringstream ss;
  for (auto x : v)
    ss << x << ' ';
  auto s = ss.str();
  out << s.substr(0, s.length() - 1) << endl;
  return out;
}

//// start up ////
void solve();
inline void readfrom(string filename) { freopen(filename.c_str(), "r", stdin); }
inline void writeto(string filename) { freopen(filename.c_str(), "w", stdout); }
int main() {
  solve();
  return 0;
}

////////////////////
/// template end ///
////////////////////

inline int setbit(int n) { return (1 << n) - 1; }
inline bool contains(int x, int min, int max) {
  return x >= min && x < max;
} // max含まない

void solve() {
  int testcases = INF;
  REP(testcase, testcases) {
    READ(int, N, M);
    if (!(N | M)) {
      break;
    }

    auto hs = read<int>(N);
    hs.insert(hs.begin(), 0);
    partial_sum(allof(hs), hs.begin());
    N++;
    auto ws = read<int>(M);
    ws.insert(ws.begin(), 0);
    partial_sum(allof(ws), ws.begin());
    M++;

    auto a = vector<int>();
    REP(i, N) FOR(j, i + 1, N) { a.push_back(hs[j] - hs[i]); }
    auto b = vector<int>();
    REP(i, M) FOR(j, i + 1, M) { b.push_back(ws[j] - ws[i]); }

    sort(allof(a));
    sort(allof(b));

    int i = 0, j = 0, r = 0;
    while (i < a.size() && j < b.size()) {
      int x = i;
      int y = j;
      if (a[i] == b[j]) {
        while (i < a.size() && a[i] == a[x])
          i++;
        while (j < b.size() && b[j] == b[y])
          j++;
        r += (i - x) * (j - y);
      } else if (a[i] < b[j]) {
        while (i < a.size() && a[i] == a[x])
          i++;
      } else {
        while (j < b.size() && b[j] == b[y])
          j++;
      }
    }
    WRITE(r);
  }
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(S) cout << (S) << endl;
#define ShowAll(collection)                                                    \\
  for (auto i : collection) {                                                  \\
    out(i);                                                                    \\
  }
#define beginend(v) v.begin(), v.end()

using pii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvc = vector<vector<char>>;
using ti3 = tuple<int, int, int>;
template <typename T> void removeAt(vector<T> &v, int index) {
  v.erase(v.begin() + index);
}

int solve(int n, int m) {
  vi w(m + 1, 0), h(n + 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> hm, wm;
  rep(i, n + 1) for (int j = i + 1; j <= n; ++j) hm[h[j] - h[i]]++;
  rep(i, m + 1) for (int j = i + 1; j <= m; ++j) wm[w[j] - w[i]]++;

  int ans = 0;
  for (auto hh : hm) {
    int hk, hv;
    tie(hk, hv) = hh;
    for (auto ww : wm) {
      int wk, wv;
      tie(wk, wv) = ww;
      if (hk == wk)
        ans += wv * hv;
    }
  }
  return ans;
}

int main() {
  int N, M;
  while (cin >> N >> M, N | M) {
    out(solve(N, M));
  }
}

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(S) cout << (S) << endl;
#define ShowAll(collection)                                                    \\
  for (auto i : collection) {                                                  \\
    out(i);                                                                    \\
  }
#define beginend(v) v.begin(), v.end()

using pii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvc = vector<vector<char>>;
using ti3 = tuple<int, int, int>;
template <typename T> void removeAt(vector<T> &v, int index) {
  v.erase(v.begin() + index);
}

int solve(int n, int m) {
  vi w(m + 1, 0), h(n + 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> hm, wm;
  rep(i, n + 1) for (int j = i + 1; j <= n; ++j) hm[h[j] - h[i]]++;
  rep(i, m + 1) for (int j = i + 1; j <= m; ++j) wm[w[j] - w[i]]++;

  int ans = 0;
  rep(i, max(h[n], w[n]) + 1) ans += (hm[i] * wm[i]);
  return ans;
}

int main() {
  int N, M;
  while (cin >> N >> M, N | M) {
    out(solve(N, M));
  }
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M, i, j, x, y, lx, ly, cnt;
  vector<int> h, w;
  while (cin >> N >> M, N || M) {
    h.resize(N);
    w.resize(M);
    for (i = 0; i < N; i++)
      cin >> h[i];
    for (i = 0; i < M; i++)
      cin >> w[i];
    cnt = 0;
    for (i = 0; i < N; i++) {
      for (j = 0; j < M; j++) {
        x = i;
        y = j;
        lx = h[x];
        ly = w[y];
        while (x < N && y < M) {
          if (lx == ly)
            cnt++;
          if (lx <= ly) {
            x++;
            lx += h[x];
          } else {
            y++;
            ly += w[y];
          }
        }
      }
    }
    cout << cnt << endl;
  }
}

#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int N, M, i, j, t, ans;
  while (cin >> N >> M, N | M) {
    vector<int> h(N), w(M);
    map<int, int> m;
    for (i = 0; i < N; i++)
      cin >> h[i];
    for (i = 0; i < M; i++)
      cin >> w[i];

    for (i = 0; i < N; i++) {
      t = 0;
      for (j = i; j < N; j++) {
        t += h[j];
        m[t]++;
      }
    }
    ans = 0;
    for (i = 0; i < M; i++) {
      t = 0;
      for (j = i; j < M; j++) {
        t += w[j];
        if (m.count(t))
          ans += m[t];
      }
    }

    cout << ans << endl;
  }
}


#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

const int MAX_SIZE = 5000001;

int main() {

  int mtate[MAX_SIZE];
  int myoko[MAX_SIZE];
  int n, m;
  vector<int> tate;
  vector<int> yoko;
  while (cin >> n >> m && !(n == 0 && m == 0)) {
    tate.clear();
    yoko.clear();
    tate.push_back(0);
    for (int i = 0; i < n; i++) {
      int t;
      cin >> t;
      int p = tate.size() - 1;
      tate.push_back(t + tate[p]);
    }
    yoko.push_back(0);
    for (int i = 0; i < m; i++) {
      int t;
      cin >> t;
      int p = yoko.size() - 1;
      yoko.push_back(t + yoko[p]);
    }
    // ツ閉敖づ個青板づーcnt
    // fill(mtate,mtate+MAX_SIZE,0);
    // fill(myoko,myoko+MAX_SIZE,0);
    // memset(mtate,0,sizeof(mtate));
    // memset(myoko,0,sizeof(myoko));
    for (int i = 0; i < MAX_SIZE; i++) {
      mtate[i] = myoko[i] = 0;
    }

    for (int i = 0; i < tate.size(); i++) {
      for (int j = i + 1; j < tate.size(); j++) {
        mtate[tate[j] - tate[i]]++;
      }
    }
    for (int i = 0; i < yoko.size(); i++) {
      for (int j = i + 1; j < yoko.size(); j++) {
        myoko[yoko[j] - yoko[i]]++;
      }
    }
    int cnt = 0;
    for (int i = 0; i < MAX_SIZE; i++) {
      cnt += (mtate[i] * myoko[i]);
    }
    cout << cnt << endl;
  }

  return 0;
}

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

const int MAX_SIZE = 2000001;

int main() {

  // int mtate[MAX_SIZE];
  // int myoko[MAX_SIZE];
  vector<int> mtate(MAX_SIZE, 0);
  vector<int> myoko(MAX_SIZE, 0);

  int n, m;
  vector<int> tate;
  vector<int> yoko;
  while (cin >> n >> m && !(n == 0 && m == 0)) {
    tate.clear();
    yoko.clear();
    tate.push_back(0);
    for (int i = 0; i < n; i++) {
      int t;
      cin >> t;
      int p = tate.size() - 1;
      tate.push_back(t + tate[p]);
    }
    yoko.push_back(0);
    for (int i = 0; i < m; i++) {
      int t;
      cin >> t;
      int p = yoko.size() - 1;
      yoko.push_back(t + yoko[p]);
    }
    // ツ閉敖づ個青板づーcnt
    // fill(mtate,mtate+MAX_SIZE,0);
    // fill(myoko,myoko+MAX_SIZE,0);
    // memset(mtate,0,sizeof(mtate));
    // memset(myoko,0,sizeof(myoko));
    for (int i = 0; i < MAX_SIZE; i++) {
      mtate[i] = myoko[i] = 0;
    }

    for (int i = 0; i < tate.size(); i++) {
      for (int j = i + 1; j < tate.size(); j++) {
        mtate[tate[j] - tate[i]]++;
      }
    }
    for (int i = 0; i < yoko.size(); i++) {
      for (int j = i + 1; j < yoko.size(); j++) {
        myoko[yoko[j] - yoko[i]]++;
      }
    }
    int cnt = 0;
    for (int i = 0; i < MAX_SIZE; i++) {
      cnt += (mtate[i] * myoko[i]);
    }
    cout << cnt << endl;
  }

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, m;
  int N = 1500 * 1000;
  while (1) {
    cin >> n;
    cin >> m;
    if (n * m == 0) {
      break;
    }
    int v_interval[n], h_interval[m];
    for (int i = 0; i < n; i++) {
      cin >> v_interval[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> h_interval[i];
    }

    int h_num = m * (m + 1) / 2;
    int h_lengthes[h_num];
    int temp = 0;
    short h_length_num[N + 1];
    for (int i = 0; i < N + 1; i++) {
      h_length_num[i] = 0;
    }
    for (int i = 0; i < m; i++) {
      for (int j = i; j < m; j++, temp++) {
        if (i == j) {
          h_lengthes[temp] = h_interval[i];
        } else {
          h_lengthes[temp] = h_lengthes[temp - 1] + h_interval[j];
        }
        h_length_num[h_lengthes[temp]]++;
      }
    }

    int v_num = n * (n + 1) / 2;
    int v_lengthes[v_num];
    temp = 0;
    short v_length_num[N + 1];
    for (int i = 0; i < N + 1; i++) {
      v_length_num[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++, temp++) {
        if (i == j) {
          v_lengthes[temp] = v_interval[i];
        } else {
          v_lengthes[temp] = v_lengthes[temp - 1] + v_interval[j];
        }
        v_length_num[v_lengthes[temp]]++;
      }
    }

    int count = 0;
    for (int i = 0; i < N + 1; i++) {
      count += h_length_num[i] * v_length_num[i];
    }
    cout << count << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, m;
  int N = 1500 * 1000;
  while (1) {
    cin >> n;
    cin >> m;
    if (n * m == 0) {
      break;
    }
    int v_interval[n], h_interval[m];
    for (int i = 0; i < n; i++) {
      cin >> v_interval[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> h_interval[i];
    }

    short v_length_num[N + 1];
    for (int i = 0; i < N + 1; i++) {
      v_length_num[i] = 0;
    }
    int v_length = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if (i == j) {
          v_length = v_interval[i];
        } else {
          v_length += v_interval[j];
        }
        v_length_num[v_length]++;
      }
    }

    short h_length_num[N + 1];
    for (int i = 0; i < N + 1; i++) {
      h_length_num[i] = 0;
    }
    int h_length = 0;
    for (int i = 0; i < m; i++) {
      for (int j = i; j < m; j++) {
        if (i == j) {
          h_length = h_interval[i];
        } else {
          h_length += h_interval[j];
        }
        h_length_num[h_length]++;
      }
    }

    int count = 0;
    for (int i = 0; i < N + 1; i++) {
      count += v_length_num[i] * h_length_num[i];
    }
    cout << count << endl;
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (i = 0; i < n; i++)
#define rep2(i, n) for (i = 1; i <= n; i++)

int main() {
  int n, m;
  int i, j, k;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    int h[1501], w[1501];
    h[0] = 0;
    for (i = 1; i <= n; i++) {
      cin >> h[i];
      h[i] += h[i - 1];
    }
    w[0] = 0;
    for (i = 1; i <= m; i++) {
      cin >> w[i];
      w[i] += w[i - 1];
    }

    multiset<int> s;
    for (i = 0; i <= n; i++) {
      for (j = 0; j < i; j++) {
        s.insert(h[j] - h[i]);
      }
    }

    int c = 0;
    for (i = 0; i <= m; i++) {
      for (j = 0; j < i; j++) {
        c += s.count(w[j] - w[i]);
      }
    }

    cout << c << endl;
  }
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (i = 0; i < n; i++)
#define rep2(i, n) for (i = 1; i <= n; i++)

int main() {
  int n, m;
  int i, j, k;
  static int a[1500001];
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    for (i = 0; i < 1500001; i++)
      a[i] = 0;
    int h[1501], w[1501];
    h[0] = 0;
    for (i = 1; i <= n; i++) {
      cin >> h[i];
      h[i] += h[i - 1];
    }
    w[0] = 0;
    for (i = 1; i <= m; i++) {
      cin >> w[i];
      w[i] += w[i - 1];
    }

    for (i = 0; i <= n; i++) {
      for (j = 0; j < i; j++) {
        a[h[i] - h[j]]++;
      }
    }

    int c = 0;
    for (i = 0; i <= m; i++) {
      for (j = 0; j < i; j++) {
        c += a[w[i] - w[j]];
      }
    }
    //		for(i=0;i<50;i++) cout << i << "   " << a[i] << endl;
    cout << c << endl;
  }
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0)
      break;
    vector<int> h(n), w(m);
    for (int i = 0; i < n; i++)
      cin >> h[i];
    for (int i = 0; i < m; i++)
      cin >> w[i];
    int t = 0;
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        sum += h[j];
        for (int k = 0; k < m; k++) {
          int sum2 = 0;
          for (int l = k; l < m; l++) {
            sum2 += w[l];
            if (sum < sum2)
              break;
            if (sum == sum2) {
              t++;
              break;
            }
          }
        }
      }
    }
    cout << t << endl;
  }
  return 0;
}

#include <iostream>
#include <vector>
#define M 1500000
using namespace std;
int main(void) {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0)
      break;
    vector<int> h(n), w(m);
    vector<int> hl(M, 0), wl(M, 0);
    for (int i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> w[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum = 0;
      for (int j = i; j < n; j++) {
        sum += h[j];
        hl[sum - 1]++;
      }
    }
    for (int i = 0; i < m; i++) {
      sum = 0;
      for (int j = i; j < m; j++) {
        sum += w[j];
        wl[sum - 1]++;
      }
    }
    int t = 0;
    for (int i = 0; i < M; i++) {
      t += hl[i] * wl[i];
    }
    cout << t << endl;
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <string>

using namespace std;

int INF = 10000000;

int n, m;

int w[1510];
int h[1510];

int f[1510 * 1000];

int main() {

  while (1) {
    memset(f, 0, 1510 * 1000);

    cin >> n >> m;

    if (!w && !h)
      break;

    for (int i = 0; i < n; i++) {
      cin >> w[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> h[i];
    }

    int sum = 0;

    for (int i = 0; i < n; i++) {
      int tmpsum = 0;
      for (int j = i; j < n; j++) {
        tmpsum += w[j];
        f[tmpsum]++;
      }
    }

    for (int i = 0; i < m; i++) {
      int tmpsum = 0;
      for (int j = i; j < m; j++) {
        tmpsum += h[j];

        sum += f[tmpsum];
      }
    }

    cout << sum << endl;
  }

  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <string>

using namespace std;

int INF = 10000000;

int n, m;

int w[1510];
int h[1510];

int wf[1510 * 1000];
int hf[1510 * 1000];

int main() {

  while (1) {
    memset(wf, 0, 1510 * 1000 * sizeof(int));
    memset(hf, 0, 1510 * 1000 * sizeof(int));

    cin >> n >> m;

    if (!n && !m)
      break;

    for (int i = 0; i < n; i++) {
      cin >> w[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> h[i];
    }

    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        sum += w[j];
        wf[sum]++;
      }
    }

    for (int i = 0; i < m; i++) {
      int sum = 0;
      for (int j = i; j < m; j++) {
        sum += h[j];
        hf[sum]++;
      }
    }

    int sum = 0;

    for (int i = 0; i < 1510 * 1000; i++) {
      sum += wf[i] * hf[i];
    }

    cout << sum << endl;
  }

  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)

int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1, 0, -1};
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n + m == 0)
      break;
    int h[n], w[m];
    REP(i, n) cin >> h[i];
    REP(i, m) cin >> w[i];

    int wh[1500001];
    int ww[1500001];
    REP(i, n) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        sum += h[i];
        wh[sum]++;
      }
    }
    REP(i, m) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        sum += w[i];
        ww[sum]++;
      }
    }

    ll cnt = 0;
    REP(i, 1500001) cnt += wh[i] * ww[i];
    cout << cnt << endl;
  }
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)

int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1, 0, -1};
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n + m == 0)
      break;
    int h[n], w[m], max_h = 0, max_w = 0;
    REP(i, n) {
      cin >> h[i];
      max_h += h[i];
    }
    REP(i, m) {
      cin >> w[i];
      max_w += w[i];
    }

    int wh[max_h + 1];
    int ww[max_w + 1];
    memset(wh, 0, sizeof(wh));
    memset(ww, 0, sizeof(ww));
    REP(i, n) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        sum += h[j];
        wh[sum]++;
      }
    }
    REP(i, m) {
      int sum = 0;
      for (int j = i; j < m; j++) {
        sum += w[j];
        ww[sum]++;
      }
    }

    int cnt = 0;
    REP(i, min(max_h + 1, max_w + 1)) { cnt += wh[i] * ww[i]; }
    cout << cnt << endl;
  }
  return 0;
}


// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long int

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M;
int h[2000], w[2000];
int ra[2000], rb[2000];
signed main() {
  while (cin >> N >> M, N || M) {
    memset(ra, 0, sizeof(ra));
    memset(rb, 0, sizeof(rb));

    rep(i, 0, N) cin >> h[i + 1];
    rep(i, 0, M) cin >> w[i + 1];
    rep(i, 0, N) h[i + 1] += h[i];
    rep(i, 0, M) w[i + 1] += w[i];

    rep(i, 0, N) repq(j, i + 1, N) { ra[h[j] - h[i]]++; }
    rep(i, 0, M) repq(j, i + 1, M) { rb[w[j] - w[i]]++; }

    int ans = 0;
    rep(i, 0, 2000) ans += ra[i] * rb[i];
    cout << ans << endl;
  }
  return 0;
}

// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long int

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M;
int h[2000], w[2000];
signed main() {
  while (cin >> N >> M, N || M) {
    map<int, int> ra, rb;

    rep(i, 0, N) cin >> h[i + 1];
    rep(i, 0, M) cin >> w[i + 1];
    rep(i, 0, N) h[i + 1] += h[i];
    rep(i, 0, M) w[i + 1] += w[i];

    rep(i, 0, N) repq(j, i + 1, N) { ra[h[j] - h[i]]++; }
    rep(i, 0, M) repq(j, i + 1, M) { rb[w[j] - w[i]]++; }

    int ans = 0;
    for (auto x : ra) {
      int val = x.first;
      ans += ra[val] * rb[val];
    }
    cout << ans << endl;
  }
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 1501
#define MAX2 1001

int main() {
  int h[MAX], w[MAX];
  int H[MAX2], W[MAX2];
  for (int N, M; scanf("%d%d", &N, &M), N;) {
    memset(h, 0, sizeof(h));
    memset(w, 0, sizeof(w));
    memset(H, 0, sizeof(H));
    memset(W, 0, sizeof(W));

    for (int i = 0; i < N; i++) {
      scanf("%d", &h[i]);
    }
    for (int i = 0; i < M; i++) {
      scanf("%d", &w[i]);
    }

    for (int i = 0; i < N; i++) {
      int a = 0;
      for (int j = i; j < N; j++) {
        a += h[j];
        H[a]++;
      }
    }
    for (int i = 0; i < M; i++) {
      int a = 0;
      for (int j = i; j < M; j++) {
        a += w[j];
        W[a]++;
      }
    }

    int ans = 0;
    for (int i = 0; i < MAX2; i++) {
      ans += H[i] * W[i];
    }
    cout << ans << endl;
  }
  return 0;
}

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 1501
#define MAX2 1001

int main() {
  static int h[MAX], w[MAX];
  static int H[MAX * MAX2], W[MAX * MAX2];
  for (int N, M; scanf("%d%d", &N, &M), N;) {
    memset(h, 0, sizeof(h));
    memset(w, 0, sizeof(w));
    memset(H, 0, sizeof(H));
    memset(W, 0, sizeof(W));

    for (int i = 0; i < N; i++) {
      scanf("%d", &h[i]);
    }
    for (int i = 0; i < M; i++) {
      scanf("%d", &w[i]);
    }

    for (int i = 0; i < N; i++) {
      int a = 0;
      for (int j = i; j < N; j++) {
        a += h[j];
        H[a]++;
      }
    }
    for (int i = 0; i < M; i++) {
      int a = 0;
      for (int j = i; j < M; j++) {
        a += w[j];
        W[a]++;
      }
    }

    int ans = 0;
    for (int i = 0; i < MAX * MAX2; i++) {
      ans += H[i] * W[i];
    }
    cout << ans << endl;
  }
  return 0;
}