description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() k1 = 0 for i in s: if i == "1": k1 += 1 k0 = 0 for i in s: if i == "0": k0 += 1 if i == "2": break ans = "0" * k0 + "1" * k1 i = 0 while i < len(s): if s[i] == "2": ans += "2" i += 1 while i < len(s) and s[i] != "2": if s[i] == "0": ans += "0" i += 1 else: i += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING IF VAR VAR STRING VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input("") num = 0 flag = False for numero in s: if numero == "1": num += 1 if "2" not in s or "0" not in s: s = "".join(sorted(s)) print(s) quit() for elemento in s: if elemento == "0": print("0", end="") elif elemento == "2" and not flag == True: for i in range(num): print("1", end="") flag = True print("2", end="") else: if elemento == "1": continue if elemento == "2": print("2", end="") print("")
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF STRING VAR STRING VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING STRING IF VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() s1 = "" c = 0 p = s.count("1") s = s.replace("1", "") for i in range(len(s)): if s[i] == "1": s1 += s[i] s = s.replace(s[i], "3", 1) elif s[i] == "0" and c == 0: s1 += "0" s = s.replace(s[i], "3", 1) else: c = 1 s2 = "" s1 += "1" * p for i in range(len(s)): if s[i] == "2" or s[i] == "0": s2 += s[i] print("".join(sorted(s1)) + s2)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING NUMBER IF VAR VAR STRING VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
n = list(input()) if "2" in n: k = n.index("2") new = "".join(n[k:]) grew = "".join(n[:k]) eazy = grew.count("0") * "0" + grew.count("1") * "1" hard = new.count("1") * "1" for el in new: if el != "1": hard += el print(eazy + hard) else: grew = "".join(n) eazy = grew.count("0") * "0" + grew.count("1") * "1" print(eazy)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING STRING BIN_OP FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP FUNC_CALL VAR STRING STRING FOR VAR VAR IF VAR STRING VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING STRING BIN_OP FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input().strip() if "2" not in s: print("".join(sorted(s))) exit() z = s.index("2") an = [] an.append("".join(sorted(s[:z]))) xx = s[z:].count("1") an.append("1" * xx) for i in range(z, len(s)): if s[i] != "1": an.append(s[i]) print("".join(an))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() s = [int(i) for i in s] s.reverse() ans = [0] * len(s) f = 0 r0, r1 = 0, 0 for i in s: if i == 2: while r0: r0 -= 1 ans[f] = 0 f += 1 ans[f] = 2 f += 1 elif i == 1: r1 += 1 else: r0 += 1 while r1: r1 -= 1 ans[f] = 1 f += 1 while r0: r0 -= 1 ans[f] = 0 f += 1 ans.reverse() for i in ans: print(i, end="")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
a = input() ones = 0 for i in a: if i == "1": ones += 1 frontZeroes = 0 for i in a: if i == "2": break if i == "0": frontZeroes += 1 b = "0" * frontZeroes + "1" * ones if a.count("2") > 0: for i in range(a.index("2"), len(a)): if a[i] != "1": b += a[i] print(b)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
n = input() lenght = len(n) if not "1" in n: print(n) elif not "2" in n: zero = n.count("0") string = "" lenght -= zero while zero: zero -= 1 string += "0" while lenght: lenght -= 1 string += "1" print(string) elif not "0" in n: zero = n.count("1") string = "" lenght -= zero while zero: zero -= 1 string += "1" while lenght: lenght -= 1 string += "2" print(string) else: zero = n.count("0") unu = n.count("1") doi = n.count("2") partial0 = 0 i = lenght - 1 d = "" while i >= 0: part = 0 if doi: while n[i] != "2": if n[i] == "0": part += 1 i -= 1 zero -= part while part: part -= 1 d += "0" while i >= 0: if n[i] != "2": break i -= 1 doi -= 1 d += "2" else: break while unu: d += "1" unu -= 1 while zero: zero -= 1 d += "0" d = d[::-1] print(d)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR EXPR FUNC_CALL VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING VAR VAR WHILE VAR VAR NUMBER VAR STRING WHILE VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING VAR VAR WHILE VAR VAR NUMBER VAR STRING WHILE VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR NUMBER IF VAR WHILE VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR VAR WHILE VAR VAR NUMBER VAR STRING WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR STRING WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR NUMBER VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() count_ones = 0 for c in s: if c == "1": count_ones += 1 s = s.replace("1", "") index = s.find("2") if index == -1: index = len(s) ones = "1" * count_ones new_string = s[:index] + ones + s[index:] print(new_string)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = str(input()) s1 = "" j = 0 k = 0 i = 0 l = 0 flag1 = 0 while i < len(s): if s[i] == "2": break if s[i] == "0": j += 1 elif s[i] == "1": k += 1 i += 1 s1 += "0" * j + "1" * k j = 0 k = 0 z1 = i while i < len(s): if s[i] == "2": s1 += "2" elif s[i] == "0": s1 += "0" else: k += 1 i += 1 s1 = s1[:z1] + k * "1" + s1[z1:] print(s1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
l = list(input()) s = l.count("1") ls = [] for i in range(len(l)): if l[i] == "1": ls.append(i) ls.sort(reverse=True) for i in range(len(ls)): del l[ls[i]] set1 = set(l) if "2" in set1: m = l.index("2") l1 = l[:m] l2 = l[m:] li = l1 + ["1"] * s + l2 print("".join(li)) else: li = l + ["1"] * s print("".join(li))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP LIST STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() answer = "" p = 0 o = 1 for i in s: if i == "1": p = p + 1 for i in s: if i == "0": answer = answer + "0" elif i == "2": answer = answer + "1" * (o * p) o = 0 answer = answer + "2" answer = answer + "1" * (o * p) print(answer)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(map(int, input())) try: first_two = s.index(2) start = sorted(s[:first_two]) end = [] for c in s[first_two:]: if c == 1: start.append(c) else: end.append(c) sor = start + end except: sor = sorted(s) print("".join(map(str, sor)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) ans = "" t = False cnt1 = 0 f2 = -1 pc = {"0": 0, "1": 0, "2": 0} for i in range(len(s)): if s[i] == "2": t = True if f2 == -1: f2 = i if not t: pc[s[i]] += 1 if s[i] == "1" and t: cnt1 += 1 if f2 == -1: print("0" * pc["0"] + "1" * pc["1"]) exit() ans = "0" * pc["0"] + "1" * (pc["1"] + cnt1) for i in range(f2, len(s)): if s[i] != "1": ans += s[i] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR STRING VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
a = input() count1 = 0 result = "" for i in a: if i == "1": count1 += 1 else: result += i index = len(result) + 1 for i in range(len(result)): if result[i] == "2": index = i + 1 break print(result[: index - 1] + "1" * count1 + result[index - 1 :])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP STRING VAR VAR BIN_OP VAR NUMBER
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
a = input() s = "" final = "" count = 0 for i in a: if i == "1": count += 1 else: s += i s += "2" i = s.find("2") print(s[:i] + "1" * count + s[i:-1])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR NUMBER
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
temp = [int(x) for x in list(input())] n = len(temp) cnt1 = 0 cnt0 = 0 line = [] for i in temp: if i == 1: cnt1 += 1 else: line.append(i) k = len(line) for i in range(len(line)): if line[i] == 2: k = i break cnt0 += 1 ans = [0] * cnt0 + [1] * cnt1 + line[k:] print("".join([str(x) for x in ans]))
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() c1 = s.count("1") cc = "1" * c1 if c1 == 0: print(s) elif s.count("2") == 0: print("0" * s.count("0") + cc) else: ans = "" for i in range(len(s)): if s[i] != "1": ans += s[i] ind = ans.index("2") ans1 = [ans[:ind], cc, ans[ind:]] print("".join(ans1))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) a = [] k1 = 0 for i in range(len(s)): if s[i] == "1": k1 += 1 else: a.append(s[i]) f = True i = 0 a.append("a") while i <= len(a): if i == len(a) - 1 and f or a[i] == "2" and f: f = False for j in range(k1): print(1, end="") if i == len(a) - 1: break print(a[i], end="") i += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
import sys input = sys.stdin.readline s = input().strip("\n") b = [] c = 0 last = -1 for i in range(len(s)): if s[i] == "1": c += 1 else: b.append(s[i]) if s[i] == "2" and last == -1: last = len(b) - 1 if last != -1: b = "".join(b[:last]) + "1" * c + "".join(b[last:]) else: b = "".join(b) + "1" * c print(b)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL STRING VAR VAR BIN_OP STRING VAR FUNC_CALL STRING VAR VAR ASSIGN VAR BIN_OP FUNC_CALL STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
a = list(input()) a = [int(i) for i in a] l = len(a) i = 0 c = [] prev = 0 flag = False b = [] fin = [] for i in a: if i is 1 or flag is False and i is 0: fin.append(i) if i is 2: flag = True b.append(i) if flag and i is 0: b.append(i) fin.sort() print("".join([str(i) for i in fin]) + "".join([str(i) for i in b]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() a = [] cnt = 0 for x in s: if x == "1": cnt += 1 else: a.append(x) i = 0 while i < len(a) and a[i] == "0": i += 1 print("0" * i + "1" * cnt + "".join(a[i:]))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR FUNC_CALL STRING VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) tmp = "" res = "" if "0" not in s or "2" not in s: res = "".join(sorted(s)) else: ind = s.index("2") res += "".join(sorted(s[:ind])) ones = s[ind:].count("1") res += ones * "1" lst = [x for x in s[ind:] if x != "1"] res += "".join(lst) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF STRING VAR STRING VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR BIN_OP VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR STRING VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = str(input()) answer = [] ed_count = 0 prev_null = 0 prev_twos = 0 for el in s: if el == "1": ed_count += 1 elif el == "0": if prev_null == 0: if prev_twos != 0: answer.append([2, prev_twos]) prev_twos = 0 prev_null += 1 else: if prev_twos == 0: if prev_null != 0: answer.append([0, prev_null]) prev_null = 0 prev_twos += 1 if prev_twos != 0: answer.append([2, prev_twos]) prew_twos = 0 if prev_null != 0: answer.append([0, prev_null]) prev_null = 0 if len(answer) != 0 and answer[0][0] == 0: print("{}".format(answer[0][0]) * answer[0][1], end="") print("1" * ed_count, end="") z = len(answer) min_in = 0 if z != 0 and answer[0][0] == 0: min_in += 1 for i in range(min_in, z): print(str(answer[i][0]) * answer[i][1], end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR NUMBER NUMBER VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() a = "" b = "" for i in s: if i == "1": a += i else: b += i n = b.find("2") if n == -1: ans = b + a else: ans = b[:n] + a + b[n:] print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
u = list(map(int, input())) n = len(u) d0 = 0 d1 = 0 d2 = 0 dd0 = [] dd2 = [] m0 = 0 for i in range(n): if u[i] == 1: d1 += 1 elif u[i] == 0: if dd2 == [] and d2 == 0: m0 = 1 d0 += 1 if d2 != 0: dd2.append(d2) d2 = 0 else: d2 += 1 if d0 != 0: dd0.append(d0) d0 = 0 if d0 != 0: dd0.append(d0) else: dd2.append(d2) ans = [] i = 0 while len(ans) < n: if m0: if len(dd0) > i: for j in range(dd0[i]): ans.append(0) if i == 0: for j in range(d1): ans.append(1) if len(dd2) > i: for j in range(dd2[i]): ans.append(2) else: if i == 0: for j in range(d1): ans.append(1) if len(dd2) > i: for j in range(dd2[i]): ans.append(2) if len(dd0) > i: for j in range(dd0[i]): ans.append(0) i += 1 for i in ans: print(i, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR LIST VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() oneCnt = s.count("1") sNo1s = s.replace("1", "") oneStr = "1" * oneCnt first2 = sNo1s.find("2") if first2 < 0: print(sNo1s + oneStr) else: print(sNo1s[:first2] + oneStr + sNo1s[first2:])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
input_ = list(map(str, input().split("2"))) result = "" z_counter = 0 z_list = [] o_counter = 0 for st in input_: for s in st[:]: if s == "1": o_counter += 1 elif s == "0": z_counter += 1 z_list.append(z_counter) z_counter = 0 for i, z in enumerate(z_list): result += "0" * z if i == 0: result += "1" * o_counter if i == len(z_list) - 1: break result += "2" print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP STRING VAR IF VAR NUMBER VAR BIN_OP STRING VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() t = "".join(c for c in s if c != "1") i = (t + "2").find("2") print(t[:i], "1" * s.count("1"), t[i:], sep="")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL BIN_OP VAR STRING STRING EXPR FUNC_CALL VAR VAR VAR BIN_OP STRING FUNC_CALL VAR STRING VAR VAR STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
n = input() t = n.count("1") n = n.replace("1", "") if "2" in n: r = n.index("2") print("0" * r + "1" * t + n[r:]) else: print("0" * n.count("0") + "1" * t)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING BIN_OP STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() oc = 0 zc = 0 id2 = len(s) for i in range(len(s)): if s[i] == "1": oc += 1 for i in range(len(s)): if s[i] == "0": zc += 1 if s[i] == "2": id2 = i break for i in range(zc): print("0", end="") for i in range(oc): print("1", end="") for i in range(id2, len(s)): if s[i] == "1": continue else: print(s[i], end="") print()
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() x = "" c = 0 for i in s: if i != "1": x += i else: c += 1 if len(x) == len(s): print(s) else: z = x.find("2") if z != -1: for i in range(z): print(x[i], end="") print("1" * c + x[z:]) else: print(x + "1" * c)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
inpt = input() inp = list(str(inpt)) temp = [] for i in inp: temp.append(int(i)) nums = temp[::-1] countZero = 0 countOne = 0 res = [] for i in range(len(nums)): if nums[i] == 0: countZero += 1 elif nums[i] == 1: countOne += 1 else: res += [0] * countZero res.append(2) countZero = 0 res += [1] * countOne res += [0] * countZero res = res[::-1] res = "".join(str(item) for item in res) print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP LIST NUMBER VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) ss = "" cnt = [0, 0, 0] i = 0 cnt = 0 while i != len(s) and s[i] in ["0", "1"]: cnt += s[i] == "0" i += 1 print("0" * cnt + "1" * s.count("1"), end="") while i != len(s): if s[i] in ["0", "2"]: print(s[i], end="") i += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR LIST STRING STRING VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING FUNC_CALL VAR STRING STRING WHILE VAR FUNC_CALL VAR VAR IF VAR VAR LIST STRING STRING EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() ind = 0 zeros = 0 ones = 0 while ind < len(s) and s[ind] != "2": if s[ind] == "0": zeros += 1 else: ones += 1 ind += 1 suff = "" while ind < len(s): if s[ind] == "1": ones += 1 else: suff += s[ind] ind += 1 print("0" * zeros + "1" * ones + suff)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
n = list(map(str, list(input()))) a = "" b = "" for i in n: if i == "1": a += "1" else: b += i n = b.find("2") if n == -1: print(b + a) else: print(b[:n] + a + b[n:])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() one = s.count("1") if one == 0: print(s) exit() ind = s.find("2") ans = "" for i in range(len(s)): if i == ind: ans += "1" * one if s[i] == "1": continue ans += s[i] if ind == -1: ans += "1" * one print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP STRING VAR IF VAR VAR STRING VAR VAR VAR IF VAR NUMBER VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
k = input() a = k.count("1") k = k.replace("1", "") b = (k + "2").find("2") k = k[:b] + "1" * a + k[b:] print(k)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL BIN_OP VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
a = input() n = len(a) s_zero = [0] * (n + 2) if a[0] == "0": s_zero[0] = 1 ans = "" a += "2" for i in range(1, n + 1): if a[i] == "0": s_zero[i] = s_zero[i - 1] + 1 else: s_zero[i] = s_zero[i - 1] pre = -1 two = 0 one = 0 zero = 0 for i in range(n + 1): if a[i] == "2": if pre == -1: pre = i else: cnt = s_zero[i] - s_zero[pre - 1] ans += "2" + "0" * cnt zero += cnt two += 1 pre = i zero = a.count("0") - zero one = a.count("1") - one ans = "0" * zero + "1" * one + ans print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR STRING VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP STRING VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
t = str(input("")) A = [] count = 0 s = "" check = 0 j = 0 for i in range(len(t)): if t[i] != "1": s += t[i] else: count += 1 for i in range(len(s)): if s[i] == "2": j = i break else: j = len(s) k = j - 1 ans = s[0:j] + "1" * count + s[j:] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() num_ones = s.count("1") s = s.replace("1", "") if "2" in s: first_two = s.index("2") s = s[0:first_two] + "1" * num_ones + s[first_two:] else: s += "1" * num_ones print(s)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP STRING VAR VAR VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() a = "" s = s[::-1] o = 0 z = 0 i = 0 while i != len(s): if s[i] == "2": a = a + "0" * z + "2" z = 0 if s[i] == "0": z += 1 if s[i] == "1": o += 1 i += 1 a = a + "1" * o + "0" * z a = a[::-1] print(a)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP STRING VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def main(): s = input() if "1" in s: t = s.replace("1", "") u, v, *_ = t.split("2", 1) + ["*"] print(u, "1" * (len(s) - len(t)), *(["2", v] if v != "*" else []), sep="") else: print(s) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER LIST STRING EXPR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING LIST STRING VAR LIST STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
line = list(input()) count = 0 for i in range(len(line) - 1, -1, -1): if line[i] == "1": del line[i] count += 1 try: two = line.index("2") newline = line[:two] + ["1"] * count + line[two:] except: newline = line + ["1"] * count print(*newline, sep="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP LIST STRING VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR VAR STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
import sys s = input() cnt = 0 ans = [] for x in s: if x == "1": cnt += 1 else: ans.append(x) for i in range(len(ans)): if ans[i] == "2": break else: print("".join(ans) + "1" * cnt) sys.exit() print("".join(ans[:i]) + "1" * cnt + "".join(ans[i:]))
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING VAR VAR BIN_OP STRING VAR FUNC_CALL STRING VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def main(): s = input() pos = s.find("2") pos = len(s) if pos < 0 else pos print("0" * s[:pos].count("0") + "1" * s.count("1") + s[pos:].replace("1", "")) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING BIN_OP STRING FUNC_CALL VAR STRING FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() prefix = "" suffix = "" middle = "" seen2 = False for c in s: if c == "2": seen2 = True suffix += c elif c == "1": middle += c elif seen2: suffix += c else: prefix += c print("%s%s%s" % (prefix, middle, suffix))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER VAR VAR IF VAR STRING VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def main(): string = input() chars = [] cnt = 0 for c in string: if c != "1": chars.append(c) else: cnt += 1 res = "".join(chars) if "2" in string: print(res[: res.find("2")] + "1" * cnt + res[res.find("2") :]) else: print(res + "1" * cnt) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING BIN_OP STRING VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input().strip() ones = s.count("1") s = "".join(filter(lambda c: c != "1", s)) indx = s.find("2") if indx == -1: print(s + "1" * ones) else: print(s[:indx] + "1" * ones + s[indx:])
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
t = 1 for test in range(t): n = list(input()) firstZeros = 0 onesCount = 0 for i in n: if i == "1": onesCount += 1 index = 0 for i in n: if i == "0": firstZeros += 1 elif i == "2": break index += 1 print("0" * firstZeros, end="") print("1" * onesCount, end="") zeroCount = 0 for i in range(index, len(n)): if n[i] == "2": print("0" * zeroCount, end="") print("2", end="") zeroCount = 0 elif n[i] == "0": zeroCount += 1 print("0" * zeroCount)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() l, m, r = "", "", "" for c in s: if c == "1": m += c elif c == "2": r += c elif r == "": l += c else: r += c print(l + m + r)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR STRING STRING STRING FOR VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
a = [i for i in input()] n = a.count("1") b = [i for i in a if i != "1"] if "2" in b: x = b.index("2") print("".join(b[:x]) + n * "1" + "".join(b[x:])) else: print("".join(b) + n * "1")
ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING VAR VAR BIN_OP VAR STRING FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR BIN_OP VAR STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() n = len(s) t, e = 0, 0 r = "" for i in range(n): t += s[i] == "1" for i in range(n): if s[i] == "0": r += "0" elif s[i] == "2": if not e: r += "1" * t t, e = 0, 1 r += "2" if not e: r += "1" * t print(r)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING IF VAR VAR STRING IF VAR VAR BIN_OP STRING VAR ASSIGN VAR VAR NUMBER NUMBER VAR STRING IF VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() s = list(s) uns = 0 for n in s: if n == "1": uns += 1 aindanao = 1 for a in s: if a == "2" and aindanao: aindanao = 0 for i in range(uns): print("1", end="") if a != "1": print(a, end="") if aindanao: aindanao = 0 for i in range(uns): print("1", end="") print()
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR STRING EXPR FUNC_CALL VAR VAR STRING IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(str(input())) s = [int(i) for i in s] X = [] temp = [] for i in s: if i != 2: temp.append(i) else: X.append(temp) temp = [] else: X.append(temp) ans = [[] for i in range(len(X))] for j, x in enumerate(X): for i in x: if i == 1: ans[0].append(1) else: ans[j].append(0) for i, x in enumerate(ans): if x: x = list(sorted(x)) x = [str(j) for j in x] ans[i] = "".join(x) else: ans[i] = "" ans = "2".join(ans) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL STRING VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) for i in range(len(s)): s[i] = int(s[i]) n = len(s) ans = [i for i in s if i == 0 or i == 2] c1 = sum([(1) for i in s if i == 1]) f2 = n for i in range(len(ans)): if ans[i] == 2: f2 = i break ans1 = ans[:f2] + [(1) for i in range(c1)] + ans[f2:] print("".join([str(i) for i in ans1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() c = 0 l = len(s) for i in range(len(s)): if s[i] == "1": c += 1 s = s.replace("1", "") s1 = "" if len(s) == 0: s1 = c * "1" print(s1) exit(0) for i in range(len(s)): if s[i] == "2": s1 = s1 + c * "1" s1 += s[i:] break s1 += s[i] if len(s1) != l: s1 += c * "1" print(s1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR STRING VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() l = "" for x in s: if x != "1": l += x two = s.count("2") one = s.count("1") ans = "" if two > 0: flag = 1 for i in range(len(l)): if l[i] == "2" and flag == 1: ans += "1" * one + "2" flag = 0 else: ans += l[i] else: ans = l ans += "1" * one print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) data = [] n = len(s) for i in range(n): s[i] = int(s[i]) cnt = 0 for some in s: if some == 1: cnt += 1 else: data.append(some) index = -1 for i in range(len(data)): if data[i] == 2: index = i break if index >= 0: k = data[:index] + [(1) for _ in range(cnt)] + data[index:] for i in range(n): k[i] = str(k[i]) print("".join(k)) else: k = data + [(1) for _ in range(cnt)] for i in range(n): k[i] = str(k[i]) print("".join(k))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() ones = 0 a = [] for i in s: if i == "1": ones += 1 else: a.append(i) two = -1 for i in range(len(a)): if a[i] == "2" and two == -1: print(ones * "1", end="") two = i print(a[i], end="") if two == -1: print(ones * "1", end="")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR STRING STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR STRING STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() was2 = False i = 0 am1 = 0 s1 = "" for i in range(len(s)): if s[i] == "1": am1 += 1 for i in range(len(s)): if s[i] == "2": if not was2: s1 += "1" * am1 + "2" was2 = True else: s1 += "2" if s[i] == "0": s1 += "0" if not was2: s1 += "1" * am1 print(s1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR NUMBER VAR STRING IF VAR VAR STRING VAR STRING IF VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() n = 0 m = 0 h = "" for i in range(len(s)): if s[i] == "1": m += 1 for i in range(len(s)): if s[i] == "0": n += 1 if s[i] == "2": h += "0" * n + "1" * m + "2" n = 0 m = 0 h += "0" * n + "1" * m print(h)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
string = input() string = [x for x in string] count_0 = [] count_1 = [] count_2 = [] counting_0 = 0 counting_1 = 0 counting_2 = 0 for number in string: if number == "1": counting_1 += 1 elif number == "0": counting_0 += 1 else: count_0.append(counting_0) counting_0 = 0 count_2.append("2") count_0.append(counting_0) count_1.append(counting_1) answer = [] first = True for idx, qtd_0 in enumerate(count_0): while qtd_0 > 0: answer.append("0") qtd_0 -= 1 while count_1[0] and first: answer.append("1") count_1[0] -= 1 first = False if len(count_0) > 1 and idx < len(count_2) and count_2[idx] == "2": answer.append("2") print("".join(answer))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR STRING VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) zeroes, ones, twos = s.count("0"), s.count("1"), s.count("2") news = [] for i in range(len(s)): if s[i] != "1": news.append(s[i]) if not twos: print("".join(news) + "1" * ones) exit() p = news.index("2") newss = news[:p] + [str("1" * ones)] + news[p:] print("".join(newss))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR LIST FUNC_CALL VAR BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() m = len(s) if "2" in s: index = s.find("2") s = "".join(list(sorted(list(s[:index])))) + s[index:].replace("1", "").rjust( m - index, "1" ) else: s = "".join(list(sorted(list(s)))) print(s)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def min_tr(s): c = s.count("1") if s[0] == "1" and s.count(s[0]) == len(s): return s if s.count("2") == 0: return "".join(sorted(s)) new = "" for i in range(len(s)): if s[i] == "0": new += "0" elif s[i] == "2": while c > 0: new += "1" c -= 1 new += "2" while c > 0: new += "1" c -= 1 return new print(min_tr(input()))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR STRING NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING IF VAR VAR STRING WHILE VAR NUMBER VAR STRING VAR NUMBER VAR STRING WHILE VAR NUMBER VAR STRING VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def main(): s = input() index = s.find("2") ones = 0 if index != -1: for i in range(index, len(s)): if s[i] == "1": ones += 1 l = list(s[0:index]) l.sort() tmp = "".join(l) for i in range(ones): tmp += "1" l = list(s[index:]) for c in l: if c != "1": tmp += c print(tmp) else: l = list(s) l.sort() print("".join(l)) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
t = input() t = t + "2" Z = [] U = 0 c = 0 for i in t: if i == "1": U += 1 elif i == "0": c += 1 else: Z.append(c) c = 0 for i in range(Z[0]): print("0", end="") for i in range(U): print("1", end="") for j in range(1, len(Z)): print("2", end="") for i in range(Z[j]): print("0", end="")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
num = input() length = len(num) first_2 = num.find("2") if first_2 == -1: first_2 = length zeros_before_first_two = num[:first_2].count("0") ones = num.count("1") print("0" * zeros_before_first_two, end="") print("1" * ones, end="") for i in range(first_2, length): if num[i] != "1": print(num[i], end="")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() z = "" t = "" o = "" f = 0 for i in range(len(s)): if s[i] == "0": t += "0" elif s[i] == "2": t += "2" else: o += "1" for i in range(len(t)): if t[i] == "2": t = t[:i] + o + t[i:] f = 1 break if f == 0: t = t + o print(t)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR STRING VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
ans = [] seen = False ones = 0 for c in input(): if c == "0": if not seen: print("0", end="") else: ans.append("0") elif c == "1": ones += 1 elif c == "2": seen = True ans.append("2") print(*(["1"] * ones), sep="", end="") print("".join(ans), end="")
ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR STRING IF VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING IF VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR STRING STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR STRING
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() ones = 0 o = [] first_two = -1 for i, x in enumerate(s): if x == "0": o.append(x) elif x == "1": ones += 1 else: if first_two == -1: first_two = len(o) o.append(x) if first_two == -1: first_two = len(o) one_str = "1" * ones print("".join(o[:first_two]) + one_str + "".join(o[first_two:]))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING VAR VAR VAR FUNC_CALL STRING VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() c1 = s.count("1") if "2" not in s: lens = len(s) print("0" * (lens - c1) + "1" * c1) else: f2 = s.index("2") s1 = s[:f2] s2 = "".join(c for c in s[f2:] if c != "1") c0 = s1.count("0") print("0" * c0 + "1" * c1 + s2)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() index = [0] n = len(s) zero = [] one = [] zo = 0 on = 0 for i in range(n): if s[i] == "2" and i != 0: index.append(i) zero.append(zo) one.append(on) zo = 0 on = 0 elif s[i] == "0": zo = zo + 1 elif s[i] == "1": on = on + 1 if index[-1] != n - 1: index.append(n) zero.append(zo) one.append(on) S = set(s) ans = "" b = len(index) if len(S) == 1: ans = ans + s elif len(S) == 2: if "0" in S and "1" in S: ans = "0" * s.count("0") + "1" * s.count("1") elif "1" in S and "2" in S: ans = "1" * s.count("1") + "2" * s.count("2") else: ans = ans + s else: b = len(one) if s[0] != "2": ans = ans + "0" * s[: index[1]].count("0") else: ans = ans + "0" * s[: index[0]].count("0") ans = ans + "1" * s.count("1") p = "" a = s.find("2") for i in range(a, n): if s[i] != "1": p = p + s[i] ans = ans + p print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER IF STRING VAR STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING BIN_OP STRING FUNC_CALL VAR STRING IF STRING VAR STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() x1 = s.count("1") if s.count("2") == 0: print(s.count("0") * "0" + x1 * "1") else: x = s.index("2") s1 = s[:x] s2 = s[x:] x0 = s1.count("0") s2 = s2.replace("1", "") print("0" * x0 + "1" * x1 + s2)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING STRING BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() n = len(s) _0, _1, i = 0, 0, 0 while i < n and s[i] != "2": if s[i] == "0": _0 += 1 elif s[i] == "1": _1 += 1 i += 1 front = "0" * _0 + "1" * _1 end = "" for c in s[i:]: if c == "1": front += c else: end += c print(front + end)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR STRING IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR STRING FOR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() x = s.count("1") s = s.replace("1", "") s = "1" * x + s u = 0 z = 0 l = 0 ans = "" for i in range(len(s)): if s[i] == "2": ans += "0" * z + "1" * u + "2" z = 0 u = 0 elif s[i] == "1": u += 1 elif s[i] == "0": z += 1 ans += "0" * z + "1" * u print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def solve(s): ones = s.count("1") stripped = "".join([i for i in s if i != "1"]) for i in range(len(stripped)): if stripped[i] == "2": return stripped[:i] + "1" * ones + stripped[i:] return stripped + "1" * ones s = input().strip() print(solve(s))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING RETURN BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR RETURN BIN_OP VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() temp1 = "" temp2 = "" for x in s: if x == "0" or x == "2": temp1 += x else: temp2 += x put = False for i in range(len(temp1)): if temp1[i] == "2": temp1 = temp1[:i] + temp2 + temp1[i:] put = True break if not put: temp1 = temp1 + temp2 print(temp1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() ones, s = s.count("1"), s.replace("1", "") print( s[: s.index("2")] + "1" * ones + s[s.index("2") :] if "2" in s else s + "1" * ones )
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING BIN_OP STRING VAR VAR FUNC_CALL VAR STRING BIN_OP VAR BIN_OP STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() string = "" c0 = 0 c1 = 0 c2 = 0 state = 0 p = 9999999 for i in range(len(s)): if state == 0: if s[i] == "1": c1 += 1 elif s[i] == "0": c0 += 1 else: c2 += 1 for j in range(c0): string += "0" p = min(p, len(string)) c0 = 0 state = 1 elif state == 1: if s[i] == "1": c1 += 1 elif s[i] == "2": c2 += 1 else: c0 += 1 for j in range(c2): string += "2" c2 = 0 state = 0 if p == 9999999: stt = "" for j in range(c0): stt += "0" for j in range(c1): stt += "1" else: stt = string[0:p] for j in range(c1): stt += "1" stt += string[p:] if state == 0: for j in range(c0): stt += "0" for j in range(c2): stt += "2" else: for j in range(c2): stt += "2" for j in range(c0): stt += "0" print(stt)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR STRING VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() p = "" c0, c1 = 0, 0 for i in range(len(s)): if s[i] == "0": c0 += 1 if s[i] == "1": c1 += 1 if s[i] == "2": p += "0" * c0 + "1" * c1 + "2" c0, c1 = 0, 0 p += "0" * c0 + "1" * c1 if p.find("2") == -1: print(p) else: c1 = 0 s2 = "" for i in range(p.find("2"), len(s)): if p[i] == "2": s2 += "2" if p[i] == "0": s2 += "0" if p[i] == "1": c1 += 1 ans = p[0 : p.find("2")] + "1" * c1 + s2 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR STRING ASSIGN VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
x = input() x = x[::-1] y = ["0"] * len(x) ji = 0 ji1 = 0 flag = 0 for i in range(len(x)): if x[i] == "1": ji1 += 1 if x[i] == "2": flag = 1 ji = max(ji, i - ji1) y[ji] = "2" if flag: y = y[::-1] for i in range(len(y)): if y[i] == "2": for j in range(ji1): y[i - j - 1] = "1" break else: for i in range(ji1): y[i] = "1" y = y[::-1] print("".join(y))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR STRING IF VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
ch = input() p = ch.find("2") if p == -1: p = len(ch) a = ch[0:p].count("0") b = ch.count("1") st = "0" * a + "1" * b + ch[p:].replace("1", "") print(st)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() cnt = 0 s1 = s2 = s3 = "" flag = 0 for i in s: if flag: if i == "1": cnt = cnt + 1 else: s3 = s3 + i elif i == "0": s1 = s1 + i elif i == "1": cnt = cnt + 1 else: s3 = i flag = 1 for i in range(cnt): s2 = s2 + "1" print(s1 + s2 + s3)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() n = len(s) tp = "" ans = "" c0, c1, c2 = 0, 0, 0 for e in s: if e == "1": c1 = c1 + 1 elif e == "0": c0 = c0 + 1 else: c2 = c2 + 1 if c2 == 0: r = "0" * c0 + "1" * c1 print(r) else: r = "" z = s.index("2") lp = s[:z] qw = lp.count("0") p = 0 while z < n: a = s[z] if a == "1": p = p + 1 z = z + 1 else: c = 0 while z < n and s[z] == a: c = c + 1 z = z + 1 r = r + a * c ans = "0" * qw + "1" * c1 + r print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
fixed = set(["0", "2"]) def sort(ss): out = [] count = 0 for a in ss: if a in fixed: out.append(a) else: count += 1 ind = 0 for a in out: if a == "0": ind += 1 continue break out.insert(ind, "".join(["1" for b in range(count)])) return "".join(out) print(sort(input()))
ASSIGN VAR FUNC_CALL VAR LIST STRING STRING FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING STRING VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def helper(s): zero = s.count("0") one = s.count("1") two = s.count("2") if zero == 0: return "1" * one + "2" * two elif one == 0: return s elif two == 0: return "0" * zero + "1" * one else: l = "" r = "" f = False for i in s: if i == "1": continue if i == "2": f = True if f: r += i else: l += i return l + "1" * one + r s = input() print(helper(s))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER RETURN BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP STRING VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
k = input() l = list(k) l.sort() c = l.count("1") s = "" count = 0 one = 0 if c == 0: print(k) else: for i in range(len(l)): if k[i] == "0": count += 1 elif k[i] == "2": break one = c + 0 maxi = count for i in range(len(l)): if l[i] == "0" and count > 0: s += l[i] count -= 1 elif l[i] == "1" and one > 0: one -= 1 s += l[i] for i in range(len(k)): if k[i] == "0" and maxi > 0: maxi -= 1 elif k[i] == "0" and maxi == 0: s = s + k[i] elif k[i] == "2": s = s + k[i] print(s)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
a = list(input()) n = len(a) if "2" not in a or "0" not in a: print("".join(sorted(a))) else: ind = a.index("2") i = n - 1 ans = [] count = 0 while i >= ind: if a[i] != "1": ans.append(a[i]) else: count += 1 i -= 1 ans = sorted(a[: i + 1] + ["1"] * count) + ans[::-1] print("".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP LIST STRING VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() pref = [] cnt1 = s.count("1") s = s.replace("1", "") i = 0 while i < len(s) and s[i] != "2": i += 1 end = "" if i != len(s): end = s[i:] s = s[:i] + "1" * cnt1 + end print(s)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR STRING IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() l = len(s) count_1 = s.count("1") new_out = "" red = "".join([c for c in s if c != "1"]) out = "" try: insert = red.index("2") out = red[:insert] + "1" * count_1 + red[insert:] except: out = red + "1" * count_1 print(out)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
st = input() kol_1 = st.count("1") stroka = [] lena = 0 for elem in st: if elem != "1": stroka += [elem] lena += 1 i = 0 while i < lena and stroka[i] != "2": i += 1 stroka = stroka[0:i] + ["1"] * kol_1 + stroka[i:] print("".join(map(str, stroka)))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP LIST STRING VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) s.append("2") l = [] c = s.count("1") f = 0 for i in range(len(s)): if s[i] == "2" and f == 0: for j in range(c): l.append("1") f = 1 l.append("2") elif s[i] != "1": l.append(s[i]) l = l[: len(s) - 1] print("".join(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = input() cnt1 = 0 ans = "" for i in s: if i != "1": ans += i else: cnt1 += 1 f = 0 for i in range(len(ans)): if ans[i] == "2": ans = ans[0:i] + "1" * cnt1 + ans[i : len(ans)] f += 1 break if f == 0: ans += "1" * cnt1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP STRING VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(map(int, list(input()))) c = [0, 0, 0] ans = list() f = True for el in s: if el == 0 and c[2] > 0: ans.append("0" * c[0]) if f: ans.append("1" * s.count(1)) f = False ans.append("2" * c[2]) c = [0, 0, 0] if el != 1: c[el] += 1 ans.append("0" * c[0]) ans.append("2" * c[2]) if f: if 0 not in s: ans.insert(0, "1" * s.count(1)) elif 2 not in s: ans.insert(-1, "1" * s.count(1)) else: ans.insert(1, "1" * s.count(1)) f = False print("".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER IF VAR IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP STRING FUNC_CALL VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP STRING FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP STRING FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def min_ternary_string(seq): zero_two = [ch for ch in seq if ch != "1"] ones = seq.count("1") i = 0 while i < len(zero_two): if zero_two[i] == "2": break i += 1 return "".join(zero_two[:i]) + "1" * ones + "".join(zero_two[i:]) print(min_ternary_string(input()))
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL STRING VAR VAR BIN_OP STRING VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
def writeRestOfString(TS, result, indexOfFirstTwo): size = len(TS) for num in TS[indexOfFirstTwo:size]: result += str(num) return result def removeAllOnesAfterFirstTwo(TS, indexOfFirstTwo): i = indexOfFirstTwo size = len(TS) beginOfTS = TS[0:indexOfFirstTwo] restOfTS = "" while i < size: if TS[i] != "1": restOfTS += str(TS[i]) i += 1 return beginOfTS + restOfTS def countZerosAndOnes(TS, limit): i = 0 zeros = 0 ones = 0 while i < limit: if TS[i] == 1: ones += 1 else: zeros += 1 i += 1 return zeros, ones def countOnes(TS, limit): i = 0 ones = 0 while i < limit: if TS[i] == 1: ones += 1 i += 1 return ones def countZeros(TS, limit): i = 0 zeros = 0 while i < limit: if TS[i] == 0: zeros += 1 i += 1 return zeros def writeZeros(result, zeros): i = 1 while i <= zeros: result += str(0) i += 1 return result def writeOnes(result, ones): i = 1 while i <= ones: result += str(1) i += 1 return result def checkForFirstTwo(TS): i = 0 size = len(TS) while i < size: if TS[i] == 2 or TS[i] == "2": return i i += 1 return None def changeStringWithOnlyOnesAndZeros(TS): size = len(TS) result = "" zeros, ones = countZerosAndOnes(TS, size) result = writeZeros(result, zeros) result = writeOnes(result, ones) return result def changeString(TS, indexOfFirstTwo): result = "" size = len(TS) zeros = countZeros(TS, indexOfFirstTwo) ones = countOnes(TS, size) result = writeZeros(result, zeros) result = writeOnes(result, ones) result = writeRestOfString(TS, result, indexOfFirstTwo) indexOfFirstTwo = checkForFirstTwo(result) result = removeAllOnesAfterFirstTwo(result, indexOfFirstTwo) return result def splitString(string): characters = [] size = len(string) i = 0 while i < size: characters.append(int(string[i])) i += 1 return characters ternaryString = input() TSArray = splitString(ternaryString) indexOfFirstTwo = checkForFirstTwo(TSArray) if indexOfFirstTwo != None: print(changeString(TSArray, indexOfFirstTwo)) else: print(changeStringWithOnlyOnesAndZeros(TSArray))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR STRING WHILE VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR VAR STRING RETURN VAR VAR NUMBER RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) one = 0 res = "" for x in s: if x == "1": one += 1 else: res += x ans = -1 for i in range(len(res)): if res[i] == "2": ans = i break new_s = "1" * one if ans == -1: s = res + new_s elif ans == 0: s = new_s + res else: s = res[:ans] + new_s + res[ans:] print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
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" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "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 $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (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
s = list(input()) count = 0 for i in range(len(s) - 1, -1, -1): if s[i] == "1": count += 1 del s[i] try: mark = s.index("2") except: mark = -1 if mark == -1: s.extend(["1"] * count) else: s = s[:mark] + ["1"] * count + s[mark:] print(*s, sep="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP LIST STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING