using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            cin = new CommonInput();

            int N, M;

            int[] hArray, wArray;

            while (true)
            {
                N = cin.GetNextToInt();
                M = cin.GetNextToInt();

                if (N == 0 && M == 0)
                    break;

                hArray = new int[N];
                wArray = new int[M];

                for (int i = 0; i < N; i++)
                    hArray[i] = cin.GetNextToInt();

                for (int i = 0; i < M; i++)
                    wArray[i] = cin.GetNextToInt();

                Console.WriteLine(Calc(hArray, wArray));
            }
        }

        private int Calc(int[] hArray, int[] wArray)
        {
            Dictionary<int, int> dictH = new Dictionary<int, int>();
            Dictionary<int, int> dictW = new Dictionary<int, int>();
            int tmp;
            int count = 0;

            for (int i = 0; i < hArray.Length; i++)
            {
                tmp = hArray[i];
                for (int j = i + 1; j < hArray.Length; j++)
                {
                    if (dictH.ContainsKey(tmp))
                        dictH[tmp]++;
                    else
                        dictH[tmp] = 1;

                    tmp += hArray[j];
                }

                if (dictH.ContainsKey(tmp))
                    dictH[tmp]++;
                else
                    dictH[tmp] = 1;
            }

            for (int i = 0; i < wArray.Length; i++)
            {
                tmp = wArray[i];
                for (int j = i + 1; j < wArray.Length; j++)
                {
                    if (dictW.ContainsKey(tmp))
                        dictW[tmp]++;
                    else
                        dictW[tmp] = 1;

                    tmp += wArray[j];
                }

                if (dictW.ContainsKey(tmp))
                    dictW[tmp]++;
                else
                    dictW[tmp] = 1;
            }

            foreach (var item in dictH)
            {
                if (dictW.ContainsKey(item.Key))
                    count += dictW[item.Key] * item.Value;
            }

            return count;
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        public string Line { get; set; }
        private string[] _s;
        private int _i;
        private char[] _sep = { ' ' };

        public void GetLine()
        {
            this._i = 0;
            do
            {
                this.Line = Console.ReadLine();
            } while (this.Line == "");

            if (this.Line != null)
                this._s = this.Line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);
        }

        public string GetNext()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            this.GetLine();

            return this._s[this._i++];
        }

        public int GetNextToInt()
        {
            return int.Parse(this.GetNext());
        }

        public long GetNextToLong()
        {
            return long.Parse(this.GetNext());
        }

        public double GetNextToDouble()
        {
            return double.Parse(this.GetNext());
        }
    }
}

Measured memory_bytes: 35424