#K40512. Rearrange String for Maximum Integer

    ID: 26659 Type: Default 1000ms 256MiB

Rearrange String for Maximum Integer

Rearrange String for Maximum Integer

You are given a string s which consists of digits and the characters '+' and '-'. The task is to extract all digits from the string, sort them in descending order, and form the largest possible integer. If the input string contains any '-' sign, the result is considered negative and a '-' is prefixed to the sorted digits. All '+' characters and any other non-digit characters (except '-') are ignored.

This can be mathematically expressed as follows:

[ \text{result} = (-1)^{\mathbf{1}_{{s \text{ contains '-' }}}} \times \text{concatenation}(\text{digits sorted in descending order}) ]

Note that if the input string is empty, the output should also be an empty string.

inputFormat

The input consists of a single line containing the string s which may include digits (0-9), '+' and '-' characters.

outputFormat

Output the rearranged string according to the rules. If the string contains at least one '-' character, the output should begin with '-' followed by the digits in descending order. Otherwise, output only the digits in descending order.## sample

1234
4321