#C11960. Sort Words by Length

    ID: 41334 Type: Default 1000ms 256MiB

Sort Words by Length

Sort Words by Length

Given a list of words, your task is to sort them according to the following rules:

  • First, by their length in ascending order.
  • If two words have the same length, sort them lexicographically in ascending order.

The input is provided via stdin and the output should be printed to stdout.

Example:

Input:
5
apple
pear
banana
kiwi
peach

Output: kiwi pear apple peach banana

</p>

inputFormat

The first line contains an integer n denoting the number of words. The following n lines each contain a single word.

outputFormat

Output the sorted list of words, with each word on a new line.

## sample
5
apple
pear
banana
kiwi
peach
kiwi

pear apple peach banana

</p>