#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char> T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char> T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0},
          vx[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
#define ALL(x) (x).begin(), (x).end()
#define UNIQ(c) (isok).erase(unique(ALL((isok))), (isok).end())
#define LOWER(s) transform(ALL((maze)), (maze).begin(), TL<char>)
#define UPPER(s) transform(ALL((maze)), (maze).begin(), TU<char>)
#define FOR(i, a, b) for (LL i = (a); i < (b); i++)
#define RFOR(i, a, b) for (LL i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define INIT                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0)

int n, m;
int h[1510], w[1510];
LL hcnt[1550] = {}, wcnt[1550] = {};

int main() {
  while (cin >> n >> m && n && m) {
    for (int i = 1; i <= n; i++) {
      cin >> h[i];
    }
    for (int i = 1; i <= m; i++) {
      cin >> w[i];
    }
    REP(i, 1550) hcnt[i] = wcnt[i] = 0;
    for (int i = 1; i <= n; i++) {
      int he = h[i];
      hcnt[he]++;
      for (int j = i + 1; j <= n; j++) {
        he += h[j];
        hcnt[he]++;
      }
    }
    for (int i = 1; i <= m; i++) {
      int he = w[i];
      wcnt[he]++;
      for (int j = i + 1; j <= m; j++) {
        he += w[j];
        wcnt[he]++;
      }
    }
    LL ans = 0;
    REP(i, 1550) {
      if (i)
        ans += wcnt[i] * hcnt[i];
    }
    cout << ans << endl;
  }
}

#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char> T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char> T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0},
          vx[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
#define ALL(x) (x).begin(), (x).end()
#define UNIQ(c) (isok).erase(unique(ALL((isok))), (isok).end())
#define LOWER(s) transform(ALL((maze)), (maze).begin(), TL<char>)
#define UPPER(s) transform(ALL((maze)), (maze).begin(), TU<char>)
#define FOR(i, a, b) for (LL i = (a); i < (b); i++)
#define RFOR(i, a, b) for (LL i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define INIT                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0)

int n, m;
int h[1510], w[1510];
LL hcnt[1500001] = {}, wcnt[1500001] = {};

int main() {
  while (cin >> n >> m && n && m) {
    for (int i = 1; i <= n; i++) {
      cin >> h[i];
    }
    for (int i = 1; i <= m; i++) {
      cin >> w[i];
    }
    REP(i, 1500001) hcnt[i] = wcnt[i] = 0;
    for (int i = 1; i <= n; i++) {
      int he = h[i];
      hcnt[he]++;
      for (int j = i + 1; j <= n; j++) {
        he += h[j];
        hcnt[he]++;
      }
    }
    for (int i = 1; i <= m; i++) {
      int he = w[i];
      wcnt[he]++;
      for (int j = i + 1; j <= m; j++) {
        he += w[j];
        wcnt[he]++;
      }
    }
    LL ans = 0;
    REP(i, 1500001) {
      if (i)
        ans += wcnt[i] * hcnt[i];
    }
    cout << ans << endl;
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vector<int> h(n + 1, 0);
    vector<int> w(m + 1, 0);
    for (int i = 1; i <= n; i++) {
      cin >> h[i];
      h[i] += h[i - 1];
      //            cout << h[i] << " ";
    }
    //        cout << endl;
    for (int i = 1; i <= m; i++) {
      cin >> w[i];
      w[i] += w[i - 1];
      //            cout << w[i] << " ";
    }
    //        cout << endl;
    int ans = 0;
    for (int i = 1; i <= h[n]; i++) {
      int hnum = 0, wnum = 0;
      for (int j = n; j > 0; j--) {
        /*
                        cout << "*" << i << " ";
                        cout << *lower_bound(h.begin(),h.end(),h[j]-i);
        */
        if (*lower_bound(h.begin(), h.end(), h[j] - i) == h[j] - i) {
          hnum++;
          //                   cout << "+";
        }
        //                else cout << "-";
      }
      //            cout << endl;
      for (int j = m; j > 0; j--) {
        /*
                        cout << "*" << i << " ";
                        cout << *lower_bound(w.begin(),w.end(),w[j]-i);
        */
        if (*lower_bound(w.begin(), w.end(), w[j] - i) == w[j] - i) {
          wnum++;
          //                    cout << "+";
        }
        //                else cout << "-";
      }
      //            cout << endl;
      ans += hnum * wnum;
    }
    cout << ans << endl;
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vector<int> h(n + 1, 0);
    vector<int> w(m + 1, 0);
    for (int i = 1; i <= n; i++) {
      cin >> h[i];
      h[i] += h[i - 1];
      //            cout << h[i] << " ";
    }
    //        cout << endl;
    for (int i = 1; i <= m; i++) {
      cin >> w[i];
      w[i] += w[i - 1];
      //            cout << w[i] << " ";
    }
    //        cout << endl;
    int ans = 0;
    map<int, int> hlen, wlen;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        int t = h[j] - h[i];
        hlen[t]++;
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        int t = w[j] - w[i];
        wlen[t]++;
      }
    }
    map<int, int>::iterator hitr, witr;
    for (hitr = hlen.begin(); hitr != hlen.end(); ++hitr) {
      int len = hitr->first, hval = hitr->second;
      witr = wlen.find(len);
      if (witr != wlen.end()) {
        int wval = witr->second;
        ans += hval * wval;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


#include <iostream>

using namespace std;

int max(int a, int b) {
  if (a >= b)
    return a;
  else
    return b;
}

int main() {
  int n, m;

  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;

    int *h, *w;

    int *hNum, *wNum;

    h = new int[n];
    w = new int[m];

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

    hNum = new int[maxHLength + 1];
    wNum = new int[maxWLength + 1];

    for (int i = 0; i <= maxHLength; i++) {
      hNum[i] = 0;
    }

    for (int i = 0; i <= maxWLength; i++) {
      wNum[i] = 0;
    }

    int maxLength = 0;

    for (int i = 0; i < n; i++) {
      int length = 0;
      for (int j = i; j < n; j++) {
        length += h[j];
        hNum[length]++;
      }
    }
    for (int i = 0; i < m; i++) {
      int length = 0;
      for (int j = i; j < m; j++) {
        length += w[j];
        wNum[length]++;
      }
    }

    int sum = 0;

    maxLength = max(maxHLength, maxWLength);

    for (int i = 0; i <= maxLength; i++) {
      sum += hNum[i] * wNum[i];
    }

    cout << sum << endl;
  }

  return 0;
}

#include <iostream>

using namespace std;

int max(int a, int b) {
  if (a >= b)
    return b;
  else
    return a;
}

int main() {
  int n, m;

  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;

    int *h, *w;

    int *hNum, *wNum;

    h = new int[n];
    w = new int[m];

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

    hNum = new int[maxHLength + 1];
    wNum = new int[maxWLength + 1];

    for (int i = 0; i <= maxHLength; i++) {
      hNum[i] = 0;
    }

    for (int i = 0; i <= maxWLength; i++) {
      wNum[i] = 0;
    }

    int maxLength = 0;

    for (int i = 0; i < n; i++) {
      int length = 0;
      for (int j = i; j < n; j++) {
        length += h[j];
        hNum[length]++;
      }
    }
    for (int i = 0; i < m; i++) {
      int length = 0;
      for (int j = i; j < m; j++) {
        length += w[j];
        wNum[length]++;
      }
    }

    int sum = 0;

    maxLength = max(maxHLength, maxWLength);

    for (int i = 0; i <= maxLength; i++) {
      sum += hNum[i] * wNum[i];
    }

    cout << sum << endl;
  }

  return 0;
}


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

bool solve() {
  int n, m;
  cin >> n >> m;
  if (n == 0 && m == 0)
    return false;
  vector<int> h(n + 1), w(m + 1);
  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];
  }

  vector<int> hei(2001);
  for (int i = 0; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      hei[h[j] - h[i]]++;
    }
  }

  int cnt = 0;
  for (int i = 0; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      cnt += hei[w[j] - w[i]];
    }
  }
  cout << cnt << endl;
  return true;
}

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

//????????????

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

bool solve() {
  int n, m;
  cin >> n >> m;
  if (n == 0 && m == 0)
    return false;
  vector<int> h(n + 1), w(m + 1);
  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];
  }

  vector<int> hei(1500001);
  for (int i = 0; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      hei[h[j] - h[i]]++;
    }
  }

  int cnt = 0;
  for (int i = 0; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      cnt += hei[w[j] - w[i]];
    }
  }
  cout << cnt << endl;
  return true;
}

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

//????????????


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

int total(int k);
int count(std::vector<int> arr, int k);

using namespace std;
int main() {
  int n, m, i, j, sum, squares;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    int h[n], w[m];
    for (i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (i = 0; i < m; i++) {
      cin >> w[i];
    }
    vector<int> sums_h;

    for (i = 0; i < n; ++i) {
      sum = 0;
      for (j = 0; j < n - i; ++j) {
        sum += h[i + j];
        sums_h.push_back(sum);
      }
    }
    squares = 0;
    for (i = 0; i < m; ++i) {
      sum = 0;
      for (j = 0; j < m - i; ++j) {
        sum += w[i + j];
        squares += count(sums_h, sum);
      }
    }
    cout << squares << endl;
  }
}

int total(int k) {
  int i, sum;
  sum = 0;
  for (i = 0; i < k; ++i) {
    sum += (k - i);
  }
  return sum;
}

int count(vector<int> arr, int k) {
  int sum = 0;
  for (vector<int>::iterator it = arr.begin(); it != arr.end(); ++it) {
    if (k == *it) {
      sum++;
    }
  }
  return sum;
}

#include <iostream>

int total(int k);

using namespace std;
int main() {
  int n, m, i, j, sum, squares;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    int h[n], w[m];
    for (i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (i = 0; i < m; i++) {
      cin >> w[i];
    }
    int array[1500001];
    for (i = 0; i < 1500001; ++i) {
      array[i] = 0;
    }
    for (i = 0; i < n; ++i) {
      sum = 0;
      for (j = 0; j < n - i; ++j) {
        sum += h[i + j];
        array[sum]++;
      }
    }

    squares = 0;
    for (i = 0; i < m; ++i) {
      sum = 0;
      for (j = 0; j < m - i; ++j) {
        sum += w[i + j];
        squares += array[sum];
      }
    }
    cout << squares << endl;
  }
}

int total(int k) {
  int i, sum;
  sum = 0;
  for (i = 0; i < k; ++i) {
    sum += (k - i);
  }
  return sum;
}


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

using namespace std;

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

#define all(v) v.begin(), v.end()
#define INF 1 << 30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

