import java.io.*; import java.util.*; public class SquareRoute2 { 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 cx = new HashMap(); Map cy = new HashMap(); for(int i = 0; i < y.length; i++) { for(int j = i + 1; j < y.length; j++) { int key = y[j] - y[i]; int cur = cy.containsKey(key) ? cy.get(key) : 0; cy.put(key, cur + 1); } } for(int i = 0; i < x.length; i++) { for(int j = i + 1; j < x.length; j++) { int key = x[j] - x[i]; int cur = cx.containsKey(key) ? cx.get(key) : 0; cx.put(key, cur + 1); } } int ans = 0; for(int key : cy.keySet()) { ans += cy.get(key) * (cx.containsKey(key) ? cx.get(key) : 0); } System.out.println(ans); } } }