#include <stdio.h>

#define N 1500

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int px[ N + 1 ], py[ N + 1 ];
    int x1, x2, y1, y2;
    int res = 0;
    int n, m;

    scanf ( "%d%d", &n, &m );
    if ( !( n | m ) ) break ;

    px[ 0 ] = 0; py[ 0 ] = 0;
    for ( i = 1; i <= n; ++i )
    {
      scanf ( "%d", px + i );
      px[ i ] += px[ i - 1 ];
    }
    for ( i = 1; i <= m; ++i )
    {
      scanf ( "%d", py + i );
      py[ i ] += py[ i - 1 ];
    }

    for ( x1 = 0;       x1 <= n; ++x1 )
    for ( x2 = x1 + 1;  x2 <= n; ++x2 )
    {
      const int dx = px[ x2 ] - px[ x1 ];

      for ( y1 = 0;       y1 <= m; ++y1 )
      {
        for ( y2 = y1 + 1;  y2 <= m; ++y2 )
        {
          const int dy = py[ y2 ] - py[ y1 ];

          if ( dy >= dx )
          {
            res += !!( dx == dy );
            break ;
          }
        }
      }
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}