#C1156. Exclusive Word List Generation

    ID: 40889 Type: Default 1000ms 256MiB

Exclusive Word List Generation

Exclusive Word List Generation

You are given a dictionary of words, a series of previously used word lists, and a starting letter. Your task is to generate a new list containing unique words from the dictionary that:

  • Start with the given letter, and
  • Do not appear in any of the previous word lists.

The resulting list should be sorted in lexicographical order. If no valid word exists, output "No words available".

Details:

Let \(n\) be the number of dictionary words. The dictionary words are given as a list, and you are also given \(m\) pre-existing lists. Each pre-existing list may contain one or more words that have already been used. Your goal is to find all dictionary words that start with the specified letter and are not present in any pre-existing list, then sort them alphabetically.

If there are no such words, simply output "No words available".

inputFormat

The input is given via standard input (stdin) in the following format:

  1. An integer \(n\) representing the number of dictionary words.
  2. A line with \(n\) space-separated words.
  3. An integer \(m\) representing the number of previous word lists.
  4. For each of the next \(m\) lines: an integer \(k\) (the number of words in that list) followed by \(k\) space-separated words.
  5. A single line containing a single character representing the starting letter.

All words consist of lowercase English letters.

outputFormat

Output to standard output (stdout) a single line. If there is at least one valid word, print the sorted valid words separated by a space. Otherwise, print "No words available".

## sample
7
apple apricot banana berry cherry chocolate cucumber
2
3 apple apricot berry
2 banana cherry
a
No words available