#K65742. Find Anagrams

    ID: 32265 Type: Default 1000ms 256MiB

Find Anagrams

Find Anagrams

Given a target word and a list of candidate words, your task is to find all the candidates that are anagrams of the target word. An anagram is a word formed by rearranging the letters of another word, using all the original letters exactly once.

For example, for the word \(listen\) and the candidate list [\(enlist\), \(google\), \(inlets\), \(banana\)], the anagrams are \(enlist\) and \(inlets\).

Your program should read input from stdin and output the anagrams (if any) to stdout in the same order they appear in the input. If there are no anagrams, output an empty line.

inputFormat

The input consists of three parts:

  1. The first line contains a single word, the target word.
  2. The second line contains an integer \(n\), the number of candidate words.
  3. The third line contains \(n\) space-separated words representing the candidate words.

outputFormat

Output a single line containing the candidate words that are anagrams of the target word, separated by a space, in the same order as they appear in the input. If no candidate word is an anagram of the target word, output an empty line.

## sample
listen
4
enlist google inlets banana
enlist inlets

</p>