Group Anagrams

MediumStrings
Next
StringHashingSorting

Group together the words that are anagrams of each other. Inside each group list the words in alphabetical order, and list the groups in alphabetical order of their first word.

Input

Line 1: n, the number of words. Line 2: n lowercase words separated by spaces.

Output

One line per group, with the words in that group separated by spaces.

Constraints

1 <= n <= 10^4 1 <= length of each word <= 100

Example 1
Input
6
eat tea tan ate nat bat
Output
ate eat tea
bat
nat tan

Three groups: ate/eat/tea, bat, and nat/tan.

Hints

Group Anagrams - Medium Strings Problem | Skill Shiksha