Sorting strings by length and lexicographically

C# Hard sorting

Task «Sorting strings by length and lexicographically»

Given a string containing words separated by spaces. It is necessary to sort the words first by increasing length, and for equal length — in lexicographic order (descending). Output the sorted words separated by spaces. Constraints: the length of the string does not exceed 10^5 characters, words consist of lowercase Latin letters. The solution must be efficient and use built-in sorting methods.

Input Format

One line containing words of lowercase Latin letters, separated by exactly one space. The length of the line does not exceed 100000 characters.

Output Format

A string containing the same words, sorted by increasing length, and for equal length — in lexicographically descending order. Words are separated by exactly one space.

Examples

Example 1

INPUT
cat dog apple banana
OUTPUT
dog cat apple banana

Example 2

INPUT
a bb ccc dd
OUTPUT
a dd bb ccc

Example 3

INPUT
5 12 34 21 43 15
OUTPUT
5

Example 4

INPUT
{"a":1,"b":{"c":2}} {"a":2,"b":{"d":3}}
OUTPUT
{"a":1,"b":{"c":2}}
main.cs