SDE Path

Sort Characters by Frequency

Medium

Sort Characters by Frequency

Given a string, sort its characters in decreasing order of frequency.

Input format

A single line containing a lowercase string.

Output format

Print the string with characters sorted by decreasing frequency; characters with equal frequency are ordered alphabetically.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
tree
Expected output
eert
Example 2
Input
cccaaa
Expected output
aaaccc