#include <stdio.h>

int main() {
  int N, M, i, hs, he, ws, we, temp;
  while (scanf("%d%d", &N, &M), (N != 0) || (M != 0) ) {
    int h[1500] = {0}, w[1000] = {0}, squares = 0;
    int hight[1500001] = {0}, width[1500001] = {0};
    for (i = 0; i < N; i++) scanf("%d", &h[i]);
    for (i = 0; i < M; i++) scanf("%d", &w[i]);
    for (hs = 0; hs < N; hs++) {
      for (he = hs; he < N; he++) {
	for (i = hs, temp = 0; i <= he; i++) {
	  temp += h[i];
	}
	hight[temp]++;
      }
    }
    for (ws = 0; ws < M; ws++) {
      for (we = ws; we < M; we++) {
	for (i = ws, temp = 0; i <= we; i++) {
	  temp += w[i];
	}
	width[temp]++;
      }
    }
    for (i = 1; i < 1500001; i++) {
      squares += hight[i] * width[i];
    }
#ifdef debug
    for (i = 0; i < 21; i++)
      printf("hight[%d]:%d\n", i, hight[i]);
    for (i = 0; i < 21; i++)
      printf("width[%d]:%d\n", i, width[i]);
#endif
    printf("%d\n", squares);
  }
  return 0;
}