#C313. Custom Word Sort

    ID: 46523 Type: Default 1000ms 256MiB

Custom Word Sort

Custom Word Sort

You are given a list of words. Your task is to sort the list primarily by the word's length (i.e. the number of characters) and, for words with the same length, sort them lexicographically (alphabetical order).

The sorting criterion can be mathematically represented as follows: For two words \(a\) and \(b\), word \(a\) comes before word \(b\) if:

\(\text{len}(a) < \text{len}(b)\) or \(\text{len}(a) = \text{len}(b)\) and \(a < b\).

Your program should read the input from standard input and print the result to standard output.

inputFormat

The first line contains a single integer \(N\) denoting the number of words. The second line contains \(N\) space-separated words.

outputFormat

Output a single line containing the sorted list of words separated by a single space. The words should be sorted primarily on their length and secondarily in alphabetical order.

## sample
6
apple bat banana pear dog cat
bat cat dog pear apple banana