#K1326. Group Anagrams
Group Anagrams
Group Anagrams
Given a list of strings, group them into groups of anagrams. Two words are anagrams if they consist of the same characters with the same frequencies. Formally, two strings \(a\) and \(b\) are anagrams if \(\text{sort}(a) = \text{sort}(b)\).
Your task is to form groups such that each group contains words which are anagrams of each other. For each group, sort the words in lexicographical order. Finally, output the groups sorted by the first word of each group in lexicographical order.
inputFormat
The first line contains an integer \(n\) representing the number of words. The next line contains \(n\) space-separated words.
outputFormat
Print each anagram group on a separate line. Within each line, print the words sorted in lexicographical order, and the groups themselves should be ordered by the lexicographical order of their first word.
## sample6
eat tea tan ate nat bat
ate eat tea
bat
nat tan
</p>