HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Kovrov IT 2010 > problem:


J. String manipulations

Volume problems

• B. Primes
• C. Bishops
• D. Unusual Lottery
• E. Polygons
• F. Liars and Knights
• G. Sequence
• H. Coins
• I. Galls village
• J. String manipulations

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 3000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Автор: Кирилл Бутин, ПГУ.

You are given a string S, consisting of lowercase Latin letters. The length of string is L. There are N small strings. You should concatenate all of them in any order to get string T. Your task is to count the number of different strings T, which are subsequences of string S.

Input
The first line contains L lowercase Latin letters (1 ≤ L ≤ 10000). The second line contains integer N (1 ≤ N ≤ 9) - the number of small strings, which should be concatenated. The following N lines contain sequences of lowercase Latin letters. The total length of small strings does not exceed 1000 symbols.

Output
Output a single number - the answer for the problem.

Input 1 Output 1
abracadabra
2
aaa
a
1
Input 2 Output 2
abracadabra
2
ara
bra
2

Для отправки решений необходимо выполнить вход.

www.contester.ru