#C6108. Highest Number Rearrangement

    ID: 49832 Type: Default 1000ms 256MiB

Highest Number Rearrangement

Highest Number Rearrangement

Your task is to write a program that takes a single string consisting of digits as input and returns the highest possible number that can be formed by rearranging these digits. If the string is empty or contains any non-digit characters, the program should output 0.

In other words, given an input string \( s \), if \( s \) is not empty and \( s \in \{0-9\}^* \), output the number represented by rearranging the characters of \( s \) in descending order. Otherwise, output 0.

Examples:

  • Input: 4231 produces Output: 4321
  • Input: 102 produces Output: 210
  • Input: (empty string) produces Output: 0
  • Input: 12a5 produces Output: 0

inputFormat

The input is provided via the standard input (stdin) and consists of a single line string. This string will represent the digits. Note that the string may be empty or contain non-digit characters.

outputFormat

The program should output the highest possible number obtained by rearranging the digits to standard output (stdout). If the input string is empty or contains any non-digit characters, print 0.

## sample
4231
4321