#K83807. Group Anagrams

    ID: 36279 Type: Default 1000ms 256MiB

Group Anagrams

Group Anagrams

You are given a list of strings, and your task is to group the anagrams together.

An anagram is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once.

Note: For this problem, you will read the input from stdin and output the result to stdout in a specific format. The output should consist of several lines where each line contains one group of anagrams. Within each group, the words should be sorted in lexicographical order, and the groups should be sorted in ascending order by their first word.

Example:

Input:
6
eat
tea
tan
ate
nat
bat

Output: ate eat tea bat nat tan

</p>

inputFormat

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

  • The first line contains an integer n, denoting the number of strings.
  • The following n lines each contain a string.

outputFormat

The output should be printed to the standard output (stdout). Each line of the output corresponds to one group of anagrams. In each line, the anagrams are printed in lexicographical order separated by a single space. The groups themselves are sorted in ascending order based on the first word of each group.

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

bat nat tan

</p>