eolymp
bolt
Try our new interface for solving problems
Məsələlər

Diccionário Portuñol

Diccionário Portuñol

Portuñol is a special language that was naturally developed in Latin America. Since almost half of Latin America speaks Portuguese (Português) and almost half speaks Spanish (Español), the mixing of both languages is natural. Each word in Portuñnol is made by taking a non-empty pre x of a Portuguese word and a nonempty sux of a Spanish word, and concatenating them together. A pre x of a word is any word that can be obtained by erasing zero or more characters from its right end. A sux of a word is any word that can be obtained by erasing zero or more characters from its left end. The name of the language itself comes from taking a pre x of the word "Português" (Portu) and a suffix of the word "Español" (ñol), and concatenating them. Of course, not every possible way of combining two words will result in something meaningful, or even pronounceable, but that is not important. We want you to write a program to count the number of dierent Portuñol words. You will be given two non-empty sets of words to test your program. The rst set will represent Portuguese words and the second set will represent Spanish words. You need to calculate the number of dierent Portuñol words that can be made using the pre x and sux rule described above. Note that the same word may be constructed in several ways, but it still needs to be counted as one. Also note that the input sets are just to test your program, so they do not need to be made out of actual Portuguese or Spanish words. \InputFile Each test case is described using several lines. The first line contains two integers \textbf{P} and \textbf{S} representing respectively the number of Portuguese words and the number of Spanish words (\textbf{1} ≤ \textbf{P}, \textbf{S} ≤ \textbf{1000}). Each of the next \textbf{P} lines contains a Portuguese word, and after that each of the next \textbf{S} lines contains a Spanish word. Each word is a non-empty string of at most \textbf{1000} characters; each character is one of the \textbf{26} standard lowercase letters (from '\textbf{a}' to '\textbf{z}'). You may assume that within each test case no two Portuguese words are the same, and that the sum of the lengths of all the Portuguese words is at most \textbf{10^5}. The same holds for the Spanish words. The last test case is followed by a line containing two zeros. \OutputFile For each test case output a line with an integer representing the number of dierent words that can be constructed by concatenating a non-empty pre x of a word in the first set (Portuguese words) and a non-empty sux of a word in the second set (Spanish words).
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3 3
mais
grande
mundo
mas
grande
mundo
1 5
a
aaaaa
aaaaaa
aaaaaaa
a
aaaaaaaaa
1 1
abc
abc
0 0
Çıxış verilənləri #1
182
9
8
Mənbə ACM ICPC Latin America 2011, November 4th-5th, 2011