#include <stdio.h>
#include <stdlib.h>
int count(int N, int M){
    int i, j, k;
    int h[1500];
    int w[1500];
    int s_cnt = 0;
    int *h_cnt;
    int *w_cnt;
    for(i = 0; i < N; i++) scanf("%d", &h[i]);
    for(i = 0; i < M; i++) scanf("%d", &w[i]);
    h_cnt = (int *)calloc(1000 * N, sizeof(int));
    w_cnt = (int *)calloc(1000 * M, sizeof(int));
    //????????????
    for(i = 0; i < N; i++){
        int size = 0;
        for(j = i; j < N; j++){
            size += h[j];
            (*(h_cnt+size))++;
        }
    }
    //?¨?
    for(i = 0; i < M; i++){
        int size = 0;
        for(j = i; j < M; j++){
            size += w[j];
            (*(w_cnt+size))++;
        }
    }
    int min = (N > M) ? M : N;
    for(i = 0; i < min * 1000; i++){
        s_cnt += ((*(h_cnt + i)) * (*(w_cnt + i)));
    }
    printf("%d\n", s_cnt);
    free(h_cnt);
    free(w_cnt);
}

int main(){
    int N, M;
    while(scanf("%d %d", &N, &M) != EOF) count(N, M);
    return 0;
}