typedef long long ll;
int ih[1500 * 1500 + 1510];
int iw[1500 * 1500 + 1510];
int main() {
  while (1) {
    rep(i, 1500 * 1500 + 1510) {
      ih[i] = 0;
      iw[i] = 0;
    }
    int n, m;
    int h[1520];
    int w[1010];
    int ans = 0;
    cin >> n >> m;
    if (n == 0)
      break;
    rep(i, n) { cin >> h[i]; }
    rep(i, m) { cin >> w[i]; }
    rep(s, n) {
      REP(e, s, n) {
        // cout << "s : "  << s << "e : "<<e<< endl;
        REP(i, s, e + 1) { ih[s + e * 1500] += h[i]; }
      }
    }
    sort(ih, ih + 1500 * 1500 + 159, greater<int>());
    rep(s, m) {
      REP(e, s, m) {
        REP(i, s, e + 1) { iw[s + e * 1500] += w[i]; }
      }
    }
    sort(iw, iw + 1500 * 1500 + 159, greater<int>());
    // rep(i,6) cout << "ih : "<<ih[i] << endl;
    // rep(i,6) cout << "iw : "<<iw[i] << endl;

    int ph = 0;
    int pw = 0;

    while (ih[ph] != 0 || iw[pw] != 0) {
      // cout << "ph : " << ph << endl;
      int ch = 1;
      int cw = 1;
      if (ih[ph] == iw[pw]) {
        while (ih[ph] == ih[ph + 1]) {
          ph += 1;
          ch += 1;
        }
        while (iw[pw] == iw[pw + 1]) {
          pw += 1;
          cw += 1;
        }
        ans += ch * cw;
        ph += 1;
      }
      if (ih[ph] > iw[pw]) {
        ph += 1;
      } else if (iw[pw] > ih[ph]) {
        pw += 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

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

#define all(v) v.begin(), v.end()
#define INF 1 << 30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

typedef long long ll;
int ih[1000 * 1500 + 1500];
int iw[1000 * 1500 + 1500];
int main() {

  while (1) {
    rep(i, 1000 * 1500 + 1500) {
      ih[i] = 0;
      iw[i] = 0;
    }
    int ans = 0;
    int n, m;
    int h[1520];
    int w[1010];
    int maxh = 0;
    int maxw = 0;
    cin >> n >> m;
    if (n == 0)
      break;
    rep(i, n) {
      cin >> h[i];
      maxh += h[i];
    }
    rep(i, m) {
      cin >> w[i];
      maxw += w[i];
    }
    int maxs = min(maxh, maxw);

    rep(s, n) {
      int tsh = 0;
      for (int e = s; e < n && tsh <= maxs; e++) {
        // cout << "s : "  << s << "e : "<<e<< endl;
        tsh += h[e];
        ih[tsh] += 1;
      }
    }
    rep(s, m) {
      int tsw = 0;

      for (int e = s; e < m && tsw <= maxs; e++) {

        tsw += w[e];
        iw[tsw] += 1;
      }
    }
    // rep(i,6) cout << "ih : "<<ih[i] << endl;
    // rep(i,6) cout << "iw : "<<iw[i] << endl;

    REP(i, 1, maxs + 1) {
      ans += ih[i] * iw[i];
      // cout << i <<  "ih[i]" << ih[i] << "iw[i]" << iw[i] <<endl;
    }
    cout << ans << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
int h[1501];
int w[1501];

int widths[10000010];
int heights[10000010];

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

    for (int i = 0; i < n + 1; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        // cout << h[j] << ',' << h[i] << endl;
        heights[h[j] - h[i]]++;
      }
    }
    for (int i = 0; i < m + 1; i++) {
      for (int j = i + 1; j < m + 1; j++) {
        // cout << w[j] << ',' << w[i] << endl;
        widths[w[j] - w[i]]++;
      }
    }
    int ans = 0;
    for (int i = 0; i < 1000; i++) {
      ans += widths[i] * heights[i];
    }
    cout << ans << endl;
  }
}

#include <algorithm>
#include <iostream>
using namespace std;
int h[1501];
int w[1501];

int widths[2000000];
int heights[2000000];

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

    for (int i = 0; i < n + 1; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        // cout << h[j] << ',' << h[i] << endl;
        heights[h[j] - h[i]]++;
      }
    }
    for (int i = 0; i < m + 1; i++) {
      for (int j = i + 1; j < m + 1; j++) {
        // cout << w[j] << ',' << w[i] << endl;
        widths[w[j] - w[i]]++;
      }
    }
    int ans = 0;
    int maxsize = min(n, m) * 1000;
    for (int i = 0; i < maxsize; i++) {
      ans += widths[i] * heights[i];
    }
    cout << ans << endl;
  }
}


#include <array>
#include <iostream>

using namespace std;

int main() {
  int n, m;
  array<int, 1001> kaisa;
  kaisa[0] = 0;
  for (int i = 1; i < 1001; i++)
    kaisa[i] += kaisa[i - 1] + i;
  while (cin >> n >> m, n) {
    int hs = 0, ws = 0;
    array<bool, 1501> h, w;
    for (int i = 0; i < 1501; i++)
      h[i] = w[i] = false;
    for (int i = 0; i < n; i++) {
      int hi;
      cin >> hi;
      hs += hi;
      h[hs] = true;
    }
    for (int i = 0; i < m; i++) {
      int wi;
      cin >> wi;
      ws += wi;
      w[ws] = true;
    }
    int ret = 0;
    for (int i = 0; i < n; i++) {
      int count = 0;
      for (int j = 0; i + j < n && j < m; j++) {
        count += (int)(h[i + j] && w[j]);
      }
      ret += kaisa[count];
    }
    for (int i = 1; i < m; i++) {
      int count = 0;
      for (int j = 0; j < n && i + j < m; j++) {
        count += (int)(h[i] && w[i + j]);
      }
      ret += kaisa[count];
    }
    cout << ret << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> w, h;
    int ws = 0, hs = 0;
    h.push_back(0);
    for (int i = 0; i < n; i++) {
      int hi;
      cin >> hi;
      h.push_back(hs += hi);
    }
    w.push_back(0);
    for (int i = 0; i < m; i++) {
      int wi;
      cin >> wi;
      w.push_back(ws += wi);
    }
    vector<int> diag(ws + hs + 1);
    for (int unsigned i = 0; i < h.size(); i++) {
      for (int unsigned j = 0; j < w.size(); j++) {
        diag[h[i] + w[j]]++;
      }
    }
    int ret = 0;
    for (int unsigned i = 0; i < diag.size(); i++) {
      ret += diag[i] * (diag[i] - 1) / 2;
    }
    cout << ret << endl;
  }
  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int N, M, ans, tmp;
int row[1500], cow[1500];

int main() {
  while (cin >> N >> M && N > 0) {
    row[0] = 0;
    for (int i = 1; i <= N; i++) {
      cin >> tmp;
      row[i] = row[i - 1] + tmp;
    }
    cow[0] = 0;
    for (int i = 1; i <= M; i++) {
      cin >> tmp;
      cow[i] = cow[i - 1] + tmp;
    }

    ans = 0;

    for (int i = 0; i <= N; i++) {
      for (int j = i + 1; j <= N; j++) {
        for (int k = 0; k <= M; k++) {
          for (int l = k + 1; l <= M; l++) {
            if (row[j] - row[i] == cow[l] - cow[k])
              ans++;
          }
        }
      }
    }

    cout << ans << endl;
  }
}

#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 > 0) {
    int h[1600];
    int w[1600];
    rep(i, N) { cin >> h[i]; }
    rep(i, M) { cin >> w[i]; }

    vector<int> h_edge(1500000, 0);
    vector<int> w_edge(1500000, 0);
    int len;

    rep(i, N) {
      len = 0;
      REP(j, i, N) {
        len += h[j];
        h_edge[len]++;
      }
    }

    rep(i, M) {
      len = 0;
      REP(j, i, M) {
        len += w[j];
        w_edge[len]++;
      }
    }

    int count = 0;
    REP(i, 1, 1500000) { count += h_edge[i] * w_edge[i]; }

    cout << count << endl;
  }
}


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

int main() {
  int H, W;

  while (cin >> H >> W, H + W) {
    int h[1001] = {};
    int w[1001] = {};
    map<int, int> setH;
    map<int, int> setW;

    for (int i = 1; i <= H; i++)
      cin >> h[i];
    for (int i = 1; i <= W; i++)
      cin >> w[i];

    for (int i = 1; i <= H; i++)
      h[i] += h[i - 1];
    for (int i = 1; i <= W; i++)
      w[i] += w[i - 1];

    for (int i = 0; i < H; i++) {
      for (int j = i + 1; j <= H; j++) {
        int t = h[j] - h[i];
        if (setH.count(t))
          setH[t]++;
        else
          setH[t] = 1;
      }
    }
    for (int i = 0; i < W; i++) {
      for (int j = i + 1; j <= W; j++) {
        int t = w[j] - w[i];
        if (setW.count(t))
          setW[t]++;
        else
          setW[t] = 1;
      }
    }

    int cnt = 0;
    for (auto i : setH) {
      if (setW.count(i.first))
        cnt += setW[i.first] * i.second;
    }

    cout << cnt << endl;
  }

  return 0;
}

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

int main() {
  int H, W;

  while (cin >> H >> W, H + W) {
    int h[1501] = {};
    int w[1501] = {};
    map<int, int> setH;
    map<int, int> setW;

    for (int i = 1; i <= H; i++)
      cin >> h[i];
    for (int i = 1; i <= W; i++)
      cin >> w[i];

    for (int i = 1; i <= H; i++)
      h[i] += h[i - 1];
    for (int i = 1; i <= W; i++)
      w[i] += w[i - 1];

    for (int i = 0; i < H; i++) {
      for (int j = i + 1; j <= H; j++) {
        int t = h[j] - h[i];
        if (setH.count(t))
          setH[t]++;
        else
          setH[t] = 1;
      }
    }
    for (int i = 0; i < W; i++) {
      for (int j = i + 1; j <= W; j++) {
        int t = w[j] - w[i];
        if (setW.count(t))
          setW[t]++;
        else
          setW[t] = 1;
      }
    }

    int cnt = 0;
    for (auto i : setH) {
      if (setW.count(i.first))
        cnt += setW[i.first] * i.second;
    }

    cout << cnt << endl;
  }

  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n + m == 0) {
      break;
    }
    vector<int> h(n);
    vector<int> w(m);

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

    int ans = 0;

    for (int i = 0; i < n; i++) {
      int s = h[i];
      for (int j = 0; j <= i; j++) {
        if (j > 0) {
          s = h[i] - h[j - 1];
        }
        for (int k = 0; k < m; k++) {
          int s2 = w[k];
          for (int l = 0; l <= k; l++) {
            if (l > 0) {
              s2 = w[k] - w[l - 1];
            }
            if (s == s2) {
              ans++;
            }
          }
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n + m == 0) {
      break;
    }
    vector<int> h(n);
    vector<int> w(m);
    vector<int> t(1500001);
    vector<int> t2(1500001);

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

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

    for (int i = 0; i < n; i++) {
      int len = 0;
      for (int j = i; j < n; j++) {
        len += h[j];
        t[len]++;
      }
    }

    for (int i = 0; i < m; i++) {
      int len = 0;
      for (int j = i; j < m; j++) {
        len += w[j];
        t2[len]++;
      }
    }

    int ans = 0;
    for (int i = 0; i < 1500001; i++) {
      ans += t[i] * t2[i];
    }

    cout << ans << endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
int n[2000000], m[2000000], r[2000], c[2000], H, W, R, K, LEFT, RIGHT, MID, S;
int main() {
  while (true) {
    r[0] = 0;
    c[0] = 0;
    S = 0;
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }
    for (int i = 1; i <= H; i++) {
      cin >> R;
      r[i] = r[i - 1] + R;
    }
    for (int i = 1; i <= W; i++) {
      cin >> R;
      c[i] = c[i - 1] + R;
    }
    for (int i = 0; i <= H; i++) {
      for (int j = i + 1; j <= H; j++) {
        n[K] = r[j] - r[i];
        K++;
      }
    }
    K = 0;
    for (int i = 0; i <= W; i++) {
      for (int j = i + 1; j <= W; j++) {
        m[K] = c[j] - c[i];
        K++;
      }
    }
    sort(m, m + K);
    for (int i = 0; i <= K; i++) {
      LEFT = 0;
      RIGHT = K;
      while (LEFT < RIGHT) {
        MID = (LEFT + RIGHT) / 2;
        if (n[i] == MID) {
          S++;
          break;
        }
        if (n[i] < m[MID]) {
          RIGHT = MID;
        } else if (n[i] > MID) {
          LEFT = MID + 1;
        }
      }
    }
    cout << S << endl;
  }
}


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

int main() {
  int n, m;
  while (cin >> n >> m, n != 0) {
    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 res = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int dy = 0, dx = 0;
        int ch = h[i + dy], cw = w[j + dx];
        while (i + dy < n && j + dx < m) {
          if (ch == cw) {
            res++;
          }
          if (ch < cw) {
            dy++;
            ch += h[i + dy];
          } else {
            dx++;
            cw += w[j + dx];
          }
        }
      }
    }
    cout << res << endl;
  }
}

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

#define int long long
signed main() {
  int n, m;
  while (cin >> n >> m, n != 0) {
    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];
    }
    vector<int> hs(1500 * 1000 + 10, 0);
    for (int i = 0; i < n; i++) {
      int s = 0;
      for (int j = i; j < n; j++) {
        s += h[j];
        hs[s]++;
      }
    }
    int res = 0;
    for (int i = 0; i < m; i++) {
      int s = 0;
      for (int j = i; j < m; j++) {
        s += w[j];
        res += hs[s];
      }
    }
    cout << res << endl;
  }
}


#include <bits/stdc++.h>

using namespace std;

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

int dp[1510];
int h[1510], w[1510];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M, N * M) {
    rep(i, 1510) dp[i] = 0;
    h[0] = w[0] = 0;
    REP(i, 1, N + 1) cin >> h[i];
    REP(i, 1, M + 1) cin >> w[i];
    int ans = 0;
    REP(n, 1, N + 1) {
      REP(m, 1, M + 1) {
        int p = 0, q = 0;
        for (int i = n; i > 0; i--) {
          p += h[i];
          for (int j = m; j > 0; j--) {
            q += w[j];
            if (p == q)
              ans++;
            else if (q > p)
              break;
          }
          q = 0;
        }
      }
    }
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>

using namespace std;

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

int h[1501], w[1501];
int H[2000000], W[2000000];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M, N * M) {
    memset(H, 0, 2000000);
    memset(W, 0, 2000000);
    rep(i, N) cin >> h[i];
    rep(i, M) cin >> w[i];
    rep(i, N) {
      int l = 0;
      REP(j, i, N) {
        l += h[j];
        H[l]++;
      }
    }
    rep(i, M) {
      int l = 0;
      REP(j, i, M) {
        l += w[j];
        W[l]++;
      }
    }
    int ans = 0;
    rep(i, 2000000) ans += H[i] * W[i];
    cout << ans << endl;
  }
}


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

int main() {
  int N, M;
  int height[1505];
  int width[1505];
  int H[1500001];
  int W[1500001];
  int max_h, max_w;
  int sum;
  int cnt;
  while (cin >> N >> M) {
    if (N == 0 && M == 0)
      break;
    max_h = max_w = 0;
    for (int i = 0; i < N; i++) {
      scanf("%d", &height[i]);
      max_h += height[i];
    }
    for (int i = 0; i < M; i++) {
      scanf("%d", &width[i]);
      max_w += width[i];
    }
    for (int i = 0; i < N; i++) {
      sum = 0;
      for (int j = i; j < N; j++) {
        sum += height[j];
        H[sum]++;
      }
    }
    for (int i = 0; i < M; i++) {
      sum = 0;
      for (int j = i; j < M; j++) {
        sum += width[j];
        W[sum]++;
      }
    }
    cnt = 0;
    for (int i = 0; i <= (max_h > max_w) ? max_h : max_w; i++) {
      cnt += H[i] * W[i];
      H[i] = W[i] = 0;
    }
    cout << cnt << endl;
  }
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x % (mod))
using namespace std;

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

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool debug = false;
/*---------------------------------------------------*/

int n, m;
ll ans;
int wide[1500001], hight[1500001];
int w[1505], h[1505];

void enumerate_hight() {
  int sum;
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = i; j < n; j++) {
      sum += h[j];
      hight[sum]++;
    }
  }
}

void enumerate_wide() {
  int sum;
  for (int i = 0; i < m; i++) {
    sum = 0;
    for (int j = i; j < m; j++) {
      sum += w[j];
      wide[sum]++;
    }
  }
}

void solve() {
  ll max_w = 0, max_h = 0, maxi;
  ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
    max_h += h[i];
  }
  enumerate_hight();
  for (int i = 0; i < m; i++) {
    scanf("%d", &w[i]);
    max_w += w[i];
  }
  enumerate_wide();
  maxi = max(max_w, max_h);
  rep(i, maxi + 1) {
    ans += wide[i] * hight[i];
    wide[i] = hight[i] = 0;
  }
  cout << ans << endl;
}

int main() {
  while (scanf("%d%d", &n, &m)) {
    if (n == 0 && m == 0)
      break;
    solve();
  }
}


#include <bits/stdc++.h>

using namespace std;

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

  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    std::vector<int> h, w;
    for (int i = 0; i < n; i++) {
      int he;
      cin >> he;
      h.push_back(he);
    }
    for (int i = 0; i < m; i++) {
      int wi;
      cin >> wi;
      w.push_back(wi);
    }
    multiset<int> hsum, wsum;
    for (int i = 0; i < n; i++) {
      int tmp = 0;
      for (int j = i; j < n; j++) {
        tmp += h[j];
        hsum.insert(tmp);
      }
    }
    for (int i = 0; i < m; i++) {
      int tmp = 0;
      for (int j = i; j < m; j++) {
        tmp += w[j];
        wsum.insert(tmp);
      }
    }
    int res = 0;
    for (int i = 0; i < hsum.size(); i++) {
      auto itr = hsum.begin();
      for (int j = 0; j < i; j++)
        itr++;
      res += wsum.count(*itr);
    }
    cout << res << endl;
  }
}

#include <bits/stdc++.h>

using namespace std;

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

  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    int h[1024 * 1500] = {0}, w[1024 * 1500] = {0};
    int tmp_h[n + 1], tmp_w[m + 1];
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i++) {
      cin >> tmp_h[i];
      sum1 += tmp_h[i];
      // cout<<tmp_h[i]<<endl;
    }
    for (int i = 0; i < m; i++) {
      cin >> tmp_w[i];
      sum2 += tmp_w[i];
      // cout<<tmp_w[i]<<endl;
    }
    for (int i = 0; i < n; i++) {
      int tmp = 0;
      for (int j = i; j < n; j++) {
        tmp += tmp_h[j];
        h[tmp]++;
      }
    }
    for (int i = 0; i < m; i++) {
      int tmp = 0;
      for (int j = i; j < m; j++) {
        tmp += tmp_w[j];
        w[tmp]++;
      }
    }
    long long res = 0;
    for (int i = 1; i <= min(sum1, sum2); i++) {
      res += h[i] * w[i];
    }
    cout << res << endl;
  }
}


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

#define rep(i, x, y) for (int(i) = (x); (i) < (y); (i)++)

int main() {

  while (true) {
    vector<int> X, Y;
    vector<int> lengthX, lengthY;
    int x, y;
    int n, m;
    int sumx, sumy;
    int count = 0;

    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }

    rep(i, 0, n) {
      cin >> y;
      Y.push_back(y);
    }
    rep(i, 0, m) {
      cin >> x;
      X.push_back(x);
    }

    rep(i, 0, n) {
      sumy = 0;
      rep(j, i, n) {
        sumy += Y[j];
        lengthY.push_back(sumy);
      }
    }
    rep(i, 0, m) {
      sumx = 0;
      rep(j, i, m) {
        sumx += X[j];
        lengthX.push_back(sumx);
      }
    }
    // sort(lengthX.begin(), lengthX.end());
    // sort(lengthY.begin(), lengthY.end());

    rep(i, 0, lengthX.size()) {
      rep(j, 0, lengthY.size()) {
        if (lengthX[i] == lengthY[j]) {
          count++;
        }
      }
    }

    cout << count << endl;
  }

  return 0;
}

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

#define rep(i, x, y) for (int(i) = (x); (i) < (y); (i)++)

int main() {

  while (true) {
    vector<int> X, Y;
    vector<int> lengthX, lengthY;
    int x, y;
    int n, m;
    int sumx, sumy;
    int count = 0;

    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }

    rep(i, 0, n) {
      cin >> y;
      Y.push_back(y);
    }
    rep(i, 0, m) {
      cin >> x;
      X.push_back(x);
    }

    rep(i, 0, n) {
      sumy = 0;
      rep(j, i, n) {
        sumy += Y[j];
        lengthY.push_back(sumy);
      }
    }
    rep(i, 0, m) {
      sumx = 0;
      rep(j, i, m) {
        sumx += X[j];
        lengthX.push_back(sumx);
      }
    }
    sort(lengthX.begin(), lengthX.end());
    sort(lengthY.begin(), lengthY.end());

    int i = 0;
    int j = 0;
    while (i < lengthY.size() && j < lengthX.size()) {
      if (lengthY[i] < lengthX[j]) {
        i++;
      } else if (lengthY[i] > lengthX[j]) {
        j++;
      } else {
        int k = j + 1;
        while (k < lengthX.size()) {
          if (lengthX[k] != lengthX[j]) {
            break;
          }
          k++;
        }
        count += k - j;
        i++;
      }
    }

    cout << count << endl;
  }

  return 0;
}


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

int main() {
  int N, M, l, count, N_s, M_s;
  vector<int> N_n, M_n;
  while (cin >> N >> M, N) {
    for (int i = 0; i < N; i++) {
      count = 0;
      cin >> l;
      N_n.push_back(l);
    }
    for (int i = 0; i < M; i++) {
      cin >> l;
      M_n.push_back(l);
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        for (int k = i, N_s = 0; k < N; k++) {
          N_s += N_n[k];
          for (l = j, M_s = 0; l < M; l++) {
            M_s += M_n[l];
            if (N_s == M_s) {
              count++;
              break;
            }
          }
        }
      }
    }
    cout << count << endl;
    N_n.clear();
    M_n.clear();
  }
  return 0;
}

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

int main() {
  int N, M, p, count;
  vector<int> N_n(1500000, 0), M_n(1500000, 0);
  vector<int> N_s, M_s;
  while (cin >> N >> M, N) {
    count = 0;
    for (int i = 0; i < N; i++) {
      cin >> p;
      N_s.push_back(p);
    }
    for (int i = 0; i < M; i++) {
      cin >> p;
      M_s.push_back(p);
    }
    for (int i = 0; i < N; i++) {
      p = 0;
      for (int j = i; j < N; j++) {
        p += N_s[j];
        N_n[p - 1]++;
      }
    }
    for (int i = 0; i < M; i++) {
      p = 0;
      for (int j = i; j < M; j++) {
        p += M_s[j];
        M_n[p - 1]++;
      }
    }
    for (int i = 0; i < 1500000; i++) {
      count += M_n[i] * N_n[i];
      if (M_n[i] != 0 || N_n[i] != 0)
        M_n[i] = N_n[i] = 0;
    }
    cout << count << endl;
    N_s.clear();
    M_s.clear();
  }
  return 0;
}


#include <iostream>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++)

int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    int count = 0;
    int h[1501], w[1501];
    REP(i, 0, N) cin >> h[i];
    REP(i, 0, M) cin >> w[i];

    REP(i, 0, N) {
      REP(j, 0, M) {
        int sh = 0;
        REP(k, i, N) {
          sh += h[k];

          int sw = 0;
          REP(l, j, M) {
            sw += w[l];

            if (sh == sw) {
              count++;
              break;
            } else if (sh < sw)
              break;
          }
        }
      }
    }

    cout << count << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++)
#define MAX 1501 * 1001 + 1

int ch[MAX], cw[MAX];
int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    int count = 0;
    int h[1501], w[1501];
    REP(i, 0, N) cin >> h[i];
    REP(i, 0, M) cin >> w[i];

    REP(i, 0, MAX) {
      ch[i] = 0;
      cw[i] = 0;
    }
    REP(i, 0, N) {
      int sh = 0;
      REP(j, i, N) {
        sh += h[j];
        ch[sh]++;
      }
    }
    REP(i, 0, M) {
      int sw = 0;
      REP(j, i, M) {
        sw += w[j];
        cw[sw]++;
      }
    }
    REP(i, 0, MAX) count += ch[i] * cw[i];

    cout << count << endl;
  }
  return 0;
}


///
// File:  2015.cpp
// Author: ymiyamoto
//
// Created on Sat Dec  2 23:41:55 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main() {
  while (true) {
    uint32_t N, M;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;

    vector<uint64_t> heights;
    heights.push_back(0);
    for (uint32_t i = 1; i <= N; i++) {
      uint32_t h;
      cin >> h;
      h += heights[i - 1];
      heights.push_back(h);
    }

    vector<uint64_t> widths;
    widths.push_back(0);
    for (uint32_t i = 1; i <= M; i++) {
      uint32_t w;
      cin >> w;
      w += widths[i - 1];
      widths.push_back(w);
    }

    vector<uint64_t> hs;
    for (uint32_t i = 0; i < heights.size(); i++) {
      for (uint32_t j = i + 1; j < heights.size(); j++) {
        hs.push_back(heights[j] - heights[i]);
      }
    }

    vector<uint64_t> ws;
    for (uint32_t i = 0; i < widths.size(); i++) {
      for (uint32_t j = i + 1; j < widths.size(); j++) {
        ws.push_back(widths[j] - widths[i]);
      }
    }

    uint32_t count = 0;
    for (uint32_t i = 0; i < hs.size(); i++) {
      for (uint32_t j = 0; j < ws.size(); j++) {
        if (hs[i] == ws[j]) {
          count++;
        }
      }
    }

    cout << count << endl;
  }

  return 0;
}

///
// File:  2015.cpp
// Author: ymiyamoto
//
// Created on Sat Dec  2 23:41:55 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main() {
  while (true) {
    uint32_t N, M;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;

    vector<uint64_t> heights;
    heights.push_back(0);
    for (uint32_t i = 1; i <= N; i++) {
      uint32_t h;
      cin >> h;
      h += heights[i - 1];
      heights.push_back(h);
    }

    vector<uint64_t> widths;
    widths.push_back(0);
    for (uint32_t i = 1; i <= M; i++) {
      uint32_t w;
      cin >> w;
      w += widths[i - 1];
      widths.push_back(w);
    }

    vector<uint64_t> hs;
    for (uint32_t i = 0; i < heights.size(); i++) {
      for (uint32_t j = i + 1; j < heights.size(); j++) {
        hs.push_back(heights[j] - heights[i]);
      }
    }

    vector<uint64_t> ws;
    for (uint32_t i = 0; i < widths.size(); i++) {
      for (uint32_t j = i + 1; j < widths.size(); j++) {
        ws.push_back(widths[j] - widths[i]);
      }
    }

    sort(ws.begin(), ws.end());
    uint64_t count = 0;
    for (uint32_t i = 0; i < hs.size(); i++) {
      count += upper_bound(ws.begin(), ws.end(), hs[i]) -
               lower_bound(ws.begin(), ws.end(), hs[i]);
    }

    cout << count << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define M 1500 * 1000

int h_pos[M + 1];
int w_pos[M + 1];

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<int> h(n, 0), w(n, 0);
    memset(h_pos, 0, sizeof(h_pos));
    memset(w_pos, 0, sizeof(h_pos));
    for (int i = 0; i < n; ++i) {
      cin >> h[i];
    }
    for (int i = 0; i < m; ++i) {
      cin >> w[i];
    }

    for (int i = 0; i < n; ++i) {
      int sum = 0;
      for (int j = i; j < n; ++j) {
        sum += h[j];
        h_pos[sum]++;
      }
    }
    for (int i = 0; i < m; ++i) {
      int sum = 0;
      for (int j = i; j < m; ++j) {
        sum += w[j];
        w_pos[sum]++;
      }
    }
    int cnt = 0;
    for (int i = 0; i <= M; ++i) {
      cnt += h_pos[i] * w_pos[i];
    }
    cout << cnt << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define M 1500 * 1000

int h_pos[M + 1];
int w_pos[M + 1];

int main() {
  int n, m;
  while (cin >> n >> m, n | m) {
    vector<int> h(n), w(m);
    memset(h_pos, 0, sizeof(h_pos));
    memset(w_pos, 0, sizeof(w_pos));
    for (int i = 0; i < n; ++i) {
      cin >> h[i];
    }
    for (int i = 0; i < m; ++i) {
      cin >> w[i];
    }

    for (int i = 0; i < n; ++i) {
      int sum = 0;
      for (int j = i; j < n; ++j) {
        sum += h[j];
        h_pos[sum]++;
      }
    }
    for (int i = 0; i < m; ++i) {
      int sum = 0;
      for (int j = i; j < m; ++j) {
        sum += w[j];
        w_pos[sum]++;
      }
    }
    int cnt = 0;
    for (int i = 0; i <= M; ++i) {
      cnt += h_pos[i] * w_pos[i];
    }
    cout << cnt << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int n, m;
vector<int> h;
vector<int> w;
bool grid[1503][1503];

void solve() {
  rep(i, 1503) rep(j, 1503) grid[i][j] = false;
  int add = 0;
  h.push_back(0);
  w.push_back(0);
  rep(i, n) {
    int a;
    cin >> a;
    add += a;
    h.push_back(add);
  }
  add = 0;
  rep(i, m) {
    int a;
    cin >> a;
    add += a;
    w.push_back(add);
  }
  sort(h.begin(), h.end());
  sort(w.begin(), w.end());
  rep(i, h.size()) rep(j, w.size()) grid[h[i]][w[j]] = true;
  int ans = 0;

  rep(i, h.size()) rep(j, w.size()) {
    if (grid[h[i]][w[j]]) {
      rep(k, w.size()) {
        if (w[j] >= w[k])
          continue;
        int t = w[k] - w[j];
        if (grid[h[i] + t][w[k]])
          ans++;
      }
    }
  }
  cout << ans << endl;
  w.clear();
  h.clear();
}

int main() {
  while (cin >> n >> m) {
    if (n + m == 0)
      return 0;
    solve();
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int n, m;
vector<int> y;
vector<int> x;

void solve() {
  map<int, int> line;
  int add = 0;
  y.push_back(0);
  x.push_back(0);
  rep(i, n) {
    int a;
    cin >> a;
    add += a;
    y.push_back(add);
  }
  add = 0;
  rep(i, m) {
    int a;
    cin >> a;
    add += a;
    x.push_back(add);
  }
  rep(i, y.size()) rep(j, x.size()) line[y[i] - x[j]]++;

  int ans = 0;
  map<int, int>::iterator it = line.begin();
  while (it != line.end()) {
    ans += it->second * (it->second - 1) / 2;

    it++;
  }

  cout << ans << endl;
  y.clear();
  x.clear();
}

int main() {
  while (cin >> n >> m) {
    if (n + m == 0)
      return 0;
    solve();
  }

  return 0;
}


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

int getdist(int data[], int n1, int n2) {
  int sum = 0;
  for (int i = n1; i < n2 + 1; i++) {
    sum += data[i];
  }
  return sum;
}
int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    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];
    multiset<int> hset;
    multiset<int> wset;
    set<int> edge;
    for (int i1 = 0; i1 < N; i1++) {
      for (int i2 = i1; i2 < N; i2++) {
        int t = getdist(h, i1, i2);
        edge.insert(t);
        hset.insert(t);
      }
    }
    for (int j1 = 0; j1 < M; j1++) {
      for (int j2 = j1; j2 < M; j2++) {
        int t = getdist(w, j1, j2);
        edge.insert(t);
        wset.insert(t);
      }
    }
    set<int>::iterator itr = edge.begin();
    int ans = 0;
    while (itr != edge.end()) {
      ans += hset.count(*itr) * wset.count(*itr);
      ++itr;
    }
    cout << ans << endl;
  }
}

#include <iostream>
#include <vector>
using namespace std;
#define MAX_len 1500001

int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    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];
    vector<int> h_count(MAX_len), w_count(MAX_len);

    for (int i1 = 0; i1 < N; i1++) {
      int len = 0;
      for (int i2 = i1; i2 < N; i2++) {
        len += h[i2];
        h_count[len]++;
      }
    }
    for (int i1 = 0; i1 < M; i1++) {
      int len = 0;
      for (int i2 = i1; i2 < M; i2++) {
        len += w[i2];
        w_count[len]++;
      }
    }
    int ans = 0;
    for (int i = 1; i < MAX_len; i++) {
      ans += h_count[i] * w_count[i];
    }
    cout << ans << endl;
  }
}


#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M && N) {
    int h[1501] = {0}, w[1501] = {0}, allh[1501] = {0}, allw[1501] = {0};
    int ans = 0;
    REP(i, 0, N) {
      cin >> h[i];
      int k = 0;
      for (int j = i; j >= 0; j--) {
        k += h[j];
        allh[k]++;
      }
    }
    REP(i, 0, M) {
      cin >> w[i];
      int k = 0;
      for (int j = i; j >= 0; j--) {
        k += w[j];
        allw[k]++;
      }
    }
    REP(i, 1, 1501) { ans += allh[i] * allw[i]; }
    p(ans);
  }

  return 0;
}

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M && N) {
    int h[1501], w[1501];
    map<int, int> allh, allw;
    int ans = 0, mx = 0, k;
    REP(i, 0, N) {
      cin >> h[i];
      k = 0;
      for (int j = i; j >= 0; j--) {
        k += h[j];
        allh[k]++;
      }
    }
    mx = max(mx, k);
    REP(i, 0, M) {
      cin >> w[i];
      k = 0;
      for (int j = i; j >= 0; j--) {
        k += w[j];
        allw[k]++;
      }
    }
    mx = max(mx, k);
    REP(i, 1, mx + 1) { ans += allh[i] * allw[i]; }
    p(ans);
  }

  return 0;
}


#include <algorithm>
#include <array>
#include <iostream>

using namespace std;

int main() {
  array<int, 1501> y, x;
  int n, m;
  while (cin >> n >> m && n + m != 0) {
    y[0] = x[0] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> y[i];
      y[i] += y[i - 1];
    }
    for (int i = 1; i <= m; i++) {
      cin >> x[i];
      x[i] += x[i - 1];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int k = i + 1, l = j + 1;
        while (k <= n && l <= m) {
          int h = y[k] - y[i];
          int w = x[l] - x[j];
          if (h < w)
            k++;
          else if (h > w)
            l++;
          else
            cnt++, k++, l++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

#include <algorithm>
#include <array>
#include <iostream>

using namespace std;

int main() {
  array<int, 1501> x, y;
  array<int, 1500001> t;
  int n, m;
  while (cin >> n >> m && n + m != 0) {
    y[0] = x[0] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> y[i];
      y[i] += y[i - 1];
    }
    for (int i = 1; i <= m; i++) {
      cin >> x[i];
      x[i] += x[i - 1];
    }
    fill(t.begin(), t.begin() + max(n, m) * 1000, 0);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++)
        t[y[j] - y[i]]++;
    }
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j <= m; j++)
        cnt += t[x[j] - x[i]];
    }
    cout << cnt << endl;
  }
  return 0;
}


#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef pair<int, int> P;

void debug(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

// ツ青板療アツづ茎[i]ツつゥツづァs[j]ツづ個堕債和ツづーツ陛板つキ. (a[i] :=
// s[i] + s[i+1] + ... + s[n-1])
int sum(vector<int> a, int i, int j) { return a[i] - a[j + 1]; }

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    // h,w : ツ禿シツ療?
    // H[i] := h[i] + h[i+1] + ... + h[n-1]
    // W[i] := w[i] + w[i+1] + ... + w[m-1]
    vector<int> h, w, H, W;

    int sum_h = 0;
    for (int i = 0; i < n; i++) {
      int e;
      cin >> e;
      h.push_back(e);
      sum_h += e;
    }
    H.push_back(sum_h);
    for (int i = 0; i < h.size(); i++) {
      H.push_back(H[i] - h[i]);
    }
    H.push_back(0);

    int sum_w = 0;
    for (int i = 0; i < m; i++) {
      int e;
      cin >> e;
      w.push_back(e);
      sum_w += e;
    }
    W.push_back(sum_w);
    for (int i = 0; i < w.size(); i++) {
      W.push_back(W[i] - w[0]);
    }
    W.push_back(0);

    // ツ連ツ堕アツつキツづゥ cnt ツ古つづ個堕債和ツづーツ仰?づ淞づゥ
    for (int cnt = 2; cnt <= n; cnt++) {
      // h[i] .. h[i+cnt-1] ツづ個堕債和
      for (int i = 0; i <= n - cnt; i++) {
        h.push_back(sum(H, i, i + cnt - 1));
      }
    }
    // ツ連ツ堕アツつキツづゥ cnt ツ古つづ個堕債和ツづーツ仰?づ淞づゥ
    for (int cnt = 2; cnt <= m; cnt++) {
      // w[i] .. w[i+cnt-1] ツづ個堕債和
      for (int i = 0; i <= m - cnt; i++) {
        w.push_back(sum(W, i, i + cnt - 1));
      }
    }
    // debug( h );
    // debug( w );

    // sort( h.begin() , h.end() );
    // sort( w.begin() , w.end() );
    //  A[i] := hツづ個陳?づ?値 i ツづ個古つ青?
    // map<int,int> A;
    /*for(int i=0 ; i < h.size() ; i++ ){
            if( A.count(h[i]) ){
                    A[ h[i] ]++;
            }else{
                    A[ h[i] ] = 1;
            }
    }
    h.erase( unique( h.begin() , h.end()) , h.end() );
    // B[i] := wツづ個陳?づ?値 i ツづ個古つ青?
    map<int,int> B;
    for(int i=0 ; i < w.size() ; i++ ){
            if( B.count(w[i]) ){
                    B[ w[i] ]++;
            }else{
                    B[ w[i] ] = 1;
            }
    }
    w.erase( unique( w.begin() , w.end()) , w.end() );
    */
    int ans = 0;

    /*for(int i=0 ; i < h.size() ; i++ ){
            int k = h[i];
            if( binary_search( w.begin() , w.end() , k ) ){
                    int cnt = upper_bound(w.begin() , w.end() , k) -
    lower_bound(w.begin() , w.end() , k);
                    // cout << "A[" << h[i] << "] = " << A[ h[i] ];
                    // cout << " B[" << w[j] << "] = " << B[ w[j] ] << endl;;
                    ans += A[ h[i] ] * cnt;
            }
    }*/
    cout << ans << endl;
  }
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void debug(const vector<int> &v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

// ツ青板療アツづ茎[i]ツつゥツづァs[j]ツづ個堕債和ツづーツ陛板つキ. (a[i] :=
// s[i] + s[i+1] + ... + s[n-1])
int sum(const vector<int> &a, int i, int j) { return a[i] - a[j + 1]; }

int main() {
  int n, m;
  // while( cin >> n >> m , n || m ){
  while (scanf("%d %d", &n, &m), n || m) {
    // h,w : ツ禿シツ療?
    // H[i] := h[i] + h[i+1] + ... + h[n-1]
    // W[i] := w[i] + w[i+1] + ... + w[m-1]
    vector<int> h(n), w(m), H(n + 1), W(m + 1);

    int sum_h = 0;
    for (int i = 0; i < n; i++) {
      int e;
      scanf("%d", &e);
      h[i] = e;
      sum_h += h[i];
    }
    H[0] = sum_h;
    for (int i = 0; i < h.size(); i++) {
      H[i + 1] = H[i] - h[i];
    }

    int sum_w = 0;
    for (int i = 0; i < m; i++) {
      int e;
      scanf("%d", &e);
      w[i] = e;
      sum_w += w[i];
    }
    W[0] = sum_w;
    for (int i = 0; i < w.size(); i++) {
      W[i + 1] = W[i] - w[i];
    }

    // ツ連ツ堕アツつキツづゥ cnt ツ古つづ個堕債和ツづーツ仰?づ淞づゥ
    for (int cnt = 2; cnt <= n; cnt++) {
      // h[i] .. h[i+cnt-1] ツづ個堕債和
      for (int i = 0; i <= n - cnt; i++) {
        h.push_back(sum(H, i, i + cnt - 1));
      }
    }
    // ツ連ツ堕アツつキツづゥ cnt ツ古つづ個堕債和ツづーツ仰?づ淞づゥ
    for (int cnt = 2; cnt <= m; cnt++) {
      // w[i] .. w[i+cnt-1] ツづ個堕債和
      for (int i = 0; i <= m - cnt; i++) {
        w.push_back(sum(W, i, i + cnt - 1));
      }
    }
    // debug( h );
    // debug( w );

    sort(h.begin(), h.end());
    sort(w.begin(), w.end());

    int ans = 0;
    for (int i = 0; i < h.size(); i++) {
      int k1 = h[i];
      int k2 = upper_bound(w.begin(), w.end(), k1) -
               lower_bound(w.begin(), w.end(), k1);
      ans += k2;
    }
    printf("%d\\n", ans);
  }
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a, c) memset(a, c, sizeof(a))

#define DEBUG(x)                                                               \\
  cout << "#x"                                                                 \\
       << ": " << x << endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX / 3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int vecCount(vector<int> v, int key) {
  int ret = 0;
  int h = lower_bound(ALL(v), key) - v.begin();
  int t = upper_bound(ALL(v), key) - v.begin();
  if (v[h] != key)
    ret = 0;
  else
    ret = t - h;
  return ret;
}

int main() {

  while (true) {
    int n, m;
    int ans = 0;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vi h(n), w(m);
    vector<int> widths(m * (m + 1) / 2);
    int index = 0;
    REP(i, n) scanf("%d", &h[i]);
    REP(i, m) scanf("%d", &w[i]);
    REP(i, m) {
      widths.PB(w[i]);
      int sum = w[i];
      FOR(j, i + 1, m) {
        sum += w[j];
        widths[index] = sum;
        index++;
      }
    }
    sort(ALL(widths));

    REP(i, n) {
      int sum = h[i];
      ans += vecCount(widths, sum);
      FOR(j, i + 1, n) {
        sum += h[j];
        ans += vecCount(widths, sum);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a, c) memset(a, c, sizeof(a))

#define DEBUG(x)                                                               \\
  cout << "#x"                                                                 \\
       << ": " << x << endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX / 3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int widths[1500 * 1500];
int len = 0;

int vecCount(int key) {
  int ret = 0;
  int h = lower_bound(widths, widths + len, key) - widths;
  int t = upper_bound(widths, widths + len, key) - widths;
  if (widths[h] != key)
    ret = 0;
  else
    ret = t - h;
  return ret;
}

int main() {

  while (true) {
    int n, m;
    int ans = 0;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vi h(n), w(m);
    int index = 0;
    REP(i, n) scanf("%d", &h[i]);
    REP(i, m) scanf("%d", &w[i]);
    REP(i, m) {
      widths[index] = w[i];
      index++;
      int sum = w[i];
      FOR(j, i + 1, m) {
        sum += w[j];
        widths[index] = sum;
        index++;
      }
    }
    len = index;
    sort(widths, widths + len);

    REP(i, n) {
      int sum = h[i];
      ans += vecCount(sum);
      FOR(j, i + 1, n) {
        sum += h[j];
        ans += vecCount(sum);
      }
    }
    cout << ans << endl;
  }

  return 0;
}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define pb push_back
#define dump(x) cout << " " << #x << " = " << (x) << endl;
typedef long long ll;
typedef complex<int> P;
const double EPS = 1e-10;
const double PI = acos(-1.0);

bool solve() {
  int n, m;
  cin >> n >> m;
  if (n == 0 && m == 0)
    return false;

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

  vector<int> W, H;
  for (int i = 0; i < n; i++) {
    int x = w[i];
    W.pb(x);
    for (int j = i + 1; j < n; j++) {
      x += w[j];
      W.pb(x);
    }
  }
  for (int i = 0; i < m; i++) {
    int x = h[i];
    H.pb(x);
    for (int j = i + 1; j < m; j++) {
      x += h[j];
      H.pb(x);
    }
  }

  int ans = 0;
  for (int i = 0; i < W.size(); i++) {
    for (int j = 0; j < H.size(); j++) {
      if (W[i] == H[j])
        ans++;
    }
  }
  cout << ans << endl;

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);

  while (solve())
    ;
  return 0;
}

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define pb push_back
#define dump(x) cout << " " << #x << " = " << (x) << endl;
typedef long long ll;
typedef complex<int> P;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dmax = 1500 * 1000 + 10; //
int a[dmax] = {0};                 //

bool solve() {
  int n, m;
  cin >> n >> m;
  if (n == 0 && m == 0)
    return false;

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

  vector<int> W, H;
  for (int i = 0; i < n; i++) {
    int x = w[i];
    W.pb(x);
    for (int j = i + 1; j < n; j++) {
      x += w[j];
      W.pb(x);
    }
  }
  for (int i = 0; i < m; i++) {
    int x = h[i];
    H.pb(x);
    for (int j = i + 1; j < m; j++) {
      x += h[j];
      H.pb(x);
    }
  }

  int ans = 0;
  memset(a, 0, sizeof(a));
  for (int i = 0; i < W.size(); i++) {
    a[W[i]]++;
  }
  for (int j = 0; j < H.size(); j++) {
    ans += a[H[j]];
  }
  cout << ans << endl;

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);

  while (solve())
    ;
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;
int main(void) {
  int n, m, t;
  while (cin >> n >> m && n) {
    vector<int> h, w;
    h.push_back(0);
    w.push_back(0);
    for (int i = 0; i < n; i++) {
      cin >> t;
      h.push_back(h[i] + t);
    }
    for (int i = 0; i < m; i++) {
      cin >> t;
      w.push_back(w[i] + t);
    }

    vector<int> a, b;
    for (int i = 0; i < h.size() - 1; i++) {
      for (int j = i + 1; j < h.size(); j++) {
        t = h[j] - h[i];
        a.push_back(t);
      }
    }
    for (int i = 0; i < w.size() - 1; i++) {
      for (int j = i + 1; j < w.size(); j++) {
        t = w[j] - w[i];
        b.push_back(t);
      }
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    // for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl;

    int bi = 0, ans = 0;
    for (int ai = 0; ai < a.size(); ai++) {
      int c = 1;
      while (1) {
        if (a[ai] == a[ai + 1] && ai + 1 < a.size()) {
          ai++;
          c++;
        } else
          break;
      }
      while (1) {
        if (b[bi] < a[ai])
          bi++;
        else
          break;
      }
      if (a[ai] == b[bi]) {
        int d = 1;
        while (1) {
          if (b[bi] == b[bi + 1] && bi + 1 < b.size()) {
            bi++;
            d++;
          } else
            break;
        }
        ans += c * d;
      }
    }
    cout << ans << endl;
  }
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;
int main(void) {
  int n, m, t;
  while (cin >> n >> m && n) {
    vector<int> h, w;
    h.push_back(0);
    w.push_back(0);
    for (int i = 0; i < n; i++) {
      cin >> t;
      h.push_back(h[i] + t);
    }
    for (int i = 0; i < m; i++) {
      cin >> t;
      w.push_back(w[i] + t);
    }

    vector<int> a, b;
    for (int i = 0; i < h.size() - 1; i++) {
      for (int j = i + 1; j < h.size(); j++) {
        t = h[j] - h[i];
        a.push_back(t);
      }
    }
    for (int i = 0; i < w.size() - 1; i++) {
      for (int j = i + 1; j < w.size(); j++) {
        t = w[j] - w[i];
        b.push_back(t);
      }
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    // for (int i = 0; i < h.size(); i++) cout << h[i] << " "; cout << endl;
    // for (int i = 0; i < w.size(); i++) cout << w[i] << " "; cout << endl;
    // for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl;
    // for (int i = 0; i < b.size(); i++) cout << b[i] << " "; cout << endl;

    int bi = 0, ans = 0;
    for (int ai = 0; ai < a.size(); ai++) {
      int c = 1;
      while (1) {
        if (a[ai] == a[ai + 1] && ai + 1 < a.size()) {
          ai++;
          c++;
        } else
          break;
      }
      while (1) {
        if (b[bi] < a[ai] && bi + 1 < b.size())
          bi++;
        else
          break;
      }
      if (a[ai] == b[bi]) {
        int d = 1;
        while (1) {
          if (b[bi] == b[bi + 1] && bi + 1 < b.size()) {
            bi++;
            d++;
          } else
            break;
        }
        // printf("a[ai]=%d b[bi]=%d ans+=%d*%d\\n",a[ai],b[bi],c,d);
        ans += c * d;
      }
    }
    cout << ans << endl;
  }
}


#include <iostream>
using namespace std;

int main() {
  int n, m;
  for (; cin >> n >> m, n;) {
    int h[n];
    int w[m];
    for (int i = 0; i < n; i++)
      cin >> h[i];
    for (int i = 0; i < m; i++)
      cin >> w[i];
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        // 左上固定の尺取
        int ii = i, jj = j;
        int isum = h[i];
        int jsum = w[j];
        while (ii < n && jj < m) {
          if (isum == jsum) {
            cnt++;
            //                      break;
            ii++;
            jj++;

            if (jj < m)
              jsum += w[j];
            if (ii < n)
              isum += h[j];
          }
          if (isum > jsum) {
            jj++;
            if (jj < m)
              jsum += w[j];
          }
          if (isum < jsum) {
            ii++;
            if (ii < n)
              isum += h[j];
          }
        }
      }
    }

    cout << cnt << endl;
  }
}

#include <iostream>
#include <map>
using namespace std;
int main() {
  int n, m;
  for (; cin >> n >> m, n;) {
    int h[n + 1];
    map<int, int> hash;

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

      if (i != 0) {
        h[i] += h[i - 1];
        hash[h[i]]++;
        //  cerr<<"{SS}"<<hash[h[i]]<<" "<<h[i]<<endl;
        for (int ii = i - 1; ii >= 0; ii--) {
          {
            hash[h[i] - h[ii]]++;
            //        cerr<<"{N}"<<hash[h[i]-h[ii]]<<" "<<h[i]-h[ii]<<endl;
          }
        }
      } else {
        hash[h[i]]++;
        //      cerr<<"{S}"<<hash[h[i]]<<" "<<h[i]<<endl;
      }
    }
    int ans = 0;
    int w[m + 1];

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

      if (i != 0) {
        w[i] += w[i - 1];
        ans += hash[w[i]];
        for (int ii = i - 1; ii >= 0; ii--) {
          ans += hash[w[i] - w[ii]];
        }
      } else {
        ans += hash[w[i]];
      }
    }
    cout << ans << endl;
  }

  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int INF = 1111111111;
const int M = 3000000;
int n, m, h[3000], w[3000], seg[8192], s, tn;
void init(int _n) {
  s = 1;
  while (s < _n)
    s *= 2;
  for (int i = 0; i < s * 2 - 1; i++)
    seg[i] = 0;
}
void upgrade(int k, int a) { // k???????????????a????????´
  k += tn - 1;
  seg[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    seg[k] = seg[k * 2 + 1] + seg[k * 2 + 2];
  }
}
// a???b???????¨????????±???????
//
int sum(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return 0;
  if (a <= l && r <= b) {
    ;
    return seg[k];
  } else {
    int vl = sum(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = sum(a, b, k * 2 + 2, (l + r) / 2, r);
    return vl + vr;
  }
}
int main() {

  while (cin >> n >> m, n || m) {
    tn = n + 1;
    map<int, int> ah, aw;
    ah.clear();
    aw.clear();
    for (int i = 0; i < n; i++)
      cin >> h[i];

    init(n);

    for (int i = 0; i < n; i++) {
      upgrade(i, h[i]);
    }

    for (int i = 0; i < n; i++)
      ah[h[i]]++;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        ah[sum(i, j, 0, 0, n)]++;
      }
    }
    // for(int i=0;i<1600;i++)if(ah[i]!=0)cout<<i<<" "<<ah[i]<<endl;

    for (int i = 0; i < m; i++)
      cin >> w[i];
    tn = m + 1;
    init(m);
    for (int i = 0; i < m; i++) {
      upgrade(i, w[i]);
    }
    for (int i = 0; i < m; i++)
      aw[w[i]]++;
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j < m; j++) {
        aw[sum(i, j, 0, 0, m)]++;
      }
    }
    int ans = 0;
    for (int i = 1; i <= 3000000; i++)
      ans += ah[i] * aw[i];
    cout << ans << endl;
  }
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int INF = 1111111111;
const int M = 3000000;
int n, m, h[3000], w[3000], seg[8192], s, tn, ah[3000000], aw[3000000];
void init(int _n) {
  s = 1;
  while (s < _n)
    s *= 2;
  for (int i = 0; i < s * 2 - 1; i++)
    seg[i] = 0;
}
void upgrade(int k, int a) { // k逡ェ逶ョ縺ョ蛟、繧誕縺ォ螟画峩
  k += s - 1;
  seg[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    seg[k] = seg[k * 2 + 1] + seg[k * 2 + 2];
  }
}
// a?枌縺ョ蜷郁ィ亥?繧呈アゅａ繧?//
int sum(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return 0;
  if (a <= l && r <= b) {
    return seg[k];
  } else {
    int vl = sum(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = sum(a, b, k * 2 + 2, (l + r) / 2, r);
    return vl + vr;
  }
}
int main() {

  while (cin >> n >> m, n || m) {
    tn = n;
    for (int i = 0; i < n; i++)
      cin >> h[i];

    init(n);

    for (int i = 0; i < n; i++) {
      upgrade(i, h[i]);
    }

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        ah[sum(i, j, 0, 0, s)]++;
      }
    }

    for (int i = 0; i < m; i++)
      cin >> w[i];
    tn = m;
    init(m);
    for (int i = 0; i < m; i++) {
      upgrade(i, w[i]);
    }

    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        aw[sum(i, j, 0, 0, s)]++;
      }
    }
    int ans = 0;
    for (int i = 1; i < 3000000; i++) {
      ans += ah[i] * aw[i];
    }
    cout << ans << endl;
    fill(ah, ah + 3000000, 0);
    fill(aw, aw + 3000000, 0);
  }
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
int main() {
  while (true) {
    int N, M, ans = 0;
    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 (int sh = 0; sh < N; sh++) {
      for (int sw = 0; sw < M; sw++) {
        int hval = h[sh], wval = w[sw];
        int i = sh, j = sw;
        while (i < N && j < M) {
          if (hval == wval) {
            ans++;
            hval += h[++i];
          } else if (hval < wval) {
            hval += h[++i];
          } else {
            wval += w[++j];
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
int main() {
  while (true) {
    int N, M, ans = 0;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    int h[N + 1], w[M + 1];
    h[0] = 0;
    w[0] = 0;
    int value;
    for (int i = 1; i <= N; i++) {
      cin >> value;
      h[i] = h[i - 1] + value;
    }
    for (int i = 1; i <= M; i++) {
      cin >> value;
      w[i] = w[i - 1] + value;
    }
    int val[1500000] = {};
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j <= N; j++) {
        val[abs(h[j] - h[i])]++;
      }
    }
    for (int i = 0; i < M; i++) {
      for (int j = i + 1; j <= M; j++) {
        if (abs(w[j] - w[i]) != 0)
          ans += val[abs(w[j] - w[i])];
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

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

using namespace std;
typedef long long ll;

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

    vector<int> H(n), W(m);
    rep(i, n) cin >> H[i];
    rep(i, m) cin >> W[i];

    vector<int> v;
    rep(i, n) {
      int sum = 0;
      REP(j, i, n) {
        sum += H[j];
        v.push_back(sum);
      }
    }

    vector<int> t;
    rep(i, m) {
      int sum = 0;
      REP(j, i, m) {
        sum += W[j];
        t.push_back(sum);
      }
    }

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

    cout << ans << endl;
  }

  return 0;
}

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

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

using namespace std;
typedef long long ll;

int memo[1500000];

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

    vector<int> H(n), W(m);
    rep(i, n) cin >> H[i];
    rep(i, m) cin >> W[i];

    vector<int> v;
    rep(i, n) {
      int sum = 0;
      REP(j, i, n) {
        sum += H[j];
        v.push_back(sum);
      }
    }

    vector<int> t;
    rep(i, m) {
      int sum = 0;
      REP(j, i, m) {
        sum += W[j];
        t.push_back(sum);
      }
    }

    memset(memo, 0, sizeof(memo));
    rep(i, t.size()) { memo[t[i]]++; }

    int ans = 0;
    rep(i, v.size()) { ans += memo[v[i]]; }

    cout << ans << endl;
  }

  return 0;
}


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

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<int> h;
    vector<int> w;
    vector<int> a(1500, 0);
    vector<int> o(1500, 0);
    int tmp;

    for (int i = 0; i < n; ++i) {
      cin >> tmp;
      h.push_back(tmp);
      int x = 0;
      for (int j = i; j >= 0; --j) {
        x += h[j];
        ++a[x - 1];
      }
    }

    for (int i = 0; i < m; ++i) {
      cin >> tmp;
      w.push_back(tmp);
      int x = 0;
      for (int j = i; j >= 0; --j) {
        x += w[j];
        ++o[x - 1];
      }
    }

    // int mi =
    // min(accumulate(h.begin(),h.end(),0),accumulate(w.begin(),w.end(),0));
    int ans = 0;
    for (int i = 0; i < 1500; ++i) {
      ans += a[i] * o[i];
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<int> h;
    vector<int> w;
    vector<int> a(1500000, 0);
    vector<int> o(1500000, 0);
    int tmp;

    for (int i = 0; i < n; ++i) {
      cin >> tmp;
      h.push_back(tmp);
      int x = 0;
      for (int j = i; j >= 0; --j) {
        x += h[j];
        ++a[x - 1];
      }
    }

    for (int i = 0; i < m; ++i) {
      cin >> tmp;
      w.push_back(tmp);
      int x = 0;
      for (int j = i; j >= 0; --j) {
        x += w[j];
        ++o[x - 1];
      }
    }

    int mi = min(accumulate(h.begin(), h.end(), 0),
                 accumulate(w.begin(), w.end(), 0));
    int ans = 0;
    for (int i = 0; i < mi; ++i) {
      ans += a[i] * o[i];
    }
    cout << ans << endl;
  }
  return 0;
}


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

#define pb push_back

using namespace std;

int main(void) {
  int n, m;
  int i1, i2;
  int sum;
  int c;

  while (1) {
    cin >> n >> m;
    if (n + m == 0)
      break;

    vector<int> h(n);
    vector<int> w(m);
    vector<int> hh, ww;
    for (i1 = 0; i1 < n; i1++) {
      cin >> h[i1];
      hh.pb(h[i1]);
    }
    for (i1 = 0; i1 < m; i1++) {
      cin >> w[i1];
      ww.pb(w[i1]);
    }

    for (i1 = 2; i1 <= n; i1++) {
      sum = 0;
      for (i2 = 0; i2 < i1; i2++)
        sum += h[i2];
      hh.pb(sum);
      for (i2; i2 < n; i2++) {
        sum += h[i2];
        sum -= h[i2 - i1];
        hh.pb(sum);
      }
    }

    for (i1 = 2; i1 <= n; i1++) {
      sum = 0;
      for (i2 = 0; i2 < i1; i2++)
        sum += w[i2];
      ww.pb(sum);
      for (i2; i2 < n; i2++) {
        sum += w[i2];
        sum -= w[i2 - i1];
        ww.pb(sum);
      }
    }

    c = 0;
    for (vector<int>::iterator it = hh.begin(); it != hh.end(); it++) {
      // cout<<(*it)<<" ";
      c += (static_cast<int>(count(ww.begin(), ww.end(), (*it))));
    }
    // cout<<endl;

    /*for(vector<int>::iterator it=ww.begin();it!=ww.end();it++){
            cout<<(*it)<<" ";
    }
    cout<<endl;*/

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

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

using namespace std;

int main(void) {
  int n, m;
  int i1, i2;
  int sum;
  int c;
  map<int, int>::iterator i;

  while (1) {
    cin >> n >> m;
    if (n + m == 0)
      break;

    vector<int> h(n);
    vector<int> w(m);
    map<int, int> hh, ww;
    for (i1 = 0; i1 < n; i1++)
      cin >> h[i1];
    for (i1 = 0; i1 < m; i1++)
      cin >> w[i1];

    for (i1 = 1; i1 <= n; i1++) {
      sum = 0;
      for (i2 = 0; i2 < i1; i2++)
        sum += h[i2];
      hh[sum]++;
      for (i2; i2 < n; i2++) {
        sum += h[i2];
        sum -= h[i2 - i1];
        hh[sum]++;
      }
    }

    for (i1 = 1; i1 <= m; i1++) {
      sum = 0;
      for (i2 = 0; i2 < i1; i2++)
        sum += w[i2];
      ww[sum]++;
      for (i2; i2 < m; i2++) {
        sum += w[i2];
        sum -= w[i2 - i1];
        ww[sum]++;
      }
    }

    c = 0;
    for (map<int, int>::iterator it = hh.begin(); it != hh.end(); it++) {
      // cout<<it->first<<" "<<it->second<<endl;
      i = ww.find(it->first);
      if (i != hh.end())
        c += (it->second * i->second);
    }
    // cout<<endl;

    /*for(map<int,int>::iterator it=ww.begin();it!=ww.end();it++){
            cout<<it->first<<" "<<it->second<<endl;
    }
    cout<<endl;*/

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


#include <algorithm>
#include <iostream>
#include <vector>
#define N1 1500
using namespace std;
int main() {
  int N, M, h[N1], w[N1];
  vector<int> H, W;
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> h[i];
      if (i > 0)
        h[i] += h[i - 1];
    }
    for (int i = 0; i < M; i++) {
      cin >> w[i];
      if (i > 0)
        w[i] += w[i - 1];
    }
    int l = 1;
    while (l != N + 1) {
      for (int i = l - 1; i < N; i++) {
        H.push_back(h[i] - h[i - l]);
      }
      l++;
    }
    l = 1;
    while (l != M + 1) {
      for (int i = l - 1; i < M; i++) {
        W.push_back(w[i] - w[i - l]);
      }
      l++;
    }
    sort(H.begin(), H.end());
    sort(W.begin(), W.end());
    int hcnt = 0, wcnt = 0, sum = 0, flag, k = 0;
    for (int i = 0; i < H.size(); i++) {
      hcnt = 1;
      while (H[i] == H[i + 1]) {
        hcnt++;
        i++;
      }
      wcnt = 0;
      flag = 0;
      for (int j = k; j < W.size(); j++) {
        if (H[i] == W[j]) {
          flag = 1;
          wcnt++;
          k = j + 1;
        } else if (flag == 1)
          break;
      }
      sum += hcnt * wcnt;
    }
    H.clear();
    W.clear();
    cout << sum << endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
#define N1 1501
#define N2 1000
using namespace std;
int dh[N1 * N2], dw[N1 * N2];
int main() {
  int N, M, h[N1], w[N1];
  vector<int> H, W;
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> h[i];
      if (i > 0)
        h[i] += h[i - 1];
    }
    for (int i = 0; i < M; i++) {
      cin >> w[i];
      if (i > 0)
        w[i] += w[i - 1];
    }
    for (int i = 0; i < N1 * N2; i++)
      dh[i] = dw[i] = 0;
    int l = 1;
    while (l != N + 1) {
      for (int i = l - 1; i < N; i++) {
        dh[h[i] - h[i - l]]++;
      }
      l++;
    }
    l = 1;
    while (l != M + 1) {
      for (int i = l - 1; i < M; i++) {
        dw[w[i] - w[i - l]]++;
      }
      l++;
    } /*
     sort(H.begin(),H.end());
     sort(W.begin(),W.end());
     for(int i=0;i<N1;i++){
       for(int j=0;j<N2;j++){
         dh[i][j]=dw[i][j]=0;
       }
     }
     H.clear();
     W.clear();
     */
    int sum = 0;
    for (int i = 0; i < N1 * N2; i++) {
      if (dh[i] != 0 && dw[i] != 0)
        sum += dh[i] * dw[i];
    }
    cout << sum << endl;
  }
  return 0;
}


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

using namespace std;

int combi(int n) { return n * (n - 1) / 2; }

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

    for (int i = 0; i < n; i++) {
      int h;
      cin >> h;
      h += y[i];
      y.push_back(h);
    }

    for (int i = 0; i < m; i++) {
      int w;
      cin >> w;
      w += x[i];
      y.push_back(w);
    }
    // y=x+b → y-x=bとなる
    map<int, int> cnt;
    for (int i = 0; i < n + 1; i++) {
      for (int j = 0; j < m + 1; j++) {
        int diff = y[i] - x[j];
        cnt[diff]++;
      }
    }

    // 全探索
    int ans = 0;
    for (int i = -x[m]; i < y[n] + 1; i++) {
      ans += combi(cnt[i]);
    }

    cout << ans << endl;
  }
}

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

using namespace std;

int combi(int n) { return n * (n - 1) / 2; }

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

    for (int i = 0; i < n; i++) {
      int h;
      cin >> h;
      h += y[i];
      y.push_back(h);
    }

    for (int i = 0; i < m; i++) {
      int w;
      cin >> w;
      w += x[i];
      x.push_back(w);
    }
    // y=x+b → y-x=bとなる
    map<int, int> cnt;
    for (int i = 0; i < n + 1; i++) {
      for (int j = 0; j < m + 1; j++) {
        int diff = y[i] - x[j];
        cnt[diff]++;
      }
    }

    // 全探索
    int ans = 0;
    for (int i = -x[m]; i < y[n] + 1; i++) {
      ans += combi(cnt[i]);
    }

    cout << ans << endl;
  }
}


#include <iostream>
using namespace std;

const int MAX_N = 1500, MAX_M = 1500, MAX_W = 1000;
int roadV[MAX_N], roadH[MAX_M];
int widthV[MAX_N * MAX_W + 1];
int widthH[MAX_M * MAX_W + 1];

int main() {
  ios_base::sync_with_stdio(0);
  int n, m, i, j, sumV, sumH, cnt;

  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (i = 0; i < n; i++)
      cin >> roadV[i];
    for (i = 0; i < n; i++)
      cin >> roadH[i];

    for (i = 1; i <= n * 1000; i++) {
      widthV[i] = 0;
      widthH[i] = 0;
    }

    for (i = 0; i < n - 1; i++) {
      sumV = 0;
      sumH = 0;
      for (j = i; j < n; j++) {
        sumV += roadV[i];
        sumH += roadH[i];

        widthV[sumV]++;
        widthH[sumH]++;
      }
    }

    cnt = 0;
    for (i = 1; i <= n * 1000; i++) {
      cnt += widthV[i] * widthH[i];
    }

    cout << cnt << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;

const int MAX_N = 1500, MAX_M = 1500, MAX_W = 1000;
int roadV[MAX_N], roadH[MAX_M];
int widthV[MAX_N * MAX_W + 1];
int widthH[MAX_M * MAX_W + 1];

inline int min(int a, int b) {
  if (a < b)
    return a;
  return b;
}

int main() {
  ios_base::sync_with_stdio(0);
  int n, m, i, j, sumV, sumH, cnt, minWidth;

  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    sumV = 0;
    sumH = 0;
    for (i = 0; i < n; i++) {
      cin >> roadV[i];
      sumV += roadV[i];
    }
    for (i = 0; i < m; i++) {
      cin >> roadH[i];
      sumH += roadH[i];
    }
    minWidth = min(sumV, sumH);

    for (i = 1; i <= minWidth; i++) {
      widthV[i] = 0;
    }
    for (i = 1; i <= minWidth; i++) {
      widthH[i] = 0;
    }

    for (i = 0; i < n; i++) {
      sumV = 0;
      for (j = i; j < n; j++) {
        sumV += roadV[j];
        widthV[sumV]++;
      }
    }

    for (i = 0; i < m; i++) {
      sumH = 0;
      for (j = i; j < m; j++) {
        sumH += roadH[j];
        widthH[sumH]++;
      }
    }

    cnt = 0;
    for (i = 1; i <= minWidth; i++) {
      cnt += widthV[i] * widthH[i];
    }

    cout << cnt << endl;
  }
  return 0;
}


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

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

void input(vector<int> &vec, int size) {
  for (int i = 1; i <= size; ++i) {
    cin >> vec[i];
    vec[i] += vec[i - 1];
  }
}

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

  for (int n, m; cin >> n >> m, n;) {
    vector<int> vertical(n), horizontal(m);
    input(vertical, n);
    input(horizontal, m);

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

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

    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}

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

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

void input(vector<int> &vec, int size) {
  for (int i = 1; i <= size; ++i) {
    cin >> vec[i];
    vec[i] += vec[i - 1];
  }
}

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

  for (int n, m; cin >> n >> m, n;) {
    vector<int> vertical(n + 1, 0), horizontal(m + 1, 0);
    input(vertical, n);
    input(horizontal, m);

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

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

    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> hori(1, 0);
    vector<int> vert(1, 0);
    int tmp;
    for (int i = 1; i < n + 1; i++) {
      cin >> tmp;
      REP(j, i) { hori.push_back(tmp - hori[j]); }
    }
    for (int i = 1; i < m + 1; i++) {
      cin >> tmp;
      REP(j, i) { vert.push_back(tmp - vert[j]); }
    }
    int hori_size = hori.size();
    int vert_size = vert.size();
    int ct = 0;
    for (int i = 1; i < hori_size; i++)
      for (int j = 1; j < vert_size; j++) {
        if (hori[i] == vert[j])
          ct++;
      }
    cout << ct << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main() {
  //  cin.tie(0);
  //  ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m, n) {
    int nsize = n * (n + 1) / 2;
    int msize = m * (m + 1) / 2;
    vector<int> rrr(nsize);
    vector<int> ccc(msize);
    int tmp;

    int k = n;
    REP(i, n) {
      cin >> tmp;
      rrr[i] = tmp;
      int wa = tmp;
      for (int j = i - 1; j >= 0; j--) {
        wa += rrr[j];
        rrr[k] = wa;
        k++;
      }
    }
    k = m;
    REP(i, m) {
      cin >> tmp;
      ccc[i] = tmp;
      int wa = tmp;
      for (int j = i - 1; j >= 0; j--) {
        wa += ccc[j];
        ccc[k] = wa;
        k++;
      }
    }
    sort(rrr.begin(), rrr.end());
    sort(ccc.begin(), ccc.end());
    rrr.push_back(-1);
    ccc.push_back(-1);
    int ri = 0, ci = 0;
    int ans = 0;
    int cct = 1, rct = 1;

    bool is_r = true, is_c = true;
    while (true) {
      while (is_r && rrr[ri] == rrr[ri + 1]) {
        rct++;
        ri++;
      }
      while (is_c && ccc[ci] == ccc[ci + 1]) {
        cct++;
        ci++;
      }
      if (rrr[ri] == ccc[ci]) {
        ans += rct * cct;
        //	cout << rrr[ri] << " " << ccc[ci] << endl;
        is_c = true;
        is_r = true;
        rct = 1;
        cct = 1;
        ri++;
        ci++;
      } else if (rrr[ri] > ccc[ci]) {
        ci++;
        is_c = true;
        is_r = false;
        cct = 1;
      } else {
        ri++;
        is_r = true;
        is_c = false;
        rct = 1;
      }
      if (ri > nsize - 1 || ci > msize - 1)
        break;
    }
    cout << ans << "\\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define vp vector<i_i>
#define all(a) (a).begin(), (a).end()
#define Int(x)                                                                 \\
  int x;                                                                       \\
  scanf("%lld", &x);

// int dxy[5] = {0, 1, 0, -1, 0};
//  assign

signed main() {
  Int(n);
  Int(m);

  while (n && m) {
    vi h(n), w(m);
    multiset<int> s;
    rep(i, n) { cin >> h[i]; }
    rep(i, n) {
      int tmp = h[i];
      s.insert(tmp);
      for (int j = i + 1; j < n; j++) {
        tmp += h[j];
        s.insert(tmp);
      }
    }
    rep(i, m) { cin >> w[i]; }
    int ret = 0;
    rep(i, m) {
      int tmp = w[i];
      ret += s.count(tmp);
      for (int j = i + 1; j < n; j++) {
        tmp += w[j];
        ret += s.count(tmp);
      }
    }
    cout << ret << endl;
    cin >> n >> m;
  }

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define vp vector<i_i>
#define all(a) (a).begin(), (a).end()
#define Int(x)                                                                 \\
  int x;                                                                       \\
  scanf("%lld", &x);

// int dxy[5] = {0, 1, 0, -1, 0};
//  assign

signed main() {
  Int(n);
  Int(m);

  while (n && m) {
    vi h(n), w(m);
    map<int, int> s;
    rep(i, n) { cin >> h[i]; }
    rep(i, n) {
      int tmp = h[i];
      if (s.find(tmp) != s.end()) {
        int sec = s.find(tmp)->second + 1;
        s.erase(tmp);
        s.insert(mp(tmp, sec));
      } else {
        s.insert(mp(tmp, 1));
      }
      for (int j = i + 1; j < n; j++) {
        tmp += h[j];
        if (s.find(tmp) != s.end()) {
          int sec = s.find(tmp)->second + 1;
          s.erase(tmp);
          s.insert(mp(tmp, sec));
        } else {
          s.insert(mp(tmp, 1));
        }
      }
    }
    rep(i, m) { cin >> w[i]; }
    int ret = 0;
    rep(i, m) {
      int tmp = w[i];
      if (s.find(tmp) != s.end()) {
        ret += s.find(tmp)->second;
      }
      for (int j = i + 1; j < m; j++) {
        tmp += w[j];
        if (s.find(tmp) != s.end()) {
          ret += s.find(tmp)->second;
        }
      }
    }
    cout << ret << endl;
    cin >> n >> m;
  }

  return 0;
}


#include <stdio.h>

using namespace std;
#define rep(i, j) for (int i = 0; i < (j); i++)
int main() {
  int n, m, w[1501], h[1501], t, s, cnt;
  for (;;) {
    scanf("%d%d", &n, &m);
    if (!n)
      break;
    cnt = s = *w = *h = 0;
    rep(i, n) {
      scanf("%d", &t);
      s += t;
      w[i + 1] = s;
    }
    s = 0;
    rep(i, m) {
      scanf("%d", &t);
      s += t;
      h[i + 1] = s;
    }

    rep(i, n + 1) rep(j, i) {
      int len = w[i] - w[j];
      int l = 0, r = 1;
      while (r <= m) {
        if (h[r] - h[l] == len)
          cnt++;
        if (h[r] - h[l] <= len)
          r++;
        else
          l++;
      }
    }
    printf("%d\\n", cnt);
  }
  return 0;
}

#include <stdio.h>
#include <string.h>
using namespace std;
#define rep(i, j) for (int i = 0; i < (j); i++)
int memo[15000000];
int main() {
  int n, m, w[1501], h[1501], t, s, cnt;
  for (;;) {
    scanf("%d%d", &n, &m);
    if (!n)
      break;
    cnt = s = *w = *h = 0;
    memset(memo, 0, sizeof(memo));
    rep(i, n) {
      scanf("%d", &t);
      s += t;
      w[i + 1] = s;
    }
    s = 0;
    rep(i, m) {
      scanf("%d", &t);
      s += t;
      h[i + 1] = s;
    }

    rep(i, n + 1) rep(j, i) {
      int c = 0;
      int len = w[i] - w[j];
      if (memo[len] > 0) {
        cnt += memo[len];
        continue;
      }
      int l = 0, r = 1;
      while (r <= m) {
        if (h[r] - h[l] == len) {
          c++;
          r++;
          l++;
        } else if (h[r] - h[l] < len)
          r++;
        else
          l++;
      }
      memo[len] = c;
      cnt += c;
    }
    printf("%d\\n", cnt);
  }
  return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9 + 7;

int main() {

  int n, m;
  while (cin >> n >> m, n | m) {

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

    int ans = 0;
    for (int i = 0; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        int height = hs[j] - hs[i];
        for (int k = 0; k <= m; k++) {
          for (int l = k + 1; l <= m; l++) {

            int width = ws[l] - ws[k];
            if (height == width) {
              ans++;
            }
            if (width > height) {
              break;
            }
          }
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9 + 7;

int main() {

  int n, m;
  while (cin >> n >> m, n | m) {

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

    map<int, int> H, W;
    for (int i = 0; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        H[hs[j] - hs[i]]++;
      }
    }
    for (int i = 0; i <= m; i++) {
      for (int j = i + 1; j <= m; j++) {
        W[ws[j] - ws[i]]++;
      }
    }
    int ans = 0;
    for (auto itr : H) {
      ans += H[itr.first] * W[itr.first];
    }
    cout << ans << endl;
  }

  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)

void slove(int n, int m) {
  vint tmph(n);
  vint h(n * 1000); //?????±?????????????????????
  vint tmpw(m);
  vint w(m * 1000);

  //??\\???
  rep(i, n) scanf("%d", &tmph[i]);
  rep(i, m) scanf("%d", &tmpw[i]);

  for (int i = 0; i < n; ++i) {
    int len = 0;
    for (int j = i; j < n; ++j) {
      len += tmph[j];
      h[len]++;
    }
  }

  for (int i = 0; i < m; ++i) {
    int len = 0;
    for (int j = i; j < m; ++j) {
      len += tmpw[j];
      w[len]++;
    }
  }

  ll sum = 0;
  int limit = max(n, m);
  rep(i, limit * 1000) { sum += h[i] * w[i]; }

  printf("%lld\\n", sum);
  return;
}

int main(void) {
  int n, m;
  while (1) {
    scanf("%d %d", &n, &m);
    if (n == 0)
      break;
    slove(n, m);
  }
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)

void slove(int n, int m) {
  vint tmph(1501);
  vint h(1500001); //?????±?????????????????????
  vint tmpw(1501);
  vint w(1500001);

  //??\\???
  rep(i, n) scanf("%d", &tmph[i]);
  rep(i, m) scanf("%d", &tmpw[i]);

  for (int i = 0; i < n; ++i) {
    int len = 0;
    for (int j = i; j < n; ++j) {
      len += tmph[j];
      h[len]++;
    }
  }

  for (int i = 0; i < m; ++i) {
    int len = 0;
    for (int j = i; j < m; ++j) {
      len += tmpw[j];
      w[len]++;
    }
  }

  ll sum = 0;
  rep(i, 1500001) { sum += h[i] * w[i]; }

  printf("%lld\\n", sum);
  return;
}

int main(void) {
  int n, m;
  while (1) {
    scanf("%d %d", &n, &m);
    if (n == 0)
      break;
    slove(n, m);
  }
  return 0;
}