#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp::Ordering;
use std::cmp;
use std::cmp::min;
use std::collections::BTreeMap;
use std::process;
use std::cmp::Ord;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BTreeSet;
use std::mem;
use std::collections::BinaryHeap;
/// Equivalent to std::lowerbound and std::upperbound in c++
pub struct Scanner<R> {
    stdin: R,
}
 
impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main(){
    let sssss = std::io::stdin();
    let mut sc = Scanner { stdin: sssss.lock() };
    while(true){
    let mut N:usize = sc.read();
    let mut M:usize = sc.read();
    if N == 0 && M == 0{
        break;
    }
    let mut h = vec![];
    let mut w = vec![];
    for i in 0..N{
        let mut t:usize = sc.read();
        h.push(t);
    }
    for i in 0..M{
        let mut t:usize = sc.read();
        w.push(t);
    }

    let mut sum = vec![0;M+1];
    for i in 0..M{
        sum[i+1]+=w[i];
        sum[i+1]+=sum[i];
    }
    let mut ha = HashMap::new();
    for i in 0..M+1{
        for j in i+1..M+1{
            *ha.entry(sum[j]-sum[i]).or_insert(0usize)+=1;
        }
    }



    let mut sum2 = vec![0;N+1];
    for i in 0..N{
        sum2[i+1]+=h[i];
        sum2[i+1]+=sum2[i];
    }
    let mut ha2 = HashMap::new();
    for i in 0..N+1{
        for j in i+1..N+1{
            *ha2.entry(sum2[j]-sum2[i]).or_insert(0)+=1;
        }
    }
    let mut res = 0;
    for (x,y) in &ha{
        let i = *x;
        let j = *y;
        if ha2.contains_key(&i){
            res+=j*ha2[&i];
        }
    }
    println!("{}", res);
    }
}

pub static MOD:i64 = 1000000007;
pub static MODu:usize = 1000000007;
pub static eps:f64 = 1e-6;
const INF: i64 = 1 << 60;






Measured memory_bytes: 31992