#C3191. Lexicographical Bounds

    ID: 46591 Type: Default 1000ms 256MiB

Lexicographical Bounds

Lexicographical Bounds

Given a string s composed of lowercase English letters, determine the lexicographically smallest and largest strings that can be formed by arbitrarily swapping any two characters. Since any number of swaps is allowed, the smallest string is simply the string sorted in ascending order, and the largest is the string sorted in descending order.

Formally, if \(s\) is the given string, you are required to compute:

  • \(smallest = \min(s) = \text{sort}_{asc}(s)\)
  • \(largest = \max(s) = \text{sort}_{desc}(s)\)

For example, if s is "bcda", then the smallest string is "abcd" and the largest is "dcba".

inputFormat

The input consists of a single line containing the string s, where s is composed of lowercase English letters.

Input Format:

s

outputFormat

Output two lines:

  • The first line contains the lexicographically smallest string obtainable by rearranging s.
  • The second line contains the lexicographically largest string obtainable by rearranging s.

Output Format:

smallest_string
largest_string
## sample
bcda
abcd

dcba

</p>