cswork / OAOpen practice workspace

JPMorgan ChaseOA #18

Swap Parity (Data Scientist / Analytics :)

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyStrings

You may only swap two adjacent digits with the same parity, any number of times. Return the largest digit string; all digits, including zeros, must be kept. For the original 0082663 the correct result is 8662003; the original example dropped the zeros.

Input

One line with a digit string of length 1..100000 containing only 0..9; leading zeros are allowed.

Output

Output the largest digit string of the original length; leading zeros must not be removed.

Example 1

Input:

7596801

Output:

9758601

Example 2

Input:

0082663

Output:

8662003

Example 3

Input:

0214

Output:

2014

Example notes

The outputs of the three public examples are, in order: 9758601; 8662003; 2014. These answers have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…