{"problem":{"name":"042. Number Code (Harder Version)","description":{"content":"Note: this is a harder version of a previous problem in the contest. You are using a code where letters in words map to digits in the following way: 0 = o 1 = i 3 = e 4 = a 5 = s 7 = t (the ot","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10269042"},"statements":[{"statement_type":"Markdown","content":"Note: this is a harder version of a previous problem in the contest.\n\nYou are using a code where letters in words map to digits in the following way:\n\n0 = o\n\n1 = i\n\n3 = e\n\n4 = a\n\n5 = s\n\n7 = t\n\n(the other digits will not be used in this problem)\n\nYou've found a sequence of numbers, and you want to find how many words the numbers correspond to using the code described above.\n\nAdditionally, for this problem, assume that any letters in the original word that did not map to a letter in the code were simply encoded as blanks. Thus, a number sequence can potentially map to multiple words. Thus, you are given a dictionary of words, and you are tasked with figuring out which words in the dictionary map to the given number sequence.\n\nThe first line of input contains a positive integer _D_: the number of words in the dictionary. The next _D_ lines each contain a single word: each dictionary entry. The words will be sorted alphabetically. The next line of input contains a positive integer _T_ indicating the number of test cases that follow. The next _T_ lines each contain a single number sequence (not separated by spaces).\n\nFor each test case, first print a positive integer _K_: the number of single words in the dictionary that map to the number sequence using the code described above. Then, print _K_ lines: each word, printing the words in alphabetical order (remember that the given dictionary already is in alphabetical order).\n\n## Input\n\nThe first line of input contains a positive integer _D_: the number of words in the dictionary. The next _D_ lines each contain a single word: each dictionary entry. The words will be sorted alphabetically. The next line of input contains a positive integer _T_ indicating the number of test cases that follow. The next _T_ lines each contain a single number sequence (not separated by spaces).\n\n## Output\n\nFor each test case, first print a positive integer _K_: the number of single words in the dictionary that map to the number sequence using the code described above. Then, print _K_ lines: each word, printing the words in alphabetical order (remember that the given dictionary already is in alphabetical order).\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ \\mathcal{D} = \\{w_1, w_2, \\dots, w_D\\} $ be a dictionary of $ D $ words, sorted alphabetically.  \nLet $ \\phi: \\{0,1,3,4,5,7\\} \\to \\{\\text{o}, \\text{i}, \\text{e}, \\text{a}, \\text{s}, \\text{t}\\} $ be the mapping:  \n$$\n\\phi(0) = \\text{o},\\ \\phi(1) = \\text{i},\\ \\phi(3) = \\text{e},\\ \\phi(4) = \\text{a},\\ \\phi(5) = \\text{s},\\ \\phi(7) = \\text{t}\n$$  \nLet $ \\psi: \\text{Words} \\to \\text{DigitSequences} $ be the encoding function such that for a word $ w $, $ \\psi(w) $ is the sequence of digits obtained by replacing each character $ c \\in w $ with:  \n- $ \\phi^{-1}(c) $ if $ c \\in \\{\\text{o}, \\text{i}, \\text{e}, \\text{a}, \\text{s}, \\text{t}\\} $,  \n- $ \\text{blank} $ (i.e., removed) otherwise.  \n\nLet $ \\mathcal{S} = \\{s_1, s_2, \\dots, s_T\\} $ be a sequence of $ T $ test cases, where each $ s_j $ is a string of digits from $ \\{0,1,3,4,5,7\\} $.\n\n**Constraints**  \n1. $ 1 \\le D \\le 10^5 $  \n2. Each word in $ \\mathcal{D} $ consists of lowercase English letters, length $ \\le 20 $  \n3. $ 1 \\le T \\le 1000 $  \n4. Each $ s_j $ has length $ \\le 20 $, and contains only digits from $ \\{0,1,3,4,5,7\\} $\n\n**Objective**  \nFor each test case $ s_j $, compute:  \n$$\nK_j = \\left| \\left\\{ w \\in \\mathcal{D} \\mid \\psi(w) = s_j \\right\\} \\right|\n$$  \nOutput $ K_j $, followed by the $ K_j $ words in $ \\mathcal{D} $ satisfying $ \\psi(w) = s_j $, in alphabetical order.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10269042","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}