Canadian Computing Competition: 2004 Stage 1, Senior #1
A collection of words is prefix-free if no word is a prefix of any other word. A collection of words is suffix-free if no word is a suffix of any other word. A collection of words is fix-free if it is both prefix-free and suffix-free.
For this problem, a word is a sequence of lower-case letters of length between and . A word is a prefix of word if consists of the first characters of , in order, for some . That is, the word
cat has prefixes
cat. Similarly, a word is a suffix of if consists of the last characters of , in order, for some .
Your input will be lines: the first line will be the number , and the remaining lines will be the collections of words each. (That is, lines , , and compose the first collection, lines , , and compose the second collection, and so on). Your output will be lines, each line containing either
Yes (if that collection of words is fix-free) or
No (if that collection is not fix-free).
2 abba aab bab a ab aa