#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  int tmp;
  for (;;) {
    cin >> N >> M;
    if (N == 0)
      break;
    vector<int> harr(N + 1), warr(M + 1);
    int ans = 0;
    harr[0] = 0;
    warr[0] = 0;
    for (int i = 1; i < N + 1; i++) {
      cin >> tmp;
      harr[i] = harr[i - 1] + tmp;
    }
    for (int i = 1; i < M + 1; i++) {
      cin >> tmp;
      warr[i] = warr[i - 1] + tmp;
    }
    vector<int> count(harr[N] + 1, 0);
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N + 1; j++) {
        count[harr[j] - harr[i]]++;
      }
    }
    for (int i = 0; i < M; i++) {
      for (int j = i + 1; j < M + 1; j++) {
        ans += count[warr[j] - warr[i]];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int N, M;
  int tmp;
  for (;;) {
    cin >> N >> M;
    if (N == 0)
      break;
    vector<int> harr(N + 1), warr(M + 1);
    int ans = 0;
    harr[0] = 0;
    warr[0] = 0;
    for (int i = 1; i < N + 1; i++) {
      cin >> tmp;
      harr[i] = harr[i - 1] + tmp;
    }
    for (int i = 1; i < M + 1; i++) {
      cin >> tmp;
      warr[i] = warr[i - 1] + tmp;
    }
    vector<int> count(max(harr[N], warr[M]) + 1, 0);
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N + 1; j++) {
        count[harr[j] - harr[i]]++;
      }
    }
    for (int i = 0; i < M; i++) {
      for (int j = i + 1; j < M + 1; j++) {
        ans += count[warr[j] - warr[i]];
      }
    }
    cout << ans << endl;
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int n, m;
int h[2001], w[2001];
int hsum[2001], wsum[2001];

void init() {
  memset(hsum, 0, sizeof(hsum));
  memset(wsum, 0, sizeof(wsum));
  memset(h, 0, sizeof(h));
  memset(w, 0, sizeof(w));
  return;
}

bool check(int a, int s) {
  int l = s - 1, r = m + 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (wsum[mid] - wsum[s] > a)
      r = mid;
    else
      l = mid;
  }
  if (a == wsum[l] - wsum[s])
    return true;
  return false;
}

int main(void) {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n + m == 0)
      break;
    for (int i = 0; i < n; i++)
      scanf("%d", &h[i]);
    for (int i = 0; i < n; i++)
      hsum[i + 1] = hsum[i] + h[i];
    for (int i = 0; i < m; i++)
      scanf("%d", &w[i]);
    for (int i = 0; i < m; i++)
      wsum[i + 1] = wsum[i] + w[i];
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        int hl = hsum[j] - hsum[i];
        for (int k = 0; k < m; k++) {
          if (check(hl, k))
            cnt++;
        }
      }
    }
    printf("%d\\n", cnt);
    init();
  }
  return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int n, m;
int h[2001], w[2001];
int hsum[2001], wsum[2001];
int hcnt[2000001], wcnt[2000001];

void init() {
  memset(hsum, 0, sizeof(hsum));
  memset(wsum, 0, sizeof(wsum));
  memset(h, 0, sizeof(h));
  memset(w, 0, sizeof(w));
  memset(hcnt, 0, sizeof(hcnt));
  memset(wcnt, 0, sizeof(wcnt));
  return;
}

int main(void) {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n + m == 0)
      break;
    for (int i = 0; i < n; i++)
      scanf("%d", &h[i]);
    for (int i = 0; i < n; i++)
      hsum[i + 1] = hsum[i] + h[i];
    for (int i = 0; i < m; i++)
      scanf("%d", &w[i]);
    for (int i = 0; i < m; i++)
      wsum[i + 1] = wsum[i] + w[i];
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        hcnt[hsum[j] - hsum[i]]++;
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j < m + 1; j++) {
        wcnt[wsum[j] - wsum[i]]++;
      }
    }
    int cnt = 0;
    for (int i = 0; i < 2000000; i++)
      cnt += hcnt[i] * wcnt[i];
    printf("%d\\n", cnt);
    init();
  }
  return 0;
}


#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int hi, wi;
int N, M;
int h[1520];
int w[1000];
int hl[150004] = {};
int wl[150004] = {};
int main() {
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    long long int ans = 0;
    cin >> hi;
    h[0] = hi;
    for (int i = 1; i < N; i++) {
      cin >> hi;
      h[i] = h[i - 1] + hi;
    }
    cin >> wi;
    w[0] = wi;
    for (int i = 1; i < M; i++) {
      cin >> wi;
      w[i] = w[i - 1] + wi;
    }
    hl[150004] = {};
    wl[150004] = {};
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N - i; j++) {
        hl[h[i + j] - h[j - 1]]++;
      }
    }
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M - i; j++) {
        wl[w[i + j] - w[j - 1]]++;
      }
    }
    for (int i = 0; i <= 150000; i++) {
      ans += hl[i] * wl[i];
    }
    cout << ans << endl;
  }
  return 0;
}

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int hi, wi;
int N, M;
int h[3000];
int w[3000];
long long int hl[1500004] = {};
long long int wl[1500004] = {};
int main() {
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    long long int ans = 0;
    cin >> hi;
    h[0] = hi;
    for (int i = 1; i < N; i++) {
      cin >> hi;
      h[i] = h[i - 1] + hi;
    }
    cin >> wi;
    w[0] = wi;
    for (int i = 1; i < M; i++) {
      cin >> wi;
      w[i] = w[i - 1] + wi;
    }
    for (int i = 0; i < 1500000; i++) {
      hl[i] = 0;
      wl[i] = 0;
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N - i; j++) {
        hl[h[i + j] - h[j - 1]]++;
      }
    }
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M - i; j++) {
        wl[w[i + j] - w[j - 1]]++;
      }
    }
    for (int i = 0; i <= 1500000; i++) {
      ans += hl[i] * wl[i];
    }
    cout << ans << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007
#define allof(a) (a).begin(), (a).end()
using namespace std;

/*
const double EPS = 1e-9;
const int INF = 1L << 30;
vector<int> dx = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};

bool in_range(int x, int lb, int ub) {return lb <= x and x < ub;}
bool in_range(int x, int y, int W, int H) {return in_range(x,0,W) and
in_range(y,0,H);} void modAdd(int &a, int b, int mod) {a = (a + b) % MOD;}
template <typename T> void maxUpdate(T& a, T b){a = max(a,b);}
*/
int main() {

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

    vector<int> h(n + 1);
    vector<int> w(m + 1);
    vector<int> h_cnt(1501);
    vector<int> w_cnt(1501);

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

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

    for (int i = 0; i <= n; i++) {
      for (int j = i; j <= n; j++) {
        h_cnt[h[j] - h[i]]++;
      }
    }
    for (int i = 0; i <= m; i++) {
      for (int j = i; j <= m; j++) {
        w_cnt[w[j] - w[i]]++;
      }
    }

    int ans = 0;
    for (int i = 1; i < 1501; i++) {
      ans += h_cnt[i] * w_cnt[i];
    }
    cout << ans << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
#define MOD 1000000007
#define allof(a) (a).begin(), (a).end()
using namespace std;

/*
const double EPS = 1e-9;
const int INF = 1L << 30;
vector<int> dx = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};

bool in_range(int x, int lb, int ub) {return lb <= x and x < ub;}
bool in_range(int x, int y, int W, int H) {return in_range(x,0,W) and
in_range(y,0,H);} void modAdd(int &a, int b, int mod) {a = (a + b) % MOD;}
template <typename T> void maxUpdate(T& a, T b){a = max(a,b);}
*/
int main() {

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

    vector<int> h(n + 1);
    vector<int> w(m + 1);
    vector<int> h_cnt(1000000);
    vector<int> w_cnt(1000000);

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

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

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

    int ans = 0;
    for (int i = 1; i < h_cnt.size(); i++) {
      ans += h_cnt[i] * w_cnt[i];
    }
    cout << ans << endl;
  }

  return 0;
}


#include <cstdio>
#include <unordered_map>
#define S 1500
using namespace std;
int W[S] = {0};
int H[S] = {0};

int main() {
  int N, M, h, w, i, j, k, l, c;
  while (1) {
    scanf("%d %d", &N, &M);
    if (!N && !M) {
      break;
    }
    unordered_map<int, int> ww, hh;
    for (i = 0; i < S; i++) {
      W[i] = 0;
      H[i] = 0;
    }
    for (i = 0; i < N; i++) {
      scanf("%d", &h);
      if (!i) {
        H[i] = h;
      } else {
        H[i] = H[i - 1] + h;
      }
    }
    for (i = 0; i < M; i++) {
      scanf("%d", &w);
      if (!i) {
        W[i] = w;
      } else {
        W[i] = W[i - 1] + w;
      }
    }
    c = 0;
    for (i = 0; i < M; i++) {
      for (j = 0; j <= i; j++) {
        if (i != j) {
          auto itr = ww.find(W[i] - W[j]);
          if (itr != ww.end()) {
            ww[W[i] - W[j]]++;
          } else {
            ww[W[i] - W[j]] = 1;
          }
        } else {
          auto itr = ww.find(W[i]);
          if (itr != ww.end()) {
            ww[W[i]]++;
          } else {
            ww[W[i]] = 1;
          }
        }
      }
    }

    for (k = 0; k < N; k++) {
      for (l = 0; l <= k; l++) {
        if (k != l) {
          auto itr = hh.find(H[k] - H[l]);
          if (itr != hh.end()) {
            hh[H[k] - H[l]]++;
          } else {
            hh[H[k] - H[l]] = 1;
          }
        } else {
          auto itr = hh.find(H[k]);
          if (itr != hh.end()) {
            hh[H[k]]++;
          } else {
            hh[H[k]] = 1;
          }
        }
      }
    }
    for (auto itr = ww.begin(); itr != ww.end(); itr++) {
      auto r = hh.find(itr->first);
      if (r != hh.end()) {
        c += (itr->second * r->second);
      }
    }
    printf("%d\\n", c);
  }
  return 0;
}


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

int main() {
  int n, m;
  while (cin >> n >> m && n != 0 || m != 0) {
    vector<int> x(m + 1);
    vector<int> y(n + 1);
    y[0] = 0;
    for (int i = 0; i < n; i++) {
      int h;
      cin >> h;
      y[i + 1] = y[i] + h;
    }
    x[0] = 0;
    for (int i = 0; i < m; i++) {
      int w;
      cin >> w;
      x[i + 1] = x[i] + w;
    }
    vector<pair<int, int>> xp;
    vector<pair<int, int>> yp;
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        xp.push_back(make_pair(i, j));
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        yp.push_back(make_pair(i, j));
      }
    }
    int count = 0;
    for (int i = 0; i < yp.size(); i++) {
      for (int j = 0; j < xp.size(); j++) {
        int dx = x[xp[j].second] - x[xp[j].first];
        int dy = y[yp[i].second] - y[yp[i].first];
        if (dx == dy) {
          count++;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

#include <iostream>
#include <string.h>
using namespace std;
static int table[1500 * 1000];
int main() {
  int n, m;
  while (cin >> n >> m && n != 0 || m != 0) {
    int x[1502];
    int y[1502];
    memset(table, 0, sizeof table);
    y[0] = 0;
    for (int i = 0; i < n; i++) {
      int h;
      cin >> h;
      y[i + 1] = y[i] + h;
    }
    x[0] = 0;
    for (int i = 0; i < m; i++) {
      int w;
      cin >> w;
      x[i + 1] = x[i] + w;
    }
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        table[x[j] - x[i]]++;
      }
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (table[y[j] - y[i]] > 0) {
          count += table[y[j] - y[i]];
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// common
typedef int i32;
typedef long long i64, ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<string> vs;
typedef long double ld;

#define BR "\\n"
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define EACH(it, o) for (auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l, v, r) ((l) <= (v) && (v) < (r))

// config
// #undef NDEBUG
// #define INF 1<<30
// #define EPS 1e-8
// const ll MOD =100000007;

// debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp, act)
#define STOP(e)
#else
#define DUMP(x) cerr << #x << " = " << (x)
#define DUMPLN(x) DUMP(x) << endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x) << endl
#define LINE() cerr << " (L" << __LINE__ << ")"
#define LINELN() LINE() << endl
#define CHECK(exp, act)                                                        \\
  if (exp != act) {                                                            \\
    DUMPLN(exp);                                                               \\
    DEBUGLN(act);                                                              \\
  }
#define STOP(e)                                                                \\
  CHECK(e, true);                                                              \\
  if (!(e))                                                                    \\
    exit(1);
#endif

template <class T> inline string toString(const vector<T> &x) {
  stringstream ss;
  REP(i, x.size()) {
    if (i != 0)
      ss << " ";
    ss << x[i];
  }
  return ss.str();
}

template <class T> inline string toString(const vector<vector<T>> &map) {
  stringstream ss;
  REP(i, map.size()) {
    if (i != 0)
      ss << BR;
    ss << toString(map[i]);
  }
  return ss.str();
}
template <class K, class V> string toString(map<K, V> &x) {
  string res;
  stringstream ss;
  for (auto &p : x)
    ss << p.first << ":" << p.second << " ";
  return ss.str();
}

string BITtoString(int bit) {
  stringstream ss;
  while (bit != 0) {
    ss << (bit % 2);
    bit /= 2;
  }
  string res = ss.str();
  reverse(ALL(res));
  return res;
}

template <typename T, typename V> inline T mod(T v, V MOD) {
  return (v % MOD + MOD) % MOD;
}
int hmap[200500], wmap[200500];

class Main {
public:
  void run() {
    while (true) {
      int N, M;
      cin >> N >> M;
      if (N == 0 && M == 0)
        break;
      vector<int> hs(N), ws(M);
      REP(i, N) cin >> hs[i];
      REP(i, M) cin >> ws[i];

      vector<int> hsum(N + 1), wsum(M + 1);
      for (int i = 1; i <= N; i++)
        hsum[i] = hsum[i - 1] + hs[i - 1];
      for (int i = 1; i <= M; i++)
        wsum[i] = wsum[i - 1] + ws[i - 1];

      fill_n(hmap, 200500, 0);
      fill_n(wmap, 200500, 0);

      for (int i = 0; i <= N; i++)
        for (int j = i + 1; j <= N; j++) {
          hmap[hsum[j] - hsum[i]]++;
        }
      for (int i = 0; i <= M; i++)
        for (int j = i + 1; j <= M; j++) {
          wmap[wsum[j] - wsum[i]]++;
        }

      ll res = 0;
      for (int i = 1; i < 200500; i++) {
        res += (ll)hmap[i] * wmap[i];
      }
      cout << res << endl;
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  Main().run();
  return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// common
typedef int i32;
typedef long long i64, ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<string> vs;
typedef long double ld;

#define BR "\\n"
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define EACH(it, o) for (auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l, v, r) ((l) <= (v) && (v) < (r))

// config
// #undef NDEBUG
// #define INF 1<<30
// #define EPS 1e-8
// const ll MOD =100000007;

// debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp, act)
#define STOP(e)
#else
#define DUMP(x) cerr << #x << " = " << (x)
#define DUMPLN(x) DUMP(x) << endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x) << endl
#define LINE() cerr << " (L" << __LINE__ << ")"
#define LINELN() LINE() << endl
#define CHECK(exp, act)                                                        \\
  if (exp != act) {                                                            \\
    DUMPLN(exp);                                                               \\
    DEBUGLN(act);                                                              \\
  }
#define STOP(e)                                                                \\
  CHECK(e, true);                                                              \\
  if (!(e))                                                                    \\
    exit(1);
#endif

template <class T> inline string toString(const vector<T> &x) {
  stringstream ss;
  REP(i, x.size()) {
    if (i != 0)
      ss << " ";
    ss << x[i];
  }
  return ss.str();
}

template <class T> inline string toString(const vector<vector<T>> &map) {
  stringstream ss;
  REP(i, map.size()) {
    if (i != 0)
      ss << BR;
    ss << toString(map[i]);
  }
  return ss.str();
}
template <class K, class V> string toString(map<K, V> &x) {
  string res;
  stringstream ss;
  for (auto &p : x)
    ss << p.first << ":" << p.second << " ";
  return ss.str();
}

string BITtoString(int bit) {
  stringstream ss;
  while (bit != 0) {
    ss << (bit % 2);
    bit /= 2;
  }
  string res = ss.str();
  reverse(ALL(res));
  return res;
}

template <typename T, typename V> inline T mod(T v, V MOD) {
  return (v % MOD + MOD) % MOD;
}
int hmap[2005000], wmap[2005000];

class Main {
public:
  void run() {
    while (true) {
      int N, M;
      cin >> N >> M;
      if (N == 0 && M == 0)
        break;
      vector<int> hs(N), ws(M);
      REP(i, N) cin >> hs[i];
      REP(i, M) cin >> ws[i];

      vector<int> hsum(N + 1), wsum(M + 1);
      for (int i = 1; i <= N; i++)
        hsum[i] = hsum[i - 1] + hs[i - 1];
      for (int i = 1; i <= M; i++)
        wsum[i] = wsum[i - 1] + ws[i - 1];

      fill_n(hmap, 2005000, 0);
      fill_n(wmap, 2005000, 0);

      for (int i = 0; i <= N; i++)
        for (int j = i + 1; j <= N; j++) {
          hmap[hsum[j] - hsum[i]]++;
        }
      for (int i = 0; i <= M; i++)
        for (int j = i + 1; j <= M; j++) {
          wmap[wsum[j] - wsum[i]]++;
        }

      ll res = 0;
      for (int i = 1; i < 2005000; i++) {
        res += (ll)hmap[i] * wmap[i];
      }
      cout << res << endl;
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  Main().run();
  return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, x) for (int i = 0; i < x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rep_to(a, i, x) for (int i = a; i < x; i++)

using namespace std;

int main() {
  int N, M;

  while (cin >> N >> M && M && N) {
    int h[10000] = {};
    int w[10000] = {};
    unsigned long long sum_h[10000] = {};
    unsigned long long sum_w[10000] = {};
    long long h_c[225000] = {};
    long long w_c[225000] = {};

    rep(i, N) {
      cin >> h[i];
      sum_h[i + 1] = sum_h[i] + h[i];
    }
    rep(i, M) {
      cin >> w[i];
      sum_w[i + 1] = sum_w[i] + w[i];
    }

    rep(i, N) rep(j, N - i) h_c[sum_h[j + i + 1] - sum_h[j]]++;
    rep(i, M) rep(j, M - i) w_c[sum_w[j + i + 1] - sum_w[j]]++;

    long long count = 0;
    rep(i, min(sum_h[N], sum_w[M]) + 1) count += h_c[i] * w_c[i];
    cout << count << endl;
  }
  return 0;
}

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, x) for (int i = 0; i < x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rep_to(a, i, x) for (int i = a; i < x; i++)

using namespace std;

int main() {
  int N, M;

  while (cin >> N >> M && M && N) {
    int h[10000] = {};
    int w[10000] = {};
    unsigned long long sum_h[10000] = {};
    unsigned long long sum_w[10000] = {};
    long long h_c[510000] = {};
    long long w_c[500000] = {};

    rep(i, N) {
      cin >> h[i];
      sum_h[i + 1] = sum_h[i] + h[i];
    }
    rep(i, M) {
      cin >> w[i];
      sum_w[i + 1] = sum_w[i] + w[i];
    }

    rep(i, N) rep(j, N - i) h_c[sum_h[j + i + 1] - sum_h[j]]++;
    rep(i, M) rep(j, M - i) w_c[sum_w[j + i + 1] - sum_w[j]]++;

    long long count = 0;
    rep(i, min(sum_h[N], sum_w[M]) + 1) count += h_c[i] * w_c[i];
    cout << count << endl;
  }
  return 0;
}


#define DEBUG_ON
#define CONDITION true
using namespace std; /*{{{*/

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <vector>

#define INF (1e9)
static const double PI = acos(-1.0);
static const double EPS = 1e-10;

typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef complex<double> P;

#define FOR(i, b, e) for (typeof(e) i = (b); i != (e); i < (e) ? ++i : --i)
#define REP(i, n) FOR(i, 0, n)

#define IFC(c)                                                                 \\
  if (c)                                                                       \\
    continue;
#define IFB(c)                                                                 \\
  if (c)                                                                       \\
    break;
#define IFR(c, r)                                                              \\
  if (c)                                                                       \\
    return r;

#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const

#define arrsz(a) (sizeof(a) / sizeof(a[0]))

#define F first
#define S second
#define MP(a, b) make_pair(a, b)

#define SZ(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it)                                                            \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())

#define BIT(n) (assert(n < 64), (1ULL << (n)))
#define BITOF(n, m) (assert(m < 64), ((ULL)(n) >> (m)&1))

#define RANGE(a, b, c) ((a) <= (b) && (b) <= (c))

#define PQ priority_queue
#define SC static_cast

#ifdef DEBUG_ON
#define dprt(fmt, ...)                                                         \\
  if (CONDITION)                                                               \\
  fprintf(stderr, fmt, ##__VA_ARGS__)
#define darr(a)                                                                \\
  if (CONDITION)                                                               \\
    copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " "));               \\
  cerr << endl
#define darr_range(a, f, t)                                                    \\
  if (CONDITION)                                                               \\
    copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " "));              \\
  cerr << endl
#define dvec(v)                                                                \\
  if (CONDITION)                                                               \\
    copy(ALL(v), ostream_iterator<int>(cerr, " "));                            \\
  cerr << endl
#define darr2(a, n, m)                                                         \\
  if (CONDITION)                                                               \\
    FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); }
#define dvec2(v)                                                               \\
  if (CONDITION)                                                               \\
    FOR(i, 0, SZ(v)) { dvec((v)[i]); }
#define WAIT()                                                                 \\
  if (CONDITION) {                                                             \\
    string _wait_;                                                             \\
    cerr << "(hit return to continue)" << endl;                                \\
    getline(cin, _wait_);                                                      \\
  }
#define dump(x)                                                                \\
  if (CONDITION)                                                               \\
    cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl;
#define dumpf()                                                                \\
  if (CONDITION)                                                               \\
    cerr << __PRETTY_FUNCTION__ << endl;
#define dumpv(x)                                                               \\
  if (CONDITION)                                                               \\
    cerr << " [L:" << __LINE__ << "] " << #x << " = ";                         \\
  REP(q, (x).size()) cerr << (x)[q] << " ";                                    \\
  cerr << endl;
#define where()                                                                \\
  if (CONDITION)                                                               \\
    cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__     \\
         << "]" << endl;
#define show_bits(b, s)                                                        \\
  if (CONDITION) {                                                             \\
    REP(i, s) {                                                                \\
      cerr << BITOF(b, s - 1 - i);                                             \\
      if (i % 4 == 3)                                                          \\
        cerr << ' ';                                                           \\
    }                                                                          \\
    cerr << endl;                                                              \\
  }
#else
#define cerr                                                                   \\
  if (0)                                                                       \\
  cerr
#define dprt(fmt, ...)
#define darr(a)
#define darr_range(a, f, t)
#define dvec(v)
#define darr2(a, n, m)
#define dvec2(v)
#define WAIT()
#define dump(x)
#define dumpf()
#define dumpv(x)
#define where()
#define show_bits(b, s)
#endif

/* Inline functions */
inline int onbits_count(ULL b) {
  int c = 0;
  while (b != 0) {
    c += (b & 1);
    b >>= 1;
  }
  return c;
}
inline int bits_count(ULL b) {
  int c = 0;
  while (b != 0) {
    ++c;
    b >>= 1;
  }
  return c;
}
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
inline double now() {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  return (static_cast<double>(tv.tv_sec) +
          static_cast<double>(tv.tv_usec) * 1e-6);
}
inline VS split(string s, char delimiter) {
  VS v;
  string t;
  REP(i, s.length()) {
    if (s[i] == delimiter)
      v.PB(t), t = "";
    else
      t += s[i];
  }
  v.PB(t);
  return v;
}

/* Tweaks */
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
  return s << "(" << d.first << ", " << d.second << ")";
}

/* Frequent stuffs */
int n_dir = 4;
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; /* CSS order */
enum direction { UP, RIGHT, DOWN, LEFT };
// int n_dir = 8;
// int dx[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy[] = {-1, -1, 0, 1, 1, 1, 0, -1};
// enum direction {
// UP, UPRIGHT, RIGHT, DOWNRIGHT, DOWN, DOWNLEFT, LEFT, UPLEFT
// }
#define FORDIR(d) REP(d, n_dir)

/*}}}*/

int combination(int a, int b) {
  if (a < b || b == 0) {
    return 0;
  }
  int numer = 1, denom = 1;
  int n = b;
  while (n--) {
    numer *= a--;
  }
  while (b) {
    denom *= b--;
  }
  return numer / denom;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M, N | M) {
    VI vy(N + 1), vx(M + 1);
    vy[0] = 0, vx[0] = 0;
    REP(i, N) {
      int y;
      cin >> y;
      vy[i + 1] = vy[i] + y;
    }
    REP(i, M) {
      int x;
      cin >> x;
      vx[i + 1] = vx[i] + x;
    }
    vector<P> points;
    EACH(vy, y) {
      EACH(vx, x) { points.PB(P(*y, *x)); }
    }
    map<int, int> intercept_count;
    EACH(points, p) {
      int intercept = (*p).real() - (*p).imag();
      if (EXIST(intercept_count, intercept)) {
        ++intercept_count[intercept];
      } else {
        intercept_count[intercept] = 1;
      }
    }
    int ans = 0;
    EACH(intercept_count, ic) { ans += combination(ic->second, 2); }
    cout << ans << endl;
  }
}

// vim: foldmethod=marker

#define DEBUG_ON
#define CONDITION true
using namespace std; /*{{{*/

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <vector>

#define INF (1e9)
static const double PI = acos(-1.0);
static const double EPS = 1e-10;

typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef complex<double> P;

#define FOR(i, b, e) for (typeof(e) i = (b); i != (e); i < (e) ? ++i : --i)
#define REP(i, n) FOR(i, 0, n)

#define IFC(c)                                                                 \\
  if (c)                                                                       \\
    continue;
#define IFB(c)                                                                 \\
  if (c)                                                                       \\
    break;
#define IFR(c, r)                                                              \\
  if (c)                                                                       \\
    return r;

#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const

#define arrsz(a) (sizeof(a) / sizeof(a[0]))

#define F first
#define S second
#define MP(a, b) make_pair(a, b)

#define SZ(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it)                                                            \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())

#define BIT(n) (assert(n < 64), (1ULL << (n)))
#define BITOF(n, m) (assert(m < 64), ((ULL)(n) >> (m)&1))

#define RANGE(a, b, c) ((a) <= (b) && (b) <= (c))

#define PQ priority_queue
#define SC static_cast

#ifdef DEBUG_ON
#define dprt(fmt, ...)                                                         \\
  if (CONDITION)                                                               \\
  fprintf(stderr, fmt, ##__VA_ARGS__)
#define darr(a)                                                                \\
  if (CONDITION)                                                               \\
    copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " "));               \\
  cerr << endl
#define darr_range(a, f, t)                                                    \\
  if (CONDITION)                                                               \\
    copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " "));              \\
  cerr << endl
#define dvec(v)                                                                \\
  if (CONDITION)                                                               \\
    copy(ALL(v), ostream_iterator<int>(cerr, " "));                            \\
  cerr << endl
#define darr2(a, n, m)                                                         \\
  if (CONDITION)                                                               \\
    FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); }
#define dvec2(v)                                                               \\
  if (CONDITION)                                                               \\
    FOR(i, 0, SZ(v)) { dvec((v)[i]); }
#define WAIT()                                                                 \\
  if (CONDITION) {                                                             \\
    string _wait_;                                                             \\
    cerr << "(hit return to continue)" << endl;                                \\
    getline(cin, _wait_);                                                      \\
  }
#define dump(x)                                                                \\
  if (CONDITION)                                                               \\
    cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl;
#define dumpf()                                                                \\
  if (CONDITION)                                                               \\
    cerr << __PRETTY_FUNCTION__ << endl;
#define dumpv(x)                                                               \\
  if (CONDITION)                                                               \\
    cerr << " [L:" << __LINE__ << "] " << #x << " = ";                         \\
  REP(q, (x).size()) cerr << (x)[q] << " ";                                    \\
  cerr << endl;
#define where()                                                                \\
  if (CONDITION)                                                               \\
    cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__     \\
         << "]" << endl;
#define show_bits(b, s)                                                        \\
  if (CONDITION) {                                                             \\
    REP(i, s) {                                                                \\
      cerr << BITOF(b, s - 1 - i);                                             \\
      if (i % 4 == 3)                                                          \\
        cerr << ' ';                                                           \\
    }                                                                          \\
    cerr << endl;                                                              \\
  }
#else
#define cerr                                                                   \\
  if (0)                                                                       \\
  cerr
#define dprt(fmt, ...)
#define darr(a)
#define darr_range(a, f, t)
#define dvec(v)
#define darr2(a, n, m)
#define dvec2(v)
#define WAIT()
#define dump(x)
#define dumpf()
#define dumpv(x)
#define where()
#define show_bits(b, s)
#endif

/* Inline functions */
inline int onbits_count(ULL b) {
  int c = 0;
  while (b != 0) {
    c += (b & 1);
    b >>= 1;
  }
  return c;
}
inline int bits_count(ULL b) {
  int c = 0;
  while (b != 0) {
    ++c;
    b >>= 1;
  }
  return c;
}
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
inline double now() {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  return (static_cast<double>(tv.tv_sec) +
          static_cast<double>(tv.tv_usec) * 1e-6);
}
inline VS split(string s, char delimiter) {
  VS v;
  string t;
  REP(i, s.length()) {
    if (s[i] == delimiter)
      v.PB(t), t = "";
    else
      t += s[i];
  }
  v.PB(t);
  return v;
}

/* Tweaks */
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
  return s << "(" << d.first << ", " << d.second << ")";
}

/* Frequent stuffs */
int n_dir = 4;
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; /* CSS order */
enum direction { UP, RIGHT, DOWN, LEFT };
// int n_dir = 8;
// int dx[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy[] = {-1, -1, 0, 1, 1, 1, 0, -1};
// enum direction {
// UP, UPRIGHT, RIGHT, DOWNRIGHT, DOWN, DOWNLEFT, LEFT, UPLEFT
// }
#define FORDIR(d) REP(d, n_dir)

/*}}}*/

int combination(int a, int b) {
  if (a < b || b == 0) {
    return 0;
  }
  int numer = 1, denom = 1;
  int n = b;
  while (n--) {
    numer *= a--;
  }
  while (b) {
    denom *= b--;
  }
  return numer / denom;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M, N | M) {
    VI vy(N + 1), vx(M + 1);
    vy[0] = 0, vx[0] = 0;
    REP(i, N) {
      int y;
      cin >> y;
      vy[i + 1] = vy[i] + y;
    }
    REP(i, M) {
      int x;
      cin >> x;
      vx[i + 1] = vx[i] + x;
    }

    map<int, int> intercept_count;
    EACH(vy, y) {
      EACH(vx, x) {
        P p(*y, *x);
        int intercept = p.real() - p.imag();
        if (EXIST(intercept_count, intercept)) {
          ++intercept_count[intercept];
        } else {
          intercept_count[intercept] = 1;
        }
      }
    }
    int ans = 0;
    EACH(intercept_count, ic) { ans += combination(ic->second, 2); }
    cout << ans << endl;
  }
}

// vim: foldmethod=marker


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

using namespace std;

int h[1024 * 1500];
int w[1024 * 1500];

int getInt() {
  int c = getchar();
  int ret = 0;
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main() {
  int n, m;
  while (n = getInt(), m = getInt(), n + m) {
    int hh[n];
    int ww[m];
    int mm = 0;

    for (int i = 0; i < n; i++)
      hh[i] = getInt();
    for (int i = 0; i < m; i++)
      ww[i] = getInt();

    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        sum += hh[j];
        h[sum]++;
      }
      mm = max(mm, sum);
    }
    for (int i = 0; i < m; i++) {
      int sum = 0;
      for (int j = i; j < m; j++) {
        sum += ww[j];
        if (sum > mm)
          break;
        w[sum]++;
      }
    }
    long long ans = 0;
    for (int i = 0; i <= mm; i++) {
      if (w[i] | h[i]) {
        ans += (long long)w[i] * h[i];
        w[i] = h[i] = 0;
      }
    }

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

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

using namespace std;

int h[1024 * 1500];
int w[1024 * 1500];

int getInt() {
  int c = getchar();
  int ret = 0;
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main() {
  int n, m;
  while (n = getInt(), m = getInt(), n + m) {
    int hh[n];
    int ww[m];
    int mm = 0;

    for (int i = 0; i < n; i++)
      hh[i] = getInt();
    for (int i = 0; i < m; i++)
      ww[i] = getInt();

    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        sum += hh[j];
        h[sum]++;
      }
      mm = max(mm, sum);
    }
    for (int i = 0; i < m; i++) {
      int sum = 0;
      for (int j = i; j < m; j++) {
        sum += ww[j];
        if (sum > mm)
          break;
        w[sum]++;
      }
    }
    long long ans = 0;
    for (int i = 0; i <= mm; i++) {
      if (w[i] | h[i]) {
        ans += (long long)w[i] * h[i];
        w[i] = h[i] = 0;
      }
    }

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


#include <algorithm>
#include <iostream>
#include <list>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  // FILE* fp_in = freopen("data.txt", "r", stdin);

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

    vector<int> x, y;
    int sum = 0;
    x.push_back(0);
    y.push_back(0);

    for (int i = 0; i < n; i++) {
      int tmp;
      cin >> tmp;
      sum += tmp;
      y.push_back(sum);
    }
    sum = 0;
    for (int i = 0; i < m; i++) {
      int tmp;
      cin >> tmp;
      sum += tmp;
      x.push_back(sum);
    }

    int height = y.size();
    int width = x.size();

    int ans = 0;
    for (int i = 0; i < width; i++)
      for (int j = 0; j < height; j++)
        for (int k = i + 1; k < width; k++)
          for (int l = j + 1; l < height; l++)
            if (x.at(i) - x.at(k) == y.at(j) - y.at(l))
              ans++;

    cout << ans << endl;
  }

  // while(1){}
  return 0;
}

#include <algorithm>
#include <iostream>
#include <list>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int min(int p, int q) {
  if (p > q)
    return q;
  return p;
}

int main(void) {
  // FILE* fp_in = freopen("data.txt", "r", stdin);

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

    vector<int> x, y;
    int sum = 0;
    int xmax, ymax;
    x.push_back(0);
    y.push_back(0);

    for (int i = 0; i < n; i++) {
      int tmp;
      cin >> tmp;
      sum += tmp;
      y.push_back(sum);
    }
    ymax = sum;
    sum = 0;
    for (int i = 0; i < m; i++) {
      int tmp;
      cin >> tmp;
      sum += tmp;
      x.push_back(sum);
    }
    xmax = sum;

    vector<int> dx, dy;
    int width = x.size();
    int height = y.size();

    for (int i = 0; i <= xmax; i++)
      dx.push_back(0);
    for (int i = 0; i <= ymax; i++)
      dy.push_back(0);

    for (int i = 0; i < width; i++)
      for (int j = i + 1; j < width; j++)
        dx.at(x.at(j) - x.at(i))++;

    for (int i = 0; i < height; i++)
      for (int j = i + 1; j < height; j++)
        dy.at(y.at(j) - y.at(i))++;

    int ans = 0;
    int size = min(dx.size(), dy.size());

    for (int i = 0; i < size; i++)
      ans += dx.at(i) * dy.at(i);

    cout << ans << endl;
  }

  // while(1){}
  return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  while (1) {
    int n, m;
    cin >> n >> m;
    vector<int> hmap, wmap;
    vector<int> map;
    if (!n || !m)
      return 0;

    int o = 0;
    for (int i = 0; i < n; i++) {
      int h;
      cin >> h;
      hmap.push_back(o);
      o += h;
    }
    hmap.push_back(o);
    o = 0;
    for (int i = 0; i < m; i++) {
      int w;
      cin >> w;
      wmap.push_back(o);
      o += w;
    }
    wmap.push_back(o);

    int cnt = 0;
    map.resize(max(hmap[n], wmap[m]));
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        map[hmap[j] - hmap[i]] += 1;
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j < m + 1; j++) {
        int it = wmap[j] - wmap[i];
        if (map[it] > 0)
          cnt += map[it];
      }
    }

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

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

using namespace std;

int main(int argc, char const *argv[]) {
  while (1) {
    int n, m;
    cin >> n >> m;
    vector<int> hmap, wmap;
    vector<int> map;
    if (!n || !m)
      return 0;

    int o = 0;
    for (int i = 0; i < n; i++) {
      int h;
      cin >> h;
      hmap.push_back(o);
      o += h;
    }
    hmap.push_back(o);
    o = 0;
    for (int i = 0; i < m; i++) {
      int w;
      cin >> w;
      wmap.push_back(o);
      o += w;
    }
    wmap.push_back(o);

    int cnt = 0;
    map.resize(max(hmap[n], wmap[m]) + 10);
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        map[hmap[j] - hmap[i]]++;
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j < m + 1; j++) {
        int it = wmap[j] - wmap[i];
        if (map[it] > 0)
          cnt += map[it];
      }
    }

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


#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
int main() {

  for (int n, m; cin >> n >> m, n && m;) {
    int h[1500], w[1500], a0[MAX + 10] = {}, a1[MAX + 10] = {};
    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++)
      for (int j = 0; j < n - i + 1; j++) {
        int r = 0;
        for (int k = 0; k < i; k++)
          r += h[j + k];
        a0[r]++;
      }
    for (int i = 1; i <= m; i++)
      for (int j = 0; j < m - i + 1; j++) {
        int r = 0;
        for (int k = 0; k < i; k++)
          r += w[j + k];
        a1[r]++;
      }
    int r = 0;
    for (int i = 1; i <= MAX; i++)
      r += a0[i] * a1[i];
    cout << r << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int MAX = 1500000;
int main() {

  for (int n, m; cin >> n >> m, n && m;) {
    int h[1500], w[1500], a0[MAX + 10] = {}, a1[MAX + 10] = {};
    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++)
      for (int j = 0; j < n - i + 1; j++) {
        int r = 0;
        for (int k = 0; k < i; k++)
          r += h[j + k];
        a0[r]++;
      }
    for (int i = 1; i <= m; i++)
      for (int j = 0; j < m - i + 1; j++) {
        int r = 0;
        for (int k = 0; k < i; k++)
          r += w[j + k];
        a1[r]++;
      }
    int r = 0;
    for (int i = 1; i <= MAX; i++)
      r += a0[i] * a1[i];
    cout << r << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int Count(int square, const vector<int> &data, int size) {
  int res = 0, l = 0, r = 1;

  while (r < size && l < r) {
    int area = data[r] - data[l];
    if (square == area) {
      ++res;
      ++r;
      ++l;
    } else if (square < area) {
      ++l;
      if (l == r)
        ++r;
    } else {
      ++r;
    }
  }

  return res;
}

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

  int n, m;

  while (cin >> n >> m, n != 0 && m != 0) {
    vector<int> h(n + 1), w(m + 1);

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

    ++n, ++m;
    for (int i = 1; i < n; ++i)
      h[i] += h[i - 1];
    for (int i = 1; i < m; ++i)
      w[i] += w[i - 1];

    int lim = max(h[n - 1], w[m - 1]);
    int ans = 0;
    for (int d = 1; d <= lim; ++d) {
      int cnt_h = Count(d, h, n);
      int cnt_w = Count(d, w, m);

      ans += cnt_h * cnt_w;
    }

    cout << ans << endl;
  }

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAX_N = 1500 * 1000 + 5;
int size_w[MAX_N], size_h[MAX_N];

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

  int n, m;

  while (cin >> n >> m, n != 0 && m != 0) {
    vector<int> h(n + 1), w(m + 1);

    memset(size_h, 0, sizeof(size_h));
    memset(size_w, 0, sizeof(size_w));

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

    ++n, ++m;
    for (int i = 1; i < n; ++i)
      h[i] += h[i - 1];
    for (int i = 1; i < m; ++i)
      w[i] += w[i - 1];

    for (int l = 0; l < n - 1; ++l)
      for (int r = l + 1; r < n; ++r)
        ++size_h[h[r] - h[l]];
    for (int l = 0; l < m - 1; ++l)
      for (int r = l + 1; r < m; ++r)
        ++size_w[w[r] - w[l]];

    int lim = max(h[n - 1], w[m - 1]);
    int ans = 0;
    for (int d = 1; d <= lim; ++d)
      ans += size_h[d] * size_w[d];

    cout << ans << endl;
  }

  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r), end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define vary(type, name, size, init) vector<type> name(size, init)
#define vvl(v, w, h, init) vector<vector<ll>> v(w, vector<ll>(h, init))
#define mp(a, b) make_pair(a, b)

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array)                                                        \\
  for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T> void O(T t) { cout << t << endl; }
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P; //????´???°????????¢?????????????????¨?§£???
namespace std {
bool operator<(const P &a, const P &b) { // x????????????
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool sorty(const P &a, const P &b) { // y????????????
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
bool same(const P &a, const P &b) {
  P p = a - b;
  if (abs(real(p)) < EPS && abs(imag(p)) < EPS) {
    return true;
  }
  return false;
}
} // namespace std
double cross(const P &a, const P &b) { //??????
  return imag(conj(a) * b);
}
double dot(const P &a, const P &b) { //??????
  return real(conj(a) * b);
}

class L { // line
public:
  vector<P> l;
  P v;
  L(){};
  L(const P &a, const P &b) {
    l.push_back(a);
    l.push_back(b);
    v = (b - a);
  }
  L(double a, double b, double c, double d) {
    l.push_back(P(a, b)), l.push_back(P(c, d));
  }
  P &operator[](const int i) { return l[i]; }
  void readL() {
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    l.clear();
    l.push_back(P(a, b)), l.push_back(P(c, d));
  }
};

int ccw(P a, P b, P c) { // 3????????????????????§????????§??????????????????
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return +1; // counter clockwise
  if (cross(b, c) < 0)
    return -1; // clockwise
  if (dot(b, c) < 0)
    return +2; // c--a--b on line
  if (norm(b) < norm(c))
    return -2; // a--b--c on line
  return 0;    // a--c--b on line
}
bool intersectLL(L &l, L &m) {
  return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel
         abs(cross(l[1] - l[0], m[0] - l[0])) < EPS;   // same line
}
bool intersectLS(L &l, L &s) {
  return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l
             cross(l[1] - l[0], s[1] - l[0]) <
         EPS; // s[1] is right of l
}
bool intersectLP(L &l, P &p) { return abs(cross(l[1] - p, l[0] - p)) < EPS; }
bool intersectSS(L &s, L &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool intersectSP(L &s, P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) <
         EPS; // triangle inequality
}
// L & P intersection
P projection(L &l, P &p) {
  double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
  return l[0] + t * (l[0] - l[1]);
}
// L????????????P???????°????
P reflection(L &l, P &p) { return p + 2.0 * (projection(l, p) - p); }
P crosspointSS(L &l1, L &l2) {
  double d1 = abs(cross(l2.v, l1[0] - l2[0])); // l1.a - l2.b???
  double d2 = abs(cross(l2.v, l1[1] - l2[0]));
  double t = d1 / (d1 + d2);
  return l1[0] + t * l1.v;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  double d = 1000 * 1510;
  ll n, m, k;
  double w, b;
  while (cin >> n >> m, n + m) {
    P a, b;
    vector<P> ps((n + 1) * (m + 1));
    vector<L> x(n + 1), y(m + 1);
    y[0] = L(P(-1, 0), P(d, 0));
    x[0] = L(P(0, -1), P(0, d));
    k = 0;
    rep(i, n) {
      cin >> w;
      k += w;
      a = P(k, -1), b = P(k, d);
      x[i + 1] = L(a, b);
    }
    k = 0;
    rep(i, m) {
      cin >> w;
      k += w;
      a = P(-1, k), b = P(d, k);
      y[i + 1] = L(a, b);
    }
    rep(i, n + 1) {
      rep(j, m + 1) { ps[i * (m + 1) + j] = (crosspointSS(x[i], y[j])); }
    }
    sort(all(ps));
    ll cnt = 0, fc = 0;
    vector<bool> f(ps.size(), true);
    rep(i, ps.size()) {
      if (!f[i])
        continue;
      f[i] = false;
      ++fc;
      P p = ps[i] + P(d, d);
      L l(ps[i], p);
      ll c = 1;
      REP(j, i + 1, ps.size()) {
        if (intersectLP(l, ps[j])) {
          f[j] = false;
          ++fc;
          ++c;
        }
      }
      cnt += c * (c - 1) / 2;
      if (fc >= ps.size())
        break;
    }
    cout << cnt << endl;
  }
  return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r), end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define vary(type, name, size, init) vector<type> name(size, init)
#define vvl(v, w, h, init) vector<vector<ll>> v(w, vector<ll>(h, init))
#define mp(a, b) make_pair(a, b)

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array)                                                        \\
  for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T> void O(T t) { cout << t << endl; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  double d = 1000 * 1510;
  ll n, m, k;
  double w, b;
  while (cin >> n >> m, n + m) {
    vector<ll> x(n + 1), y(m + 1);
    k = 0;
    rep(i, n) {
      cin >> w;
      k += w;
      x[i + 1] = k;
    }
    k = 0;
    rep(i, m) {
      cin >> w;
      k += w;
      y[i + 1] = k;
    }
    map<int, int> ans;
    rep(i, n + 1) {
      rep(j, m + 1) { ans[int(y[j] - x[i])]++; }
    }
    ll cnt = 0;
    for (auto p : ans) {
      int o = p.se;
      cnt += o * (o - 1) / 2;
    }
    cout << cnt << endl;
  }
  return 0;
}


// #include<bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef int int__;
#define rep(i, j) for (int__(i) = 0; (i) < (j); (i)++)
#define repeat(i, j, k) for (int__ i = (j); i < (k); (i)++)
#define all(v) begin(v), end(v)

class Binary_Indexed_Tree {
private:
  vector<int> bit;

public:
  Binary_Indexed_Tree(int n) { bit.resize(n + 1, 0); }
  // index 0 to i ???????????????
  int sum(int i) {
    int s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & (-i); // i& -i ???i???????°?1bit  <- 2^k?????????
    }
    return s;
  }
  // index i to j ??????
  int sum(int i, int j) { return sum(j) - sum(i - 1); }
  // index i ??? x ?????????
  void add(int i, int x) {
    while (i <= bit.size()) {
      bit[i] += x;
      i += i & (-i);
    }
  }
};

int main() {

  while (true) {
    int N, M;
    cin >> N >> M;
    if (N == 0 and M == 0)
      break;
    Binary_Indexed_Tree H(N), W(M);

    rep(i, N) {
      int in;
      cin >> in;
      H.add(i + 1, in);
    }

    rep(i, M) {
      int in;
      cin >> in;
      W.add(i + 1, in);
    }

    map<int, unsigned char> lens_w, lens_h;
    rep(i, N + 1) {
      rep(j, i) {
        int len = H.sum(j + 1, i);
        lens_h[len]++;
      }
    }
    rep(i, M + 1) {
      rep(j, i) { lens_w[W.sum(j + 1, i)]++; }
    }

    int ans = 0;
    for (auto num : lens_h) {
      if (num.first == 0)
        continue;
      ans += num.second * lens_w[num.first];
    }
    cout << ans << endl;
  }

  return 0;
}

// #include<bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef int int__;
#define rep(i, j) for (int__(i) = 0; (i) < (j); (i)++)
#define repeat(i, j, k) for (int__ i = (j); i < (k); (i)++)
#define all(v) begin(v), end(v)

class Binary_Indexed_Tree {
private:
  vector<ll> bit;

public:
  Binary_Indexed_Tree(ll n) { bit.resize(n + 1, 0); }
  // index 0 to i ???????????????
  ll sum(ll i) {
    ll s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & (-i); // i& -i ???i????????°?1bit  <- 2^k?????????
    }
    return s;
  }
  // index i to j ??????
  ll sum(ll i, ll j) { return sum(j) - sum(i - 1); }
  // index i ??? x ?????????
  void add(ll i, ll x) {
    while (i < bit.size()) {
      bit[i] += x;
      i += i & (-i);
    }
  }
};

