Given N words \(a_i\) of lowercase letters. Arrange these words such that word \(a_i\) of length \(l_i\) comes before word \(a_j\) of length \(l_j\) if
1) \(l_i < l_j\).
OR
2) \(l_i = l_j\) and the first different letter in \(a_i\) < corresponding letter in \(a_j\). Letters are compared with respect to their ASCII Value.
For example: \(a_i\) = "arm", \(a_j\) = "ant", so "ant" comes before "arm" because second letter in \(a_j\) n < second letter in \(a_i\) r.
Input:
In the first line: Given an integer N.
In the second line: N strings \(a_i\) follow.
Output:
Print the words in the order illustrated in the question.
Constraints:
\(1 \le N \le 100\).
\(1 \le l_i \le 10\).
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor