#C14383. Find All Anagrams

    ID: 44026 Type: Default 1000ms 256MiB

Find All Anagrams

Find All Anagrams

Given a target string and a dictionary of words, your task is to find all words that are anagrams of the target string. Two words are anagrams if they contain exactly the same characters with the same frequencies. Formally, for a word w and target string s, they are anagrams if:

$$ \text{Counter}(w) = \text{Counter}(s) $$

The matching should be case-sensitive, and only those words with exactly the same character counts as the target string should be considered.

inputFormat

The input is read from standard input and consists of:

  1. A single line containing the target string.
  2. A single line containing an integer n, the number of words in the dictionary.
  3. n subsequent lines, each containing one word from the dictionary.

outputFormat

Print each anagram found in the dictionary on a separate line in the same order as they appear in the input. If no anagrams are found, print nothing.

## sample
listen
5
listen
silent
enlist
google
facebook
listen

silent enlist

</p>