The One-Handed Typist
Jimmy has a job of typing documents for ACM or he rather had a job until his un- fortunate skiing accident. With some of his fingers in a cast, he is finding it dif- ficult to type as he cannot press all the keys of a keyboard and hence his job is in danger.
Jimmy has come to you for help. He
needs to prove to his boss that he can still
type long words (his boss likes long words
because it makes him look smart). Given a list of fingers (fingers are identified by integers) that cannot be used (due to his accident), and a list of words Jimmy can add to his boss’s documents to make him look smart, find all the longest words that Jimmy can type.
Jimmy uses standard fingering, meaning he can type each of these letters with a finger. The list below shows a finger number and the characters it can press.
- qaz
- wsx
- edc
- rfvtgb
- space
- space
- yhnujm
- ik,
- ol.
- p;/
Input
Means finger 1 is used to type q, a, z Others have same meaning
Input consists of a number of descriptions of Jimmy’s handicap. Each description begins with two numbers: F , the number of fingers that Jimmy cannot use, and N ≤ 1000, the number of big words to consider.
Following are F numbers listing the fingers Jimmy cannot use. On a standard (qwerty) keyboard with standard finger positioning, the fingers are numbered 1 through 10 from left to right (that is, left pinky is 1, left ring is 2, ..., left index is 4, left thumb is 5, right thumb is 6, ..., right pinky is 10).
Next are N lines, each containing one word of at most 50 characters. A word consists of small letters only. Input terminates with end of file.
Output
Output for each case consists of a number M indicating the number of longest words found in the list which Jimmy can type. Following are M lines containing the list of longest words Jimmy can type. The words in the list should be distinct and occur in alphabetical order.
2/2 Sample Input
55
6 7 8 9 10 the stewardesses have
funny
hair
3 18
789
wax
waxed
waxen
waxer
waxers
waxes
waxing
waxy
we
wear wearable wearer wearing wears
weave
weaver weaves weaving
Sample Output
1
stewardesses
4
waxers
wearer
weaver
weaves