int main() {

  while (true) {
    ll N, M;
    cin >> N >> M;
    if (N == 0 and M == 0)
      break;
    Binary_Indexed_Tree H(N), W(M);

    rep(i, N) {
      ll in;
      cin >> in;
      H.add(i + 1, in);
    }

    rep(i, M) {
      ll in;
      cin >> in;
      W.add(i + 1, in);
    }

    map<ll, ll> lens_w, lens_h;
    rep(i, N + 1) {
      rep(j, i) {
        ll len = H.sum(j + 1, i);
        lens_h[len]++;
      }
    }
    rep(i, M + 1) {
      rep(j, i) { lens_w[W.sum(j + 1, i)]++; }
    }

    ll ans = 0;
    for (auto num : lens_h) {
      if (num.first == 0)
        continue;
      ans += num.second * lens_w[num.first];
    }
    cout << ans << endl;
  }

  return 0;
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOREQ(i, k, n) for (int i = (k); i <= (int)(n); ++i)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FIND(m, w) ((m).find(w) != (m).end())

int main(void) {
  int N, M;
  while (cin >> N >> M, N) {
    vector<int> h(N);
    vector<int> w(M);
    vector<int> sumh(N + 1);
    vector<int> sumw(M + 1);
    REP(i, N) cin >> h[i];
    REP(i, M) cin >> w[i];
    REP(i, N) sumh[i + 1] = h[i] + sumh[i];
    REP(i, M) sumw[i + 1] = w[i] + sumw[i];
    int ans = 0;
    FOR(y1, 0, N + 1)
    FOR(y2, y1 + 1, N + 1) FOR(x1, 0, M + 1) FOR(x2, x1 + 1, M + 1) {
      if (sumh[y2] - sumh[y1] == sumw[x2] - sumw[x1]) {
        ans++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

int main() {
  int N, M;
  while (cin >> N >> M, N) {
    vector<int> h(N);
    vector<int> w(M);
    REP(i, N) cin >> h[i];
    REP(i, M) cin >> w[i];
    vector<int> sh(N + 1);
    vector<int> sw(M + 1);
    REP(i, N) sh[i + 1] = sh[i] + h[i];
    REP(i, M) sw[i + 1] = sw[i] + w[i];
    map<int, int> count;
    REP(i, N) FOR(j, i + 1, N + 1) { count[sh[j] - sh[i]]++; }
    int ans = 0;
    REP(i, M) FOR(j, i + 1, M + 1) { ans += count[sw[j] - sw[i]]; }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

int calc_array(vector<vector<int>> &v_array, int start, int end,
               int a_array[1500]);
// int calc_array_w(vector< vector<int> > &v_array,int start,int end);

int main(void) {

  int n, m;
  int answer;
  int max_h = 0;
  int max_w = 0;

  int h[1500];
  int w[1500];

  vector<vector<int>> h_value;
  vector<vector<int>> w_value;
  vector<int> ans_array_h(1500 * 1000);
  vector<int> ans_array_w(1500 * 1000);

  h_value.resize(1500);
  for (int i = 0; i < 1500; i++) {
    h_value[i].resize(1500);
    // fill(h_value[i].begin(),h_value[i].end(),0);
  }
  w_value.resize(1500);
  for (int i = 0; i < 1500; i++) {
    w_value[i].resize(1500);
    // fill(w_value[i].begin(),w_value[i].end(),0);
  }

  while (1) {
    fill(ans_array_h.begin(), ans_array_h.end(), 0);
    fill(ans_array_w.begin(), ans_array_w.end(), 0);
    memset(h, 0, sizeof(int) * 1500);
    memset(w, 0, sizeof(int) * 1500);

    cin >> n;
    cin >> m;

    if (n == 0 && m == 0)
      break;
    else {
      // cout << "n:" << n << endl;
      for (int i = 0; i < n; i++) {
        cin >> h[i];
        // cout << h[i] << endl;
      }
      // cout << "m:" << m << endl;
      for (int i = 0; i < m; i++) {
        cin >> w[i];
        // cout << w[i] << endl;
      }

      for (int i = 0; i < 1500; i++) {
        fill(h_value[i].begin(), h_value[i].end(), 0);
        fill(w_value[i].begin(), w_value[i].end(), 0);
      }

      calc_array(h_value, 0, n - 1, h);
      calc_array(w_value, 0, m - 1, w);
      // calc_array_w(w_value);
    }

    max_h = 0;
    max_w = 0;

    // cout << "h_array" << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        // cout << h_value[i][j] << ",";
        if (h_value[i][j] > max_h)
          max_h = h_value[i][j];
        ans_array_h[h_value[i][j]] += 1;
      }
      // cout << endl;
    }

    // cout << "w_array" << endl;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        // cout << w_value[i][j] << ",";
        if (w_value[i][j] > max_w)
          max_w = w_value[i][j];
        ans_array_w[w_value[i][j]] += 1;
      }
      // cout << endl;
    }
    // cout << "h_array_ans" << endl;
    for (int i = 0; i < max_h; i++) {
      if (ans_array_h[i] != 0) {
        // cout << i << ":" << ans_array_h[i] << endl;
      }
    }
    // cout << "w_array_ans" << endl;
    for (int i = 0; i < max_w; i++) {
      if (ans_array_w[i] != 0) {
        // cout << i << ":" << ans_array_w[i] << endl;
      }
    }
    answer = 0;
    for (int i = 1; i <= min(max_h, max_w); i++) {
      answer += ans_array_h[i] * ans_array_w[i];
    }

    // cout << "answer:" << answer << endl;
    cout << answer << endl;
  }

  return 0;
}

int calc_array(vector<vector<int>> &v_array, int start, int end,
               int a_array[1500]) {
  if (start > end)
    return -1;
  if (v_array[start][end] != 0)
    return 0;
  else {
    if (start == end) {
      if (v_array[start][end] == 0) {
        v_array[start][end] = a_array[start];
      }
    } else {
      for (int i = start; i <= end; i++) {
        v_array[start][end] += a_array[i];
      }
      for (int i = start; i <= end; i++) {
        calc_array(v_array, start, i, a_array);
        calc_array(v_array, i + 1, end, a_array);
      }
    }
  }
  return 0;
}

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

using namespace std;

int calc_array(vector<vector<int>> &v_array, int start, int end,
               int a_array[1500]);
// int calc_array_w(vector< vector<int> > &v_array,int start,int end);

int main(void) {

  int n, m;
  int answer;
  int max_h = 0;
  int max_w = 0;

  int h[1500];
  int w[1500];

  vector<vector<int>> h_value;
  vector<vector<int>> w_value;
  vector<int> ans_array_h(1500 * 1000);
  vector<int> ans_array_w(1500 * 1000);

  h_value.resize(1500);
  for (int i = 0; i < 1500; i++) {
    h_value[i].resize(1500);
    // fill(h_value[i].begin(),h_value[i].end(),0);
  }
  w_value.resize(1500);
  for (int i = 0; i < 1500; i++) {
    w_value[i].resize(1500);
    // fill(w_value[i].begin(),w_value[i].end(),0);
  }

  while (1) {
    fill(ans_array_h.begin(), ans_array_h.end(), 0);
    fill(ans_array_w.begin(), ans_array_w.end(), 0);
    memset(h, 0, sizeof(int) * 1500);
    memset(w, 0, sizeof(int) * 1500);

    cin >> n;
    cin >> m;

    if (n == 0 && m == 0)
      break;
    else {
      for (int i = 0; i < 1500; i++) {
        fill(h_value[i].begin(), h_value[i].end(), 0);
        fill(w_value[i].begin(), w_value[i].end(), 0);
      }
      // cout << "n:" << n << endl;
      for (int i = 0; i < n; i++) {
        cin >> h[i];
        h_value[i][i] = h[i];
        // cout << h[i] << endl;
      }
      // cout << "m:" << m << endl;
      for (int i = 0; i < m; i++) {
        cin >> w[i];
        w_value[i][i] = w[i];
        // cout << w[i] << endl;
      }

      // calc_array(h_value,0,n-1,h);
      // calc_array(w_value,0,m-1,w);
      for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
          h_value[i][j] = h_value[i][j - 1] + h[j];
        }
      }
      for (int i = 0; i < m; i++) {
        for (int j = i + 1; j < m; j++) {
          w_value[i][j] = w_value[i][j - 1] + w[j];
        }
      }
    }

    max_h = 0;
    max_w = 0;

    // cout << "h_array" << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        // cout << h_value[i][j] << ",";
        if (h_value[i][j] > max_h)
          max_h = h_value[i][j];
        ans_array_h[h_value[i][j]] += 1;
      }
      // cout << endl;
    }

    // cout << "w_array" << endl;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        // cout << w_value[i][j] << ",";
        if (w_value[i][j] > max_w)
          max_w = w_value[i][j];
        ans_array_w[w_value[i][j]] += 1;
      }
      // cout << endl;
    }
    // cout << "h_array_ans" << endl;
    for (int i = 0; i < max_h; i++) {
      if (ans_array_h[i] != 0) {
        // cout << i << ":" << ans_array_h[i] << endl;
      }
    }
    // cout << "w_array_ans" << endl;
    for (int i = 0; i < max_w; i++) {
      if (ans_array_w[i] != 0) {
        // cout << i << ":" << ans_array_w[i] << endl;
      }
    }
    answer = 0;
    for (int i = 1; i <= min(max_h, max_w); i++) {
      answer += ans_array_h[i] * ans_array_w[i];
    }

    // cout << "answer:" << answer << endl;
    cout << answer << endl;
  }

  return 0;
}

/*
int calc_array(vector< vector<int> > &v_array,int start,int end,int
a_array[1500]){ if(v_array[start][end] != 0) return 0; if(start > end) return
-1; else{ if(start == end){ if( v_array[start][end] == 0 ){ v_array[start][end]
= a_array[start];
      }
    }
    else{
      for(int i=start;i<=end;i++){
        v_array[start][end] += a_array[i];
      }
      for(int i=start;i<=end;i++){
        calc_array(v_array,start,i,a_array);
        calc_array(v_array,i+1,end,a_array);
      }
    }
  }
  return 0;
}
*/


#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;
map<int, int> wide, hight;
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];
      // cout<<"h: "<<sum<<endl;
      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];
      // cout<<"w: "<<sum<<endl;
      wide[sum]++;
    }
  }
}

void solve() {
  ans = 0;
  wide.clear();
  hight.clear();
  for (int i = 0; i < n; i++)
    cin >> h[i];
  enumerate_hight();
  for (int i = 0; i < m; i++)
    cin >> w[i];
  enumerate_wide();
  // rep(i,100)cout<<i<<":  "<<wide[i]<<" "<<hight[i]<<endl;
  rep(i, 1500001) if (wide[i] != 0 && hight[i] != 0) ans += wide[i] * hight[i];
  cout << ans << endl;
}

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

#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];
      // cout<<"h: "<<sum<<endl;
      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];
      // cout<<"w: "<<sum<<endl;
      wide[sum]++;
    }
  }
}

void solve() {
  ans = 0;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  enumerate_hight();
  for (int i = 0; i < m; i++)
    cin >> w[i];
  enumerate_wide();
  // rep(i,100)cout<<i<<":  "<<wide[i]<<" "<<hight[i]<<endl;
  rep(i, 1500001) {
    ans += wide[i] * hight[i];
    wide[i] = hight[i] = 0;
  }
  cout << ans << endl;
}

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


//?????????????????§??????????????????????????£????????????
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#define PB push_back
#define in scanf
#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 IREP(i, n) for (int i = 0; i <= (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
int N, M;
int h[1501], w[1501], tw[1502] = {}, th[1502] = {};
// int hhh[15000001]={};
// int www[15000001]={};
void solve() {
  while (cin >> N >> M, N != 0) {
    REP(i, N) cin >> h[i];
    REP(i, M) cin >> w[i];
    tw[0] = th[0] = 0;
    REP(i, N) { th[i + 1] = th[i] + h[i]; }
    REP(i, M) tw[i + 1] = tw[i] + w[i];
    int hhh[th[N] + 1];
    int www[tw[N] + 1];
    memset(www, 0, sizeof(www));
    memset(hhh, 0, sizeof(hhh)); // vector <int>hh,ww;
    int temp;
    for (int s = 0; s <= N; s++) {
      for (int g = s + 1; g <= N; g++) {
        temp = th[g] - th[s];
        // hh.PB(temp);
        hhh[temp]++;
      }
    }
    for (int s = 0; s <= M; s++) {
      for (int g = s + 1; g <= M; g++) {

        temp = tw[g] - tw[s];
        www[temp]++;
        // cout << temp <<endl;
        // ww.PB(temp);
      }
    }
    int m = min(th[N], tw[N]);

    int res = 0;
    REP(i, m + 1) res += www[i] * hhh[i];
    cout << res << endl;
  }
}

int main() { solve(); }


#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, m, n) for (int i = m; i >= n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265

void search(int n, int m) {
  int h[2000], w[2000];

  rep(i, n) { cin >> h[i]; }
  rep(i, m) { cin >> w[i]; }

  map<int, int> a, b;

  rep(i, n) {
    int sum = 0;
    FOR(j, i, n) {
      sum += h[j];
      a[sum]++;
    }
  }
  rep(i, m) {
    int sum = 0;
    FOR(j, i, m) {
      sum += w[j];
      b[sum]++;
    }
  }

  int ans = 0;

  rep(i, 1e6) { ans += a[i] * b[i]; }

  cout << ans << endl;
}

