ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила

1158. Censored!

Ограничение времени: 2.0 секунды
Ограничение памяти: 64 МБ
The alphabet of Freeland consists of exactly N letters. Each sentence of Freeland language (also known as Freish) consists of exactly M letters without word breaks. So, there exist exactly NM different Freish sentences.
But after recent election of Mr. Grass Jr. as Freeland president some words offending him were declared unprintable and all sentences containing at least one of them were forbidden. The sentence S contains a word W if W is a substring of S i.e. exists such k >= 1 that S[k] = W[1], S[k+1] = W[2], ... , S[k+len(W)-1] = W[len(W)], where k+len(W)-1 <= M and len(W) denotes length of W. Everyone who uses a forbidden sentence is to be put to jail for 10 years.
Find out how many different sentences can be used now by freelanders without risk to be put to jail for using it.

Исходные данные

The first line contains three integer numbers: N - the number of letters in Freish alphabet, M - the length of all Freish sentences and P - the number of forbidden words (1 ≤ N ≤ 50, 1 ≤ M ≤ 50, 0 ≤ P ≤ 10).
The second line contains exactly N different characters - the letters of the Freish alphabet (all with ASCII code greater than 32).
The following P lines contain forbidden words, each not longer than min(M, 10) characters, all containing only letters of Freish alphabet.

Результат

Output the only integer number - the number of different sentences freelanders can safely use.

Пример

исходные данныерезультат
3 3 3
QWE
QQ
WEE
Q
7

Замечания

Note that tests may contain characters with ASCII codes more than 127.
Автор задачи: Nick Durov
Источник задачи: ACM ICPC 2001. Northeastern European Region, Northern Subregion