Censorship

No attempts yetTime limit1sMemory limit128 MB

Problem

As part of a new curriculum reform, the CS department has decided to censor its course texts. In this problem you must help the department by writing a program that eliminates from an input text every occurrence of the words in a filter set.

Formally, a word ww can be removed from a string ss whenever ww is a substring of ss (the characters of ww appear consecutively in ss). Given a text string ss and a set TT of filter words, return the length of the shortest string that can result from iteratively removing words of TT from ss. Each word in TT may be removed any number of times, and removing one word can make new occurrences appear.

Input

The input contains multiple test cases. Each test case begins with an integer nn (1n501 \le n \le 50), the size of the filter set TT, followed by the text string ss, followed by the nn filter words t1,,tnt_1, \dots, t_n. The text string and every filter word consist only of the lowercase letters 'a' through 'z' and have length between 11 and 5050. All filter words within a test case are distinct. Input is terminated by a line containing a single 00, which must not be processed.

Output

For each test case, print a single integer: the minimum possible length of the resulting string.

Hint

[…] marks the word removed at each step, and denotes the empty string.

  • c[cde]defcde[cde]fcdef[cde]f
  • [aa]baab[ba]ab[ab]
  • [aa]baabb[aa]b[bb]