ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Неотсортированные > задача:


String manipulations

Задачи раздела

• Making Potions
• Santa Gifts
• Chessboard Pattern
• Galls village
• Sequence
• Bishops
• Polygons
• String manipulations
• Lawyers Council
• Math and Soldiers
• Many-coloured roads
• What about judges?
• Liars and Knights
• Interesting permutations
• Kovrov
• Points

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 3000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Автор: Кирилл Бутин, ПГУ.

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