#C5492. Scrambled Words Finder

    ID: 49147 Type: Default 1000ms 256MiB

Scrambled Words Finder

Scrambled Words Finder

You are given a list of words and a target word. Your task is to find all words in the list that are a scrambled version of the target word. A scrambled word, or anagram, is one that has exactly the same characters (including duplicates) as the target word, but possibly in a different order. Formally, if we denote the sorted sequence of characters of a word w as \(\text{sort}(w)\), then a word v is a valid scramble of the target word t if and only if \(\text{sort}(v) = \text{sort}(t)\).

You should output the list of valid scrambled words in lexicographical order. If there is no valid scrambled word, output a single line with the message: "No valid scrambled words found".

inputFormat

The input is given from standard input (stdin) and has the following format:

  1. The first line contains an integer \(N\) representing the number of words in the list.
  2. The second line contains \(N\) space-separated words. (If \(N = 0\), this line will be empty.)
  3. The third line contains a single word, the target word.

outputFormat

Output a single line to standard output (stdout) containing the valid scrambled words sorted in lexicographical order and separated by a single space. If no valid scrambled words exist, output "No valid scrambled words found".

## sample
6
tea eat tan ate nat bat
eat
ate eat tea