Sanghak Language

No attempts yetTime limit1sMemory limit128 MB

Problem

Long ago there were two languages, Namgyu and Jaehyeok. At some point a language halfway between them, called Sanghak, came into being.

A Sanghak word is built as follows.

  1. Pick one Namgyu word and choose one of its prefixes of length at least $1$ (a piece cut from the front).
  2. Pick one Jaehyeok word and choose one of its suffixes of length at least $1$ (a piece cut from the back).
  3. Concatenate the suffix right after the prefix. The order is always the Namgyu prefix followed by the Jaehyeok suffix.

For example, from the Namgyu word abc and the Jaehyeok word de you can make ae, ade, abe, abde, abce, and abcde, but you cannot make bce, ace, or abc.

It does not matter whether the resulting word actually means anything. Given a Namgyu dictionary and a Jaehyeok dictionary, determine how many distinct Sanghak words can be formed. For instance, with Namgyu words ab, abc and Jaehyeok words cd, d, the word abcd can be formed in two different ways, but since it is the same word it is counted only once.

Input

The input consists of several test cases and ends with a line 0 0.

The first line of each test case contains the number of Namgyu words $P$ and the number of Jaehyeok words $S$. ($1 \le P, S \le 1000$)

The next $P$ lines each contain one Namgyu word, and the following $S$ lines each contain one Jaehyeok word. Every word consists of between $1$ and $1000$ lowercase English letters. No word appears twice within the same language, and the total length of all words in one language is at most $10^5$.

Output

For each test case, print on its own line the number of distinct Sanghak words that can be formed.