//#include #include #include #include #include #include using namespace std; //ifstream cin("tema.in"); //ofstream cout("tema.out"); const int SIGMA = 26; const int MAXN = 100000; struct Trie { int words; Trie *son[2]; Trie() { words = 0; son[0] = son[1] = NULL; } }; Trie *root; char code[SIGMA][4]; char word[1 + MAXN], s[1 + 4 * MAXN]; int k = 0, answer = -1; void Insert() { Trie *node = root; for (int i = 1; i <= k; i++) { if (node->son[s[i] - 'a'] == NULL) node->son[s[i] - 'a'] = new Trie(); node = node->son[s[i] - 'a']; } if (node->words != 0) answer = max(answer, node->words + 1); node->words++; } int main() { root = new Trie(); for (int i = 0; i < SIGMA; i++) { char ch; cin >> ch; cin >> code[ch - 'a']; } int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> word + 1; int l = strlen(word + 1); k = 0; for (int j = 1; j <= l; j++) { int p = 0; while (p < 4 && (code[word[j] - 'a'][p] == '.' || code[word[j] - 'a'][p] == '-')) { k++; if (code[word[j] - 'a'][p] == '.') s[k] = 'a'; else s[k] = 'b'; p++; } } Insert(); } cout << answer << "\n"; return 0; }