Sorting by string length in a vector

C++ Easy vectors

Task «Sorting by string length in a vector»

Write a program that reads the number of lines, then the lines themselves, stores them in a std::vector<std::string>, sorts them by ascending line length (preserving the original order for lines of equal length), and outputs the sorted lines. Use std::stable_sort.

Input Format

The first line contains an integer N (1 ≤ N ≤ 100) — the number of lines. Then follow N lines, each no longer than 100 characters, containing only Latin letters and spaces.

Output Format

Output N lines in ascending order of length.

Examples

Example 1

INPUT
3 cat dog apple
OUTPUT
cat dog apple

Example 2

INPUT
5 hello hi greetings bye world
OUTPUT
hi bye hello world greetings

Example 3

INPUT
4 hello hi bye to
OUTPUT
hi to bye hello

Example 4

INPUT
4 longword ab medium a
OUTPUT
a ab medium longword
main.cpp