import java.io.*; import java.util.*; public class SquareRoute3 { 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(); } int ans = 0; for(int j = 0; j < y.length; j++) { for(int i = 0; i < x.length; i++) { int py = j + 1; int px = i + 1; while(px < x.length && py < y.length) { int sx = x[px] - x[i]; int sy = y[py] - y[j]; if(sx == sy) { ans++; } if(sx <= sy) { px ++; } if(sx >= sy) { py ++; } } } } System.out.println(ans); } } }