import java.io.*; import java.util.*; public class SquareRoute1 { private static final Scanner cin = new Scanner(System.in); public static void main(String[] args) { while(true) { int n = cin.nextInt(); int m = cin.nextInt(); if(n == 0 && m == 0) { break; } int[] y = new int[n+1]; int[] x = new int[m+1]; for(int i = 1; i <= n; i++) { y[i] = y[i-1] + cin.nextInt(); } for(int i = 1; i <= m; i++) { x[i] = x[i-1] + cin.nextInt(); } Map cnt = new HashMap(); for(int i = 0; i < y.length; i++) { for(int j = 0; j < x.length; j++) { int key = x[i] + y[j]; int cur = cnt.containsKey(key) ? cnt.get(key) : 0; cnt.put(key, cur + 1); } } int ans = 0; for(int key : cnt.keySet()) { ans += cnt.get(key) * (cnt.get(key) - 1) / 2; } System.out.println(ans); } } }