#C12417. Group Strings by Their Lengths

    ID: 41842 Type: Default 1000ms 256MiB

Group Strings by Their Lengths

Group Strings by Their Lengths

Given a list of strings, your task is to group them by their lengths. For each string s, its length is given by \(|s|\). You should preserve the input order for the strings within the same group and then output each group in ascending order of their lengths.

Task: Read an integer \(n\) representing the number of strings, followed by \(n\) strings (one per line). Group the strings by their length and print each group in a separate line. Each line should contain the length followed by a colon and the strings (separated by a single space) that have that length.

Example:

Input:
4
apple
dog
banana
cat

Output: 3: dog cat 5: apple 6: banana

</p>

inputFormat

The first line contains an integer (n) ((0 \leq n \leq 10^5)) indicating the number of strings. The following (n) lines each contain a non-empty string. Each string's length does not exceed 100 characters.

outputFormat

For each distinct string length (including 0 if any empty strings occur), output a single line in the following format:

L: s1 s2 s3 ...

where (L) is the string length and (s1, s2, ...) are the strings of that length in the order they appear in the input. The groups must be printed in ascending order of (L).## sample

4
apple
dog
banana
cat
3: dog cat

5: apple 6: banana

</p>