#C8175. Sort Book Titles

    ID: 52128 Type: Default 1000ms 256MiB

Sort Book Titles

Sort Book Titles

You are given a list of book titles. Your task is to sort these titles primarily by their length and, if two titles have the same length, by lexicographical order.

Formally, for each title s, define its length as \( \mathrm{len}(s) \). You need to sort the list such that for any two titles \( s_1 \) and \( s_2 \), \( s_1 \) comes before \( s_2 \) if either:

  • \( \mathrm{len}(s_1) < \mathrm{len}(s_2) \), or
  • \( \mathrm{len}(s_1) = \mathrm{len}(s_2) \) and \( s_1 < s_2 \) in lexicographical order.

Implement the solution to process input from standard input (stdin) and output the sorted list to standard output (stdout).

inputFormat

The first line contains an integer \( n \) which indicates the number of book titles. The following \( n \) lines each contain a single book title. Titles may contain spaces.

outputFormat

Output \( n \) lines containing the sorted book titles. Each title should be printed on a separate line.

## sample
4
The Great Gatsby
To Kill a Mockingbird
1984
A Tale of Two Cities
1984

The Great Gatsby A Tale of Two Cities To Kill a Mockingbird

</p>