#C12821. Unique Characters Sorted by Frequency

    ID: 42291 Type: Default 1000ms 256MiB

Unique Characters Sorted by Frequency

Unique Characters Sorted by Frequency

Given a string \(S\), your task is to output all the unique characters from \(S\) in a specific sorted order. The characters should be primarily sorted by the frequency of their occurrence in descending order. In case two characters have the same frequency, they must be ordered by their first occurrence in the string.

For example:

  • If \(S = "abab"\), the answer is a b because 'a' comes first and both 'a' and 'b' occur twice.
  • If \(S = "baba"\), the answer is b a because 'b' appears before 'a'.

If the string is empty, output an empty line.

inputFormat

A single string (S) is provided via standard input. It may contain letters, digits, and special characters. The string can also be empty.

outputFormat

Output the unique characters in (S) sorted by their frequency (in descending order). If two characters have the same frequency, order them by their first occurrence in the string. The characters should be printed on one line separated by a single space. If the string is empty, print an empty line.## sample

a
a