Minimum Ternary String (CodeForces - 1009B)

You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').

You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).

For example, for string "010210" we can perform the following moves:

  • "010210" →→ "100210";
  • "010210" →→ "001210";
  • "010210" →→ "010120";
  • "010210" →→ "010201".

Note than you cannot swap "02" →→ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.

You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).

String aa is lexicographically less than string bb (if strings aa and bb have the same length) if there exists some position ii (1≤i≤|a|1≤i≤|a|, where |s||s| is the length of the string ss) such that for every j

Input

The first line of the input contains the string ss consisting only of characters '0', '1' and '2', its length is between 11 and 105105 (inclusive).

Output

Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).

Examples

Input

100210

Output

001120

Input

11222121

Output

11112222

Input

20

Output

20

题解:观察交换规则我们发现,01可以交换,12可以交换,那么1字符作为一个承上启下的字符,他可以在整个字符串中任意滑动,因此字符串中的所有的1必须都连续的摆放在第一个2的前面,而第一个2前面的0毫无疑问连续的放在最前面,而第一个2后面的0,因为被2挡住,无论如何都不可能越过前面的2,故从第一个2开始后面的0和2相对顺序不变,因此我们只需要统计出第一个2前面的0有多少个,所有1有多少个,第一个2的位置,输出时,先输出第一个2前面的所有0,再输出所有1,然后从第一个2的位置开始往后遍历只输出0和2.

代码如下:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a>a;
    int flag=0;
    int pos;
    ll num1=0;
    ll num0=0;
    int l=strlen(a);
    for(int i=0;i

 

你可能感兴趣的:(思维)