#C13241. Find Anagrams

    ID: 42758 Type: Default 1000ms 256MiB

Find Anagrams

Find Anagrams

Given a list of words, your task is to identify and output all words that have at least one anagram within the list. Two words are anagrams if one can be formed by rearranging all letters of the other using each letter exactly once. In this problem, you should ignore case and any non-alphabetic characters.

Note: If no word in the list has an anagram, output nothing.

For example, the words "listen", "silent", and "enlist" are anagrams of each other.

Constraints: \(1 \leq N \leq 10^5\), where \(N\) is the number of words.

inputFormat

The input is read from standard input and is formatted as follows:

  • The first line contains an integer \(N\) representing the number of words.
  • The following \(N\) lines each contain a word.

Words may include non-alphabetical characters. The processing should ignore case and non-alphabetic characters when determining anagrams.

outputFormat

Output to standard output all words (each on a new line) that have at least one anagram in the input list. The order of words in the output should be the same as the order in which they appear in the input, if they belong to an anagram group. If no anagrams exist, output nothing.

## sample
9
listen
silent
enlist
google
gooegl
rat
tar
art
tar!
listen

silent enlist google gooegl rat tar art tar!

</p>