PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000075. Giảm giá trị số nguyên (Minimize The Integer)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Giảm giá trị số nguyên (Minimize The Integer)

Minimize The Integer

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a string of digits, swap adjacent digits only if their parities differ. Find the lexicographically smallest reachable string, preserving length (leading zeros may appear).

Input

A single digit string ss, no case count TT.

Output

Print the lexicographically smallest reachable digit string.

Subtasks

  • Subtask 1 (20 points): Exactly one dataset; 1≤∣s∣≤151\le |s|\le15; all characters are digits, leading zeros are allowed.
  • Subtask 2 (30 points): Exactly one dataset; 1≤∣s∣≤30001\le |s|\le3000; all characters are digits, leading zeros are allowed.
  • Subtask 3 (50 points): Exactly one dataset; 1≤∣s∣≤3000001\le |s|\le300000; all characters are digits, leading zeros are allowed.

Example

Input

13542

Output

13425

Explanation

Preserve the relative order of even digits and of odd digits and merge their two sequences greedily.