#K5351. Lexicographically Smallest String

    ID: 29547 Type: Default 1000ms 256MiB

Lexicographically Smallest String

Lexicographically Smallest String

You are given a string \(s\) consisting only of lowercase English letters. You are allowed to perform the following operation any number of times:

  • Select two different indices \(i\) and \(j\) such that \(s[i] \neq s[j]\) and swap \(s[i]\) with \(s[j]\).

Your goal is to determine the lexicographically smallest string that can be obtained by performing any number of these operations.

In other words, you need to output the sorted (in non-decreasing order) version of the string. For example, if \(s = \texttt{dcba}\), then the smallest string possible is \(\texttt{abcd}\).

Examples:

  • Input: dcba → Output: abcd
  • Input: hello → Output: ehllo
  • Input: bubble → Output: bbbelu
  • Input: algorithm → Output: aghilmort

Note: If the string contains all identical characters, the output remains the same.

inputFormat

The input consists of a single line from standard input containing the string (s) (only lowercase English letters).

outputFormat

Output to standard output the lexicographically smallest string obtainable by performing the allowed operations.## sample

dcba
abcd