int main() {
  int n, m;

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

    search(n, m);
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, m, n) for (int i = m; i >= n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265

void search(int n, int m) {
  int h[2000], w[2000];

  rep(i, n) { cin >> h[i]; }
  rep(i, m) { cin >> w[i]; }

  map<int, int> a, b;

  rep(i, n) {
    int sum = 0;
    FOR(j, i, n) {
      sum += h[j];
      a[sum]++;
    }
  }
  rep(i, m) {
    int sum = 0;
    FOR(j, i, m) {
      sum += w[j];
      b[sum]++;
    }
  }

  int ans = 0;

  for (auto itr = a.begin(); itr != a.end(); itr++) {
    ans += itr->second * b[itr->first];
  }

  cout << ans << endl;
}

int main() {
  int n, m;

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

    search(n, m);
  }

  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while (cin >> N >> M, N + M != 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> sum_h(N + 1, 0), sum_w(M + 1, 0);
    for (int i = 0; i < N; i++) {
      sum_h[i + 1] = sum_h[i] + h[i];
    }
    for (int i = 0; i < M; i++) {
      sum_w[i + 1] = sum_w[i] + w[i];
    }

    // N<=1500,M<=1500 ってこれ計算量やばい
    // 累積和ー＞全探索むりそう
    // 堂々たるTLE
    int ans = 0;
    for (int i = 0; i < N; i++)
      for (int j = i + 1; j < N + 1; j++)
        for (int k = 0; k < M; k++)
          for (int l = k + 1; l < M + 1; l++)
            if (sum_h[j] - sum_h[i] == sum_w[l] - sum_w[k])
              ans++;
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int N, M;
  while (cin >> N >> M, N + M) {
    vector<int> h(N), w(M);
    int totalH = 0, totalW = 0;
    for (int i = 0; i < N; i++) {
      cin >> h[i];
      totalH += h[i];
    }
    for (int i = 0; i < M; i++) {
      cin >> w[i];
      totalW += w[i];
    }

    vector<int> height(totalH + 1, 0), width(totalW + 1, 0);
    for (int i = 0; i < N; i++) {
      int k = h[i];
      height[k]++;
      for (int j = i + 1; j < N; j++) {
        k += h[j];
        height[k]++;
      }
    }
    for (int i = 0; i < M; i++) {
      int k = w[i];
      width[k]++;
      for (int j = i + 1; j < M; j++) {
        k += w[j];
        width[k]++;
      }
    }

    int ans = 0;
    for (int i = 1; i <= min(totalH, totalW); i++) {
      ans += height[i] * width[i];
    }
    cout << ans << endl;
  }
}


#include <map>
#include <stdio.h>
#include <vector>

auto solve(int N, int M) -> int {
  using namespace std;
  vector<int> h(N);
  vector<int> w(M);

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

  map<int, int> &eh = *(new map<int, int>());
  map<int, int> &ew = *(new map<int, int>());
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = i; j < N; j++) {
      sum += h[j];
      if (eh.find(sum) != ew.end())
        eh[sum]++;
      else
        eh[sum] = 1;
    }
  }
  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = i; j < M; j++) {
      sum += w[j];
      if (ew.find(sum) != ew.end())
        ew[sum]++;
      else
        ew[sum] = 1;
    }
  }

  int ans = 0;
  for (auto p : eh) {
    if (ew.find(p.first) != ew.end())
      ans += p.second * ew[p.first];
  }

  return ans;
}

auto main() -> int {
  int n, m;
  while (1) {
    scanf("%d%d", &n, &m);
    if (!(n | m))
      break;
    printf("%d\\n", solve(n, m));
  }
}

#include <map>
#include <stdio.h>
#include <vector>

auto solve(int N, int M) -> int {
  using namespace std;
  vector<int> h(N);
  vector<int> w(M);

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

  map<int, int> eh;
  map<int, int> ew;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = i; j < N; j++) {
      sum += h[j];
      if (eh.find(sum) != ew.end())
        eh[sum]++;
      else
        eh[sum] = 1;
    }
  }
  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = i; j < M; j++) {
      sum += w[j];
      if (ew.find(sum) != ew.end())
        ew[sum]++;
      else
        ew[sum] = 1;
    }
  }

  int ans = 0;
  for (auto p : eh) {
    if (ew.find(p.first) != ew.end())
      ans += p.second * ew[p.first];
  }

  return ans;
}

auto main() -> int {
  int n, m;
  while (1) {
    scanf("%d%d", &n, &m);
    if (!(n | m))
      break;
    printf("%d\\n", solve(n, m));
  }
}


#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX / 2 - 1
#define pb push_back
#define MAX 1500

using namespace std;

int memoH[MAX][MAX];
int memoW[MAX][MAX];
int countH[MAX * 100 + 1];
int countW[MAX * 100 + 1];

int main() {
  int n, m, res;
  while (cin >> n >> m, n | m) {
    res = 0;
    for (int i = 0; i < MAX; i++) {
      for (int j = 0; j < MAX; j++) {
        memoH[i][j] = memoW[i][j] = -1;
      }
    }
    for (int i = 0; i <= MAX * 100; i++) {
      countH[i] = countW[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> memoH[i][i];
    }
    for (int i = 0; i < m; i++) {
      cin >> memoW[i][i];
    }
    for (int j = 0; j < n; j++) {
      for (int i = 0; i < n - j; i++) {
        if (memoH[i + 1 + j][i + 1 + j] == -1)
          break;
        memoH[i][i + 1 + j] = memoH[i][i + j] + memoH[i + 1 + j][i + 1 + j];
      }
    }
    for (int j = 0; j < m; j++) {
      for (int i = 0; i < m - j; i++) {
        if (memoW[i + 1 + j][i + 1 + j] == -1)
          break;
        memoW[i][i + 1 + j] = memoW[i][i + j] + memoW[i + 1 + j][i + 1 + j];
      }
    }
    for (int i = 0; i < MAX; i++) {
      for (int j = i; j < MAX; j++) {
        if (memoH[i][j] != -1)
          countH[memoH[i][j]]++;
        if (memoW[i][j] != -1)
          countW[memoW[i][j]]++;
      }
    }
    for (int i = 0; i <= MAX * 100; i++) {
      res += countH[i] * countW[i];
    }
    cout << res << el;
  }
}

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX / 2 - 1
#define pb push_back
#define MAX 1500

using namespace std;

int memoH[MAX + 1][MAX + 1];
int memoW[MAX + 1][MAX + 1];
int countH[MAX * 1000 + 1];
int countW[MAX * 1000 + 1];

int main() {
  int n, m, res;
  while (cin >> n >> m, n | m) {
    res = 0;
    for (int i = 0; i <= MAX; i++) {
      for (int j = 0; j <= MAX; j++) {
        memoH[i][j] = memoW[i][j] = -1;
      }
    }
    for (int i = 0; i <= MAX * 1000; i++) {
      countH[i] = countW[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> memoH[i][i];
    }
    for (int i = 0; i < m; i++) {
      cin >> memoW[i][i];
    }
    for (int j = 0; j < n; j++) {
      for (int i = 0; i < n - j; i++) {
        if (memoH[i + 1 + j][i + 1 + j] == -1)
          break;
        memoH[i][i + 1 + j] = memoH[i][i + j] + memoH[i + 1 + j][i + 1 + j];
      }
    }
    for (int j = 0; j < m; j++) {
      for (int i = 0; i < m - j; i++) {
        if (memoW[i + 1 + j][i + 1 + j] == -1)
          break;
        memoW[i][i + 1 + j] = memoW[i][i + j] + memoW[i + 1 + j][i + 1 + j];
      }
    }
    for (int i = 0; i < MAX; i++) {
      for (int j = i; j < MAX; j++) {
        if (memoH[i][j] != -1)
          countH[memoH[i][j]]++;
        if (memoW[i][j] != -1)
          countW[memoW[i][j]]++;
      }
    }
    for (int i = 0; i <= MAX * 1000; i++) {
      res += countH[i] * countW[i];
    }
    cout << res << el;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template <typename T> inline
#define TTF_ template <typename T, typename F> inline
TT_ T sq(T x) { return x * x; }
TT_ T In() {
  T x;
  cin >> x;
  return x;
}
TT_ void Out(T &x) { cout << x; }
TT_ void sort(T &v) { sort(begin(v), end(v)); }
TT_ void revs(T &v) { reverse(begin(v), end(v)); }
TT_ void uniq(T &v) {
  sort(v);
  v.erase(unique(begin(v), end(v)), end(v));
}
TT_ int ubnd(T &v, typename T::value_type x) {
  return upper_bound(begin(v), end(v), x) - begin(v);
}
TT_ int lbnd(T &v, typename T::value_type x) {
  return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF_ void inpt(T &v, int n, F f) {
  for (v.reserve(n); n--; v.emplace_back(f()))
    ;
}
TTF_ void show(T &v, F f, string d = " ", string e = "\\n") {
  int i = 0;
  for (auto &x : v)
    i++ && (cout << d), f(x);
  cout << e;
}
TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); }
TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); }

inline void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
  ll r = 1;
  for (; k > 0; a = a * a % m, k >>= 1)
    if (k & 1)
      r = r * a % m;
  return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }
//}}} priority_queue queue deque front stringstream max_element min_element
//insert count make_tuple

short B[3000300];
int H[2048], W[2048];
int main() {
  int N, M;
  short K = 0;
  while (N = in(), M = in()) {
    K++;
    for (int i = 1; i <= N; i++) {
      H[i] = H[i - 1] + in();
      B[H[i]] = K;
    }
    for (int i = 1; i <= M; i++) {
      W[i] = W[i - 1] + in();
    }
    int ans = 0;
    for (int y = 0, y_ = N; y < y_; y++) {
      const int hy = H[y];
      for (int x = 0, x_ = M; x < x_; x++) {
        const int wx = W[x];
        for (int z = x + 1, z_ = M; z <= z_; z++) {
          int d = W[z] - wx;
          ans += B[hy + d] == K;
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template <typename T> inline
#define TTF_ template <typename T, typename F> inline
TT_ T sq(T x) { return x * x; }
TT_ T In() {
  T x;
  cin >> x;
  return x;
}
TT_ void Out(T &x) { cout << x; }
TT_ void sort(T &v) { sort(begin(v), end(v)); }
TT_ void revs(T &v) { reverse(begin(v), end(v)); }
TT_ void uniq(T &v) {
  sort(v);
  v.erase(unique(begin(v), end(v)), end(v));
}
TT_ int ubnd(T &v, typename T::value_type x) {
  return upper_bound(begin(v), end(v), x) - begin(v);
}
TT_ int lbnd(T &v, typename T::value_type x) {
  return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF_ void inpt(T &v, int n, F f) {
  for (v.reserve(n); n--; v.emplace_back(f()))
    ;
}
TTF_ void show(T &v, F f, string d = " ", string e = "\\n") {
  int i = 0;
  for (auto &x : v)
    i++ && (cout << d), f(x);
  cout << e;
}
TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); }
TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); }

inline void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
  ll r = 1;
  for (; k > 0; a = a * a % m, k >>= 1)
    if (k & 1)
      r = r * a % m;
  return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }
//}}} priority_queue queue deque front stringstream max_element min_element
//insert count make_tuple

short B[3000300];
int H[2048], W[2048];
int main() {
  int N, M;
  short K = 0;
  while (N = in(), M = in()) {
    K++;
    for (int i = 1; i <= N; i++) {
      H[i] = H[i - 1] + in();
      B[H[i]] = K;
    }
    for (int i = 1; i <= M; i++) {
      W[i] = W[i - 1] + in();
    }
    int ans = 0;
    for (int y = 0; y < N; y++) {
      for (int x = 0; x < M; x++) {
        for (int z = x + 1; z <= M; z++) {
          int d = W[z] - W[x];
          if (H[N] - H[y] < d)
            break;
          ans += B[H[y] + d] == K;
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

const int N = 100;

int h, w;
int A[N];
int B[N];

void init() {}

bool input() {
  cin >> h >> w;
  if (h == 0)
    return 0;
  rep(i, h) cin >> A[i];
  rep(i, w) cin >> B[i];
  return true;
}

int solve() {
  int C[N] = {0};
  int D[N] = {0};
  rep(i, h) { C[i + 1] = C[i] + A[i]; }
  rep(i, w) { D[i + 1] = D[i] + B[i]; }

  map<int, int> sum;
  rep(i, h) {
    reps(j, i, h) {
      int s = C[j + 1] - C[i];
      sum[s]++;
      // printf("s %d  %d\\n",s,sum[s]);
    }
  }

  int ans = 0;
  rep(i, w) {
    reps(j, i, w) {
      int s = D[j + 1] - D[i];
      ans += sum[s];
      // printf("g %d  %d\\n",s,sum[s]);
    }
  }

  return ans;
}
int main() {
  while (init(), input())
    printf("%d\\n", solve());
}

#include <bits/stdc++.h>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

const int N = 1600;

int h, w;
int A[N];
int B[N];

void init() {}

bool input() {
  cin >> h >> w;
  if (h == 0)
    return 0;
  rep(i, h) cin >> A[i];
  rep(i, w) cin >> B[i];
  return true;
}

int solve() {
  int C[N] = {0};
  int D[N] = {0};
  rep(i, h) { C[i + 1] = C[i] + A[i]; }
  rep(i, w) { D[i + 1] = D[i] + B[i]; }

  map<int, int> sum;
  rep(i, h) {
    reps(j, i, h) {
      int s = C[j + 1] - C[i];
      sum[s]++;
      // printf("s %d  %d\\n",s,sum[s]);
    }
  }

  int ans = 0;
  rep(i, w) {
    reps(j, i, w) {
      int s = D[j + 1] - D[i];
      ans += sum[s];
      // printf("g %d  %d\\n",s,sum[s]);
    }
  }

  return ans;
}
int main() {
  while (init(), input())
    printf("%d\\n", solve());
}


#include <iostream>
#include <map>
#include <set>

using namespace std;

int main() {
  while (1) {
    int N, M;
    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];
    }

    set<int> v1, v2;
    map<int, int> m1, m2;
    for (int i = 0; i < N; i++) {
      int bfr = 0;
      for (int j = i; j < N; j++) {
        int temp;
        temp = bfr + H[j];
        bfr = temp;
        v1.insert(temp);
        m1[temp]++;
      }
    }
    for (int i = 0; i < M; i++) {
      int bfr = 0;
      for (int j = i; j < M; j++) {
        int temp;
        temp = bfr + W[j];
        bfr = temp;
        v2.insert(temp);
        m2[temp]++;
      }
    }

    int cnt = 0;
    set<int>::iterator it1 = v1.begin();
    while (it1 != v1.end()) {
      set<int>::iterator it2 = v2.begin();
      while (it2 != v2.end()) {
        if (*it1 == *it2)
          cnt += m1[*it1] * m2[*it2];
        it2++;
      }
      it1++;
    }
    cout << cnt << endl;
  }
  return 0;
}

#include <iostream>
#include <map>
#include <set>

using namespace std;

int main() {
  while (1) {
    int N, M;
    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];
    }

    set<int> v1, v2;
    map<int, int> m1, m2;
    for (int i = 0; i < N; i++) {
      int bfr = 0;
      for (int j = i; j < N; j++) {
        int temp;
        temp = bfr + H[j];
        bfr = temp;
        v1.insert(temp);
        m1[temp]++;
      }
    }
    for (int i = 0; i < M; i++) {
      int bfr = 0;
      for (int j = i; j < M; j++) {
        int temp;
        temp = bfr + W[j];
        bfr = temp;
        v2.insert(temp);
        m2[temp]++;
      }
    }

    int cnt = 0;
    set<int>::iterator it1 = v1.begin();
    while (it1 != v1.end()) {
      set<int>::iterator it2;
      it2 = v2.find(*it1);
      if (it2 != v2.end())
        cnt += m1[*it1] * m2[*it2];
      it1++;
    }
    cout << cnt << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF (1e9 + 7)

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m and n + m) {
    vector<int> nsroad(n + 1);
    vector<int> weroad(m + 1);
    nsroad[0] = 0;
    weroad[0] = 0;
    REP(i, n) {
      int tmp;
      cin >> tmp;
      nsroad[i + 1] = nsroad[i] + tmp;
    }
    REP(i, m) {
      int tmp;
      cin >> tmp;
      weroad[i + 1] = weroad[i] + tmp;
    }
    int res = 0;
    REP(i, nsroad.size()) REP(j, i) {
      int width = nsroad[i] - nsroad[j];
      int fr = 0;
      int to = 0;
      while (fr < weroad.size()) {
        if (to >= weroad.size())
          break;
        if (weroad[to] - weroad[fr] == width) {
          res++;
          to++;
        }
        if (weroad[to] - weroad[fr] > width)
          fr++;
        if (weroad[to] - weroad[fr] < width)
          to++;
      }
    }
    cout << res << endl;
  }
  return 0;
}

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF (1e9 + 7)

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m and n + m) {
    vector<int> nsroad(n + 1);
    vector<int> weroad(m + 1);
    nsroad[0] = 0;
    weroad[0] = 0;
    REP(i, n) {
      int tmp;
      cin >> tmp;
      nsroad[i + 1] = nsroad[i] + tmp;
    }
    REP(i, m) {
      int tmp;
      cin >> tmp;
      weroad[i + 1] = weroad[i] + tmp;
    }
    int res = 0;
    map<int, int> counts;
    REP(i, nsroad.size()) REP(j, i) {
      int count = 0;
      int width = nsroad[i] - nsroad[j];
      if (counts.find(width) != counts.end()) {
        res += counts[width];
        continue;
      }
      int fr = 0;
      int to = 0;
      while (fr < weroad.size()) {
        if (to >= weroad.size())
          break;
        if (weroad[to] - weroad[fr] == width) {
          count++;
          to++;
        }
        if (weroad[to] - weroad[fr] > width)
          fr++;
        if (weroad[to] - weroad[fr] < width)
          to++;
      }
      counts[width] = count;
      res += count;
    }
    cout << res << endl;
  }
  return 0;
}


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

#define ll long long int

using namespace std;
typedef pair<int, int> P;

string str;

int main() {
  int n, m;
  int h[1505];
  int w[1505];
  int i, j, k, l;

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

    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n + 1; j++) {
        for (k = 0; k < m; k++) {
          for (l = k + 1; l < m + 1; l++) {
            int tate = 0, yoko = 0;
            for (int x = i; x < j; x++)
              tate += h[x];
            for (int x = k; x < l; x++)
              yoko += w[x];
            if (tate == yoko)
              sum++;
          }
        }
      }
    }
    cout << sum << endl;
  }
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int n, m;
  while (cin >> n >> m, n + m) {
    vi h(n + 1), w(m + 1);
    h[0] = w[0] = 0;
    rep(i, n) cin >> h[i + 1];
    rep(i, m) cin >> w[i + 1];
    rep(i, n) h[i + 1] += h[i];
    rep(i, m) w[i + 1] += w[i];
    vi v1, v2;
    rep(i, n) loop(j, i + 1, n + 1) v1.push_back(h[j] - h[i]);
    rep(i, m) loop(j, i + 1, m + 1) v2.push_back(w[j] - w[i]);
    /*
            rep(i,v1.size()) cout << v1[i] << endl;
            cout << endl;
            rep(i,v2.size()) cout << v2[i] << endl;
    */
    sort(all(v1));
    sort(all(v2));
    int ans = 0;
    rep(i, v1.size()) {
      int t = v1[i];
      ans += upper_bound(all(v2), t) - lower_bound(all(v2), t);
    }
    cout << ans << endl;
  }
}


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

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

using namespace std;

void make_map(vector<long> &sum, unordered_multimap<long, int> &map) {
  for (int i = 1; i < (int)sum.size(); i++) {
    for (int j = 0; i + j < (int)sum.size(); j++) {
      map.insert(make_pair(sum[i + j] - sum[j], DUMMY));
    }
  }
  return;
}

int main(void) {
  int N, M;
  while (cin >> N >> M, N > 0) {
    unordered_multimap<long, int> h_map;
    unordered_multimap<long, int> w_map;
    vector<long> h_sum;
    vector<long> w_sum;
    long result = 0;
    // hの累積和配列を作成
    h_sum.push_back(0);
    rep(i, N) {
      int h;
      cin >> h;
      h_sum.push_back(h_sum.back() + h);
    }
    // h_mapの構成
    make_map(h_sum, h_map);
    // wの累積和配列を作成
    w_sum.push_back(0);
    rep(i, M) {
      int w;
      cin >> w;
      w_sum.push_back(w_sum.back() + w);
    }
    // w_mapの構成
    make_map(w_sum, w_map);

    // h_mapのイテレータを回して，同じキー値をもつw_mapの要素数だけresultを加算
    for (auto itr = h_map.begin(); itr != h_map.end(); itr++) {
      result += w_map.count((*itr).first);
    }

    // 出力
    cout << result << endl;
  }
  return 0;
}

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

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

using namespace std;

void make_map(vector<long> &sum, map<long, int> &map) {
  for (int i = 1; i < (int)sum.size(); i++) {
    for (int j = 0; i + j < (int)sum.size(); j++) {
      if (map.count(sum[i + j] - sum[j]) == 0) {
        map.insert(make_pair(sum[i + j] - sum[j], 1));
      } else {
        map[sum[i + j] - sum[j]]++;
      }
    }
  }
  return;
}

int main(void) {
  int N, M;
  while (cin >> N >> M, N > 0) {
    map<long, int> h_map;
    map<long, int> w_map;
    vector<long> h_sum;
    vector<long> w_sum;
    long result = 0;
    // hの累積和配列を作成
    h_sum.push_back(0);
    rep(i, N) {
      int h;
      cin >> h;
      h_sum.push_back(h_sum.back() + h);
    }
    // h_mapの構成
    make_map(h_sum, h_map);
    // wの累積和配列を作成
    w_sum.push_back(0);
    rep(i, M) {
      int w;
      cin >> w;
      w_sum.push_back(w_sum.back() + w);
    }
    // w_mapの構成
    make_map(w_sum, w_map);

    // h_mapのイテレータを回して，同じキー値をもつw_mapの要素数だけresultを加算
    for (auto itr = h_map.begin(); itr != h_map.end(); itr++) {
      result += (*itr).second * w_map[(*itr).first];
    }

    // 出力
    cout << result << endl;
  }
  return 0;
}