description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You have an array $a$ of length $n$. For every positive integer $x$ you are going to perform the following operation during the $x$-th second:
Select some distinct indices $i_{1}, i_{2}, \ldots, i_{k}$ which are between $1$ and $n$ inclusive, and add $2^{x-1}$ to each corresponding position of $a$. Formally, $a_{i_{j}} := a_{i_{j}} + 2^{x-1}$ for $j = 1, 2, \ldots, k$. Note that you are allowed to not select any indices at all.
You have to make $a$ nondecreasing as fast as possible. Find the smallest number $T$ such that you can make the array nondecreasing after at most $T$ seconds.
Array $a$ is nondecreasing if and only if $a_{1} \le a_{2} \le \ldots \le a_{n}$.
You have to answer $t$ independent test cases.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^{4}$)Β β the number of test cases.
The first line of each test case contains single integer $n$ ($1 \le n \le 10^{5}$)Β β the length of array $a$. It is guaranteed that the sum of values of $n$ over all test cases in the input does not exceed $10^{5}$.
The second line of each test case contains $n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ ($-10^{9} \le a_{i} \le 10^{9}$).
-----Output-----
For each test case, print the minimum number of seconds in which you can make $a$ nondecreasing.
-----Example-----
Input
3
4
1 7 6 5
5
1 2 3 4 5
2
0 -4
Output
2
0
3
-----Note-----
In the first test case, if you select indices $3, 4$ at the $1$-st second and $4$ at the $2$-nd second, then $a$ will become $[1, 7, 7, 8]$. There are some other possible ways to make $a$ nondecreasing in $2$ seconds, but you can't do it faster.
In the second test case, $a$ is already nondecreasing, so answer is $0$.
In the third test case, if you do nothing at first $2$ seconds and select index $2$ at the $3$-rd second, $a$ will become $[0, 0]$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = a.copy()
for i in range(n - 1):
if b[i] > b[i + 1]:
b[i + 1] = b[i]
s = max([(b[i] - a[i]) for i in range(n)])
print(len(bin(s)) - 2 if s != 0 else 0)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER
|
You have an array $a$ of length $n$. For every positive integer $x$ you are going to perform the following operation during the $x$-th second:
Select some distinct indices $i_{1}, i_{2}, \ldots, i_{k}$ which are between $1$ and $n$ inclusive, and add $2^{x-1}$ to each corresponding position of $a$. Formally, $a_{i_{j}} := a_{i_{j}} + 2^{x-1}$ for $j = 1, 2, \ldots, k$. Note that you are allowed to not select any indices at all.
You have to make $a$ nondecreasing as fast as possible. Find the smallest number $T$ such that you can make the array nondecreasing after at most $T$ seconds.
Array $a$ is nondecreasing if and only if $a_{1} \le a_{2} \le \ldots \le a_{n}$.
You have to answer $t$ independent test cases.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^{4}$)Β β the number of test cases.
The first line of each test case contains single integer $n$ ($1 \le n \le 10^{5}$)Β β the length of array $a$. It is guaranteed that the sum of values of $n$ over all test cases in the input does not exceed $10^{5}$.
The second line of each test case contains $n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ ($-10^{9} \le a_{i} \le 10^{9}$).
-----Output-----
For each test case, print the minimum number of seconds in which you can make $a$ nondecreasing.
-----Example-----
Input
3
4
1 7 6 5
5
1 2 3 4 5
2
0 -4
Output
2
0
3
-----Note-----
In the first test case, if you select indices $3, 4$ at the $1$-st second and $4$ at the $2$-nd second, then $a$ will become $[1, 7, 7, 8]$. There are some other possible ways to make $a$ nondecreasing in $2$ seconds, but you can't do it faster.
In the second test case, $a$ is already nondecreasing, so answer is $0$.
In the third test case, if you do nothing at first $2$ seconds and select index $2$ at the $3$-rd second, $a$ will become $[0, 0]$.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
max_val = a[0]
max_diff = 0
for i in range(1, n):
if a[i] > max_val:
max_val = a[i]
if max_val - a[i] > max_diff:
max_diff = max_val - a[i]
total = 0
num = 1
count = 0
while max_diff > total:
total += num
num *= 2
count += 1
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have an array $a$ of length $n$. For every positive integer $x$ you are going to perform the following operation during the $x$-th second:
Select some distinct indices $i_{1}, i_{2}, \ldots, i_{k}$ which are between $1$ and $n$ inclusive, and add $2^{x-1}$ to each corresponding position of $a$. Formally, $a_{i_{j}} := a_{i_{j}} + 2^{x-1}$ for $j = 1, 2, \ldots, k$. Note that you are allowed to not select any indices at all.
You have to make $a$ nondecreasing as fast as possible. Find the smallest number $T$ such that you can make the array nondecreasing after at most $T$ seconds.
Array $a$ is nondecreasing if and only if $a_{1} \le a_{2} \le \ldots \le a_{n}$.
You have to answer $t$ independent test cases.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^{4}$)Β β the number of test cases.
The first line of each test case contains single integer $n$ ($1 \le n \le 10^{5}$)Β β the length of array $a$. It is guaranteed that the sum of values of $n$ over all test cases in the input does not exceed $10^{5}$.
The second line of each test case contains $n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ ($-10^{9} \le a_{i} \le 10^{9}$).
-----Output-----
For each test case, print the minimum number of seconds in which you can make $a$ nondecreasing.
-----Example-----
Input
3
4
1 7 6 5
5
1 2 3 4 5
2
0 -4
Output
2
0
3
-----Note-----
In the first test case, if you select indices $3, 4$ at the $1$-st second and $4$ at the $2$-nd second, then $a$ will become $[1, 7, 7, 8]$. There are some other possible ways to make $a$ nondecreasing in $2$ seconds, but you can't do it faster.
In the second test case, $a$ is already nondecreasing, so answer is $0$.
In the third test case, if you do nothing at first $2$ seconds and select index $2$ at the $3$-rd second, $a$ will become $[0, 0]$.
|
for _ in range(int(input())):
size = int(input())
array, time, check = list(map(int, input().split())), -1000000000.0, 0
for x in array:
time = max(time, x)
check = max(check, time - x)
print(check and len(f"{check:b}"))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR 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
|
n = input()
ones = 0
final_str = ""
for char in n:
if char == "1":
ones += 1
else:
final_str += char
actual_final_str = ""
for i in range(len(final_str)):
if final_str[i] == "2":
actual_final_str += "1" * ones + final_str[i:]
break
if i == len(final_str) - 1:
actual_final_str += final_str[i] + "1" * ones
break
else:
actual_final_str += final_str[i]
if len(actual_final_str) < len(n):
actual_final_str += "1" * ones
print(actual_final_str)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR NUMBER VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP BIN_OP STRING VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL 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() + "2"
cnt1 = s.count("1")
s = s.replace("1", "")
pos = s.find("2")
print(s[:pos] + "1" * cnt1 + s[pos:-1])
|
ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING 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
|
class Numero:
def __init__(self, num):
self.qtd_0 = num.count("0")
self.qtd_1 = num.count("1")
self.qtd_2 = num.count("2")
string = input()
num = Numero(string)
if "1" in string:
string = string.replace("1", "")
if "2" in string:
string = string[: string.index("2")] + "1" * num.qtd_1 + string[string.index("2") :]
else:
string += "1" * num.qtd_1
print(string)
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING IF STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING BIN_OP STRING VAR VAR FUNC_CALL VAR 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
|
s = input()
head = ""
tail = ""
for ch in s:
if ch == "1":
head += ch
elif ch == "0" and len(tail) == 0:
head = ch + head
else:
tail += ch
print(head + tail)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR IF VAR STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP 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
|
while True:
try:
def soln(s):
n = len(s)
zeon = []
one = 0
for i in range(n):
if s[i] != "1":
zeon.append(s[i])
else:
one += 1
ans = []
for j in range(len(zeon)):
if zeon[j] == "2":
for i in range(one):
ans.append("1")
one = 0
ans.append(zeon[j])
for j in range(one):
ans.append("1")
print("".join(ans))
def read():
s = input()
soln(s)
if __name__ == "__main__":
read()
except EOFError:
break
|
WHILE NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF 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()
c = s.count("1")
s = s.replace("1", "")
x = s.find("2")
if x == -1:
print(s + "1" * c)
else:
print(s[: int(x)] + "1" * c + s[int(x) :])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING 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 FUNC_CALL VAR VAR BIN_OP STRING VAR 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()
a = "".join([i for i in s if i in ["0", "2"]])
b = "1" * s.count("1")
print(a[: a.find("2")] + b + a[a.find("2") :] if "2" in s else a + b)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR LIST STRING STRING ASSIGN VAR BIN_OP STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR STRING 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()
l = len(s)
z = -1
c0 = 0
c1 = 0
c2 = 0
loc = -1
for i in range(l):
c = s[i]
if c == "0":
c0 += 1
if c == "1":
c1 += 1
if c == "2":
c2 += 1
if z == -1:
z = c0
loc = i
if z == -1:
for i in range(c0):
print(0, end="")
for i in range(c1):
print(1, end="")
print()
else:
for i in range(z):
print(0, end="")
for i in range(c1):
print(1, end="")
for i in range(loc, l):
if s[i] != "1":
print(s[i], end="")
print()
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR 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
|
def solve(x):
result_string = ""
ones_count = 0
nulls_before = 0
i = 0
while i < len(x) and x[i] != "2":
if x[i] == "1":
ones_count += 1
elif x[i] == "0":
nulls_before += 1
i += 1
while i < len(x):
if x[i] == "1":
ones_count += 1
else:
result_string += x[i]
i += 1
return "0" * nulls_before + "1" * ones_count + result_string
x = input()
print(solve(x))
|
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP STRING 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
|
s = input()
try:
first = s.index("2")
final = list(s[:first])
final.sort()
final = "".join(final)
extra = ""
for j in range(first, len(s)):
if s[j] in ["2", "0"]:
extra += s[j]
else:
final += "1"
print(final + extra)
except:
l = list(s[:])
l.sort()
print("".join(l))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR LIST STRING STRING VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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
|
a = input()
b = len(a)
x = a.count("1")
y = ""
for i in range(b):
if a[i] != "1":
y += a[i]
if "2" in a:
print(y[: y.index("2")] + "1" * x + y[y.index("2") :])
else:
print("".join(sorted(list(y))) + "1" * x)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR 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 FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR 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()
len1 = s.count("1")
index2 = s.find("2")
if index2 == -1:
s = list(s)
s.sort()
print("".join(s))
else:
temp = s[:index2]
zero = temp.count("0")
result = "0" * zero + "1" * len1 + s[index2:].replace("1", "")
print(result)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR VAR VAR 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
|
from sys import exit
s = input()
q = [(-1) for i in range(len(s))]
ans = []
q = -1
for i in range(len(s)):
if s[i] != "1":
ans.append(s[i])
for i in range(len(ans)):
if ans[i] == "2":
q = i
break
ind = q
if ind == -1:
ind = len(ans)
for i in range(ind):
print(ans[i], end="")
print(s.count("1") * "1", end="")
for i in range(ind, len(ans)):
print(ans[i], end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING STRING STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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
|
def scanf(obj=list, type=int):
return obj(map(type, input().split()))
s = input()[-1::-1]
ans = ""
z = on = 0
for i in range(len(s)):
if s[i] == "0":
z += 1
if s[i] == "1":
on += 1
if s[i] == "2":
ans += "0" * z + "2"
z = 0
ans += "1" * on + "0" * z
print(ans[-1::-1])
|
FUNC_DEF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR 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 STRING VAR STRING ASSIGN VAR NUMBER VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR NUMBER 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
|
def main():
ss = []
s = input()
last = ""
_0s = 0
_1s = 0
_2s = 0
for c in reversed(s):
if c == "0":
ss.append("2" * _2s)
_2s = 0
_0s += 1
elif c == "1":
_1s += 1
else:
ss.append("0" * _0s)
_0s = 0
_2s += 1
ss.append("0" * _0s + "1" * _1s + "2" * _2s)
print("".join(reversed(ss)))
main()
|
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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
|
s = input()
if len(set(s)) == 1:
print(s)
else:
noOnes = ""
oneCount = 0
for i in range(len(s)):
if s[i] == "1":
oneCount += 1
else:
noOnes += s[i]
for i in range(len(noOnes)):
if noOnes[i] == "2":
noOnes = noOnes[:i] + "1" * oneCount + noOnes[i:]
break
if i == len(noOnes) - 1:
noOnes = noOnes + "1" * oneCount
print(noOnes)
|
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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
|
params = input()
params = list(params)
zero = 0
one = 0
x = 0
while x < params.__len__():
if params[x] == "1":
one += 1
params.pop(x)
else:
x += 1
x = 0
while x < params.__len__():
if params[x] == "2":
break
else:
zero += 1
params.pop(x)
params.insert(0, "1" * one)
params.insert(0, "0" * zero)
s = ""
print(s.join(params))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR NUMBER BIN_OP STRING VAR ASSIGN VAR STRING 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
|
r = list(input())
s = ""
count = 0
for i in r:
if i == "1":
count = count + 1
else:
s = s + i
ans = ""
u = 0
while u < len(s):
if s[u] == "2":
break
else:
u = u + 1
ans = s[:u] + count * "1" + s[u:]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP 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
|
s = input()
ln = len(s)
o = s.count("1")
t = z = b = c = 0
for i in range(ln):
if s[i] == "0" or s[i] == "2":
if s[i] == "0":
z = 1
c += 1
elif s[i] == "2":
if z and c and not b:
for j in range(c):
print(0, end="")
for j in range(o):
print(1, end="")
print(2, end="")
b = 1
o = 0
c = 0
elif not b:
for j in range(o):
print(1, end="")
print(2, end="")
b = 1
o = 0
else:
for j in range(c):
print(0, end="")
print(2, end="")
c = 0
for i in range(c):
print(0, end="")
for i in range(o):
print(1, end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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()
answer = ""
zero = one = 0
finished = False
for num in s:
if num == "0":
if finished == False:
zero += 1
else:
answer += num
if num == "1":
one += 1
if num == "2":
finished = True
answer += num
z = "".join(["0"] * zero)
o = "".join(["1"] * one)
print(z + o + answer)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR NUMBER VAR NUMBER VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL STRING BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL STRING BIN_OP LIST STRING 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
|
s = input()
ones = s.count("1")
s = s.replace("1", "")
indTwo = s.find("2")
if indTwo != -1:
print(s[:indTwo] + "1" * ones + s[indTwo:])
else:
print(s + "1" * ones)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR 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
|
s = input()
ans = ""
cnt = 0
for char in s:
if char == "1":
cnt += 1
else:
ans += char
pos = 0
while pos < len(ans) and ans[pos] == "0":
pos += 1
res = ans[:pos] + "1" * cnt + ans[pos:]
print(res)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER 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
|
count1 = 0
result = []
a = input()
for i in a:
if i == "1":
count1 += 1
elif i == "0" or i == "2":
result.append(i)
try:
index = result.index("2")
temp = result[index:]
result = result[:index] + ["1"] * count1 + temp
except ValueError:
result.extend(["1"] * count1)
print("".join(result))
|
ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP LIST STRING VAR VAR VAR EXPR FUNC_CALL 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()
n = len(s)
ans = ""
flag = 0
for i in range(n):
if s[i] == "1":
ans += "1"
for i in range(n):
if s[i] == "1":
continue
elif s[i] == "2":
ans += "2"
flag = 1
elif flag == 0:
ans = "0" + ans
else:
ans += "0"
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING 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
|
def main():
s = input()
n = len(s)
nums = [[], [], []]
if n == 1:
print(s)
return 0
for i in range(n):
nums[int(s[i])].append(i)
if len(nums[0]) == 0:
temp = len(nums[1])
print("1" * temp + "2" * (n - temp))
elif len(nums[2]) == 0:
temp = len(nums[0])
print("0" * temp + "1" * (n - temp))
else:
S = [i for i in s if i != "1"]
temp = len(nums[1])
for i in range(len(S)):
if S[i] == "2":
break
print("".join(S[:i]) + temp * "1" + "".join(S[i:]))
return 0
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST LIST LIST IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING VAR VAR BIN_OP VAR STRING FUNC_CALL STRING VAR VAR RETURN NUMBER 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
|
a = input()
ans = a.replace("1", "") + "2"
t = ans.find("2")
print(ans[:t] + "1" * a.count("1") + ans[t:-1])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING STRING STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING FUNC_CALL VAR STRING 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
|
a = input() + "2"
f = a.index("2")
b = a[f:]
o = ""
for i in b:
if i != "1":
o += i
a = a[:f]
print(a.count("0") * "0" + a.count("1") * "1" + b.count("1") * "1" + o[:-1])
|
ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING STRING BIN_OP FUNC_CALL VAR STRING STRING BIN_OP FUNC_CALL VAR STRING 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
|
a = input()
x = len(a)
q = 0
a = a.replace("1", "")
if len(a) != 0:
if a[0] == "2":
print("1" * (x - len(a)) + a)
exit(0)
else:
for i in range(len(a) - 1):
print(a[i], end="")
if a[i + 1] == "2":
print("1" * (x - len(a)) + a[i + 1 :])
q = 1
break
if q == 0:
print("0", end="")
if q == 0:
print("1" * (x - len(a)))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP 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()
t = ""
num = 0
for i in range(len(s)):
if s[i] == "1":
num += 1
else:
t += s[i]
s = num * "1" + t
p = s.split("0")
q = []
for k in p:
q.append("".join(sorted(list(k))))
p = "0".join(q)
p = p.split("2")
q = []
for k in p:
q.append("".join(sorted(list(k))))
p = "2".join(q)
print(p)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR 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 = input()
ans = ""
count_0 = 0
count_1 = 0
done = False
for val in s:
if val == "0":
if not done:
count_0 += 1
else:
ans += val
if val == "1":
count_1 += 1
if val == "2":
done = True
ans += val
print("".join(["0"] * count_0) + "".join(["1"] * count_1) + ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR VAR NUMBER VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING BIN_OP LIST STRING VAR FUNC_CALL STRING BIN_OP LIST 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(str(input()))
empty = ""
for i in range(len(s)):
zero = 0
if s[i] == "2":
for t in range(i + 1, len(s)):
if s[t] == "0":
zero += 1
if s[t] == "2":
break
empty += "2" + "0" * zero
empty = (s.count("0") - empty.count("0")) * "0" + "1" * s.count("1") + empty
print(empty)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP STRING BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING STRING BIN_OP STRING FUNC_CALL VAR 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 main():
s = list(map(int, input()))
cnt0, cnt1 = 0, 0
ans = []
for a in s:
if a == 1:
cnt1 += 1
elif a == 2:
ans.append(a)
elif a == 0:
if not ans:
cnt0 += 1
else:
ans.append(a)
s = "0" * cnt0 + "1" * cnt1 + "".join(map(str, ans))
print(s)
def __starting_point():
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL 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()
t = [x for x in s if x != "1"]
if not t:
print(s)
else:
o = ["1"] * (len(s) - len(t))
try:
i = t.index("2")
print("".join(t[:i] + o + t[i:]))
except ValueError:
print("".join(t + o))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR STRING IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 = list(input())
if (
len(s) == s.count("1")
or len(s) == s.count("2")
or len(s) == s.count("0")
or len(s) == s.count("0") + s.count("2")
):
print("".join(s))
elif len(s) == s.count("1") + s.count("0"):
print("0" * s.count("0") + "1" * s.count("1"))
elif len(s) == s.count("1") + s.count("2"):
print("1" * s.count("1") + "2" * s.count("2"))
else:
a, si = s.count("1"), [i for i in s if i != "1"]
str = "".join(si)
b = str.index("2")
str = str[:b] + "1" * a + str[b:]
print(str)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING BIN_OP STRING FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR 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
|
n = list(map(int, input()))
mmm = True
if len(n) > 1000:
if n[0] == 2:
xxx = len(n) - 1
for i in range(1, 1000):
if n[i] == 2 or n[i] == 0:
mmm = False
break
else:
mmm = False
else:
mmm = False
_javob_ = []
v = 0
c = 0
hh = True
nn = True
i = 0
q = len(n) - 1
while i <= q and mmm == False:
nn = True
if n[i] == 1:
v += 1
n.pop(i)
i -= 1
if i < 0:
i += 1
nn == False
if len(n) < 1:
break
if n[i] == 2:
hh = False
if n[i] == 0 and hh == True:
c += 1
n[i] = 3
q = len(n) - 1
if nn == False:
i -= 1
i += 1
i = 0
z = 0
while z != c and i <= len(n) - 1 and mmm == False:
if n[i] == 3:
n.pop(i)
i -= 1
z += 1
i += 1
if c > 0 and mmm == False:
for i in range(c):
_javob_.append(0)
if v > 0:
for i in range(v):
_javob_.append(1)
if mmm == False:
_javob_ = _javob_ + n
else:
for ll in range(xxx):
_javob_.append(1)
_javob_.append(2)
for j in range(len(_javob_)):
print(_javob_[j], end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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
|
import sys
input = sys.stdin.readline
s = input()[:-1]
one = 0
ans = []
for i in range(len(s)):
if s[i] == "1":
one += 1
else:
ans.append(s[i])
ans2 = []
for i in range(len(ans)):
if ans[i] == "2":
for _ in range(one):
ans2.append("1")
for j in range(i, len(ans)):
ans2.append(ans[j])
break
else:
ans2.append(ans[i])
else:
for _ in range(one):
ans2.append("1")
print("".join(ans2))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR 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
|
import sys
def input():
return sys.stdin.readline().strip()
s = input()
freq = {"0": 0, "1": 0}
i = 0
while i < len(s):
if s[i] == "2":
break
else:
freq[s[i]] += 1
i += 1
suf_s = ""
while i < len(s):
if s[i] == "1":
freq[s[i]] += 1
else:
suf_s += s[i]
i += 1
pre_s = "0" * freq["0"] + "1" * freq["1"]
print(pre_s + suf_s)
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING VAR STRING 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 = list(input())
ans = [[], [], []]
for c in s:
if c == "1":
ans[1].append("1")
elif 0 < len(ans[2]) or c == "2":
ans[2].append(c)
else:
ans[0].append(c)
print("".join(map(lambda ls: "".join(ls), ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST LIST LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER STRING IF NUMBER FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL 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
|
TN = 1
def solution():
s = list(input())
n = len(s)
ed = 0
ans = ""
for i in range(n):
if s[i] != "1":
ans += s[i]
else:
ed += 1
k = (ans + "2").index("2")
print(ans[:k] + "1" * ed + ans[k:])
while TN != 0:
solution()
TN -= 1
|
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL BIN_OP VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL 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
|
import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(" "))
def solve():
a = list(input().replace("\n", ""))
delete_ones = []
count_ones = 0
for a_i in a:
if a_i == "1":
count_ones += 1
else:
delete_ones.append(a_i)
ans = []
for elem in delete_ones:
if elem == "2" and count_ones:
ans.append("1" * count_ones)
count_ones = 0
ans.append(elem)
if count_ones:
ans.append("1" * count_ones)
count_ones = 0
print("".join(ans))
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER 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
|
s = input()
n = len(s)
a = 0
b = 0
for i in range(n):
if s[i] == "1":
b += 1
st = 0
res = ""
for i in range(n):
if s[i] == "2":
for i in range(a):
res += "0"
for i in range(b):
res += "1"
res += "2"
a = 0
b = 0
elif s[i] == "0":
a += 1
for i in range(a):
res += "0"
for i in range(b):
res += "1"
print(res)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER 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
|
si = input()
so = ""
ones = 0
for i in range(len(si)):
if si[i] == "1":
ones = ones + 1
i = 0
twos_found = False
for i in range(len(si)):
if si[i] == "2" and not twos_found:
twos_found = True
if ones > 0:
so = so + "1" * ones
if si[i] == "0" or si[i] == "2":
so = so + si[i]
if ones > 0 and not twos_found:
so = so + "1" * ones
print(so)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER 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
|
from sys import stdin
line = stdin.readline().rstrip()
count0 = 0
count1 = 0
index = 0
found2 = False
for c in line:
index += 1
if c == "0":
count0 += 1
if c == "2":
found2 = True
break
while count0 > 0:
count0 -= 1
print("0", end="")
for c in line:
if c == "1":
print("1", end="")
if found2:
print("2", end="")
for i in range(index, len(line)):
if line[i] != "1":
print(line[i], end="")
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING STRING IF 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
|
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 moveTwos(lst):
totalTwos = 0
for index, ele in enumerate(lst):
if ele == 2:
totalTwos += 1
if ele == 1:
lst[index - totalTwos], lst[index] = lst[index], lst[index - totalTwos]
if ele == 0:
totalTwos = 0
return lst
def moveOnes(lst):
totalOnes = 0
for index, ele in enumerate(lst):
if ele == 1:
totalOnes += 1
if ele == 0:
lst[index - totalOnes], lst[index] = lst[index], lst[index - totalOnes]
if ele == 2:
totalOnes = 0
return lst
def moveOnesLeft(lst):
totalOnes = 0
for index in range(len(lst) - 1, -1, -1):
ele = lst[index]
if ele == 1:
totalOnes += 1
else:
lst[index + totalOnes], lst[index] = lst[index], lst[index + totalOnes]
return lst
def main():
inp = [int(i) for i in str(input())]
ans = moveOnes(moveTwos(moveOnesLeft(inp)))
for i in ans:
print(i, end="")
main()
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL 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
|
def trocaElemento(ternary, biggerElemIndex, smallerElemIndex):
temp = ternary[smallerElemIndex]
ternary[smallerElemIndex] = ternary[biggerElemIndex]
ternary[biggerElemIndex] = temp
return ternary
entrada = input()
ternary = list(entrada)
i = 0
one = 0
ans = ""
while i < len(ternary):
if ternary[i] == "0":
ans = ans + "0"
if ternary[i] == "1":
one = one + 1
if ternary[i] == "2":
ans = ans + "2"
i = i + 1
flag = False
i = 0
while i < len(ans):
if ans[i] == "2" and not flag:
flag = True
for x in range(one):
print("1", end="")
print(ans[i], end="")
i = i + 1
if not flag:
for x in range(one):
print("1", end="")
|
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR FOR VAR FUNC_CALL 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
|
s = input()
d = [0, 0]
i = 0
while i < len(s) and s[i] != "2":
d[int(s[i])] += 1
i += 1
a1 = 0
a2 = ""
while i < len(s):
if s[i] == "1":
a1 += 1
else:
a2 += s[i]
i += 1
print("0" * d[0] + "1" * d[1] + "1" * a1 + a2)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN 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 BIN_OP STRING VAR NUMBER BIN_OP STRING VAR NUMBER 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()
o, z, fpB, fp, sp = "", 0, True, "", ""
for x in s:
if fpB:
if x == "0":
fp += "0"
elif x == "1":
o += "1"
else:
sp += "2"
fpB = False
elif x != "1":
sp += x
else:
o += "1"
print(fp + o + sp)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR STRING NUMBER NUMBER STRING STRING FOR VAR VAR IF VAR IF VAR STRING VAR STRING IF VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR STRING VAR VAR 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()
res = ""
if s.count("2") > 0:
res = sorted(s[: s.index("2")])
res += ["1"] * (s.count("1") - res.count("1"))
lim = len(res)
res += s[s.index("2") :]
s = ""
for i in range(len(res)):
if i >= lim and res[i] == "1":
continue
s += res[i]
print(s)
else:
print("0" * s.count("0") + "1" * s.count("1"))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR BIN_OP LIST STRING BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING BIN_OP STRING 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
|
n = input()
n = list(n)
check_zero = True
check_two = True
sub = ["", "", ""]
for c in range(len(n)):
if n[c] == "0":
check_two = False
if check_zero:
n[c] = "X"
sub[0] = sub[0] + "0"
elif n[c] == "1":
n[c] = "X"
sub[1] = sub[1] + "1"
elif n[c] == "2":
check_zero = False
if check_two:
n[c] = "X"
sub[2] = sub[2] + "2"
output = "".join([i for i in sub]) + "".join([j for j in n if j != "X"])
print(output)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL STRING VAR VAR VAR FUNC_CALL STRING VAR 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
|
def solve(s):
count = 0
c = 0
while c < len(s):
if s[c] == "1":
count += 1
del s[c]
else:
c += 1
i = -1
if "2" in s:
i = s.index("2")
ones = ""
for x in range(0, count):
ones += "1"
ans = ""
if i >= 0:
ans = "".join(s[0:i]) + ones[:] + "".join(s[i:])
else:
ans = "".join(s[:]) + ones[:]
return ans
def main():
s = list(input())
ans = solve(s)
print(ans)
main()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL STRING VAR NUMBER VAR VAR FUNC_CALL STRING VAR VAR ASSIGN VAR BIN_OP FUNC_CALL STRING VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR 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
|
s = input()
temp = None
paste = None
zero, one = 0, 0
for i in range(len(s)):
if s[i] == "2":
temp = s[i:]
break
elif s[i] == "1":
one += 1
elif s[i] == "0":
zero += 1
if temp is not None:
for x in temp:
if x == "1":
one += 1
paste = temp.replace("1", "")
ans = "0" * zero + "1" * one
if paste is not None:
ans += paste
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NONE FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NONE 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())
k = min([i for i in range(len(s)) if s[i] == "2"] + [len(s)])
z = len([c for c in s[:k] if c == "0"])
n = len([c for c in s if c == "1"])
print("0" * z + "1" * n + "".join(c for c in s[k:] if c != "1"))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING LIST FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR FUNC_CALL STRING VAR VAR 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
|
import sys
def input():
return sys.stdin.readline().strip()
s = input()
freq = {"0": 0, "1": 0}
i = 0
while i < len(s):
if s[i] == "2":
break
else:
freq[s[i]] += 1
i += 1
s = list(s[i:])
suf_s = ""
for i in s:
if i == "1":
freq[i] += 1
else:
suf_s += i
pre_s = ""
for i in range(freq["0"]):
pre_s += "0"
for i in range(freq["1"]):
pre_s += "1"
print(pre_s + suf_s)
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR NUMBER VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR STRING VAR STRING FOR VAR FUNC_CALL VAR VAR STRING VAR STRING 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
|
def countc(s, c):
k = 0
for x in s:
if x == c:
k += 1
return k
s = input()
n = len(s)
k = countc(s, "1")
if "0" not in s:
s1 = "1" * k + "2" * (n - k)
elif "2" not in s:
s1 = "0" * (n - k) + "1" * k
else:
c = 0
for i in range(n):
if s[i] == "0":
c += 1
elif s[i] == "2":
break
s1 = "0" * c + "1" * k
for j in range(i, n):
if s[j] != "1":
s1 += s[j]
print(s1)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING IF STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR IF STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR 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
|
s = [i for i in input()]
n = len(s)
c = 0
p = 1 << 64
ans = ""
for i in range(n):
if s[i] == "1":
c += 1
else:
ans += s[i]
for i in range(len(ans)):
if ans[i] == "2":
p = min(p, i)
if p == 1 << 64:
ans += c * "1"
print(ans)
else:
s1 = ans[0:p]
s2 = ans[p:]
print(s1 + "1" * c + s2)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP 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
|
instr = input()
one_count = 0
first_2 = -1
pref2 = ""
postf2 = ""
for i in range(len(instr)):
if instr[i] == "0":
pref2 += "0"
elif instr[i] == "1":
one_count += 1
else:
first_2 = i
break
if first_2 != -1:
for i in range(first_2 + 1, len(instr)):
if instr[i] == "0":
postf2 += "0"
elif instr[i] == "1":
one_count += 1
else:
postf2 += "2"
if first_2 != -1:
outstr = pref2 + "1" * one_count + "2" + postf2
else:
outstr = pref2 + "1" * one_count
print(outstr)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP STRING VAR STRING 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
|
a = input()
if "2" in a:
b = a.split("2")
one = a.count("1")
ze = a.count("0")
k = ""
for i in b[1:]:
k += "2"
l = i.count("0")
k += "0" * l
ze -= l
print("0" * ze + "1" * one + k)
else:
print("".join(sorted(a)))
|
ASSIGN VAR FUNC_CALL VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR STRING VAR BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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
|
str = input()
new1 = ""
new3 = ""
count = 0
state = 1
for char in str:
if char == "1":
count += 1
else:
if char == "2" and state == 1:
state = 2
if state == 1:
new1 += char
else:
new3 += char
new2 = "1" * count
new = new1 + new2 + new3
print(new)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP 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
|
s = input()
num0 = []
cnt0 = 0
num1 = 0
for i in range(len(s)):
if s[i] == "0":
cnt0 += 1
elif s[i] == "1":
num1 += 1
else:
num0.append(cnt0)
cnt0 = 0
num0.append(cnt0)
print("0" * num0[0], end="")
print("1" * num1, end="")
for i in num0[1:]:
print("2", end="")
print("0" * i, end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST 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 VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING FOR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP 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()
l = len(s)
i = 0
while i < l and s[i] != "2":
i += 1
a = sorted(s[0:i])
fir = []
sec = []
while i < l:
if s[i] == "1":
fir += [s[i]]
else:
sec += [s[i]]
i += 1
r = a + fir + sec
print("".join(r))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR STRING VAR LIST VAR VAR VAR LIST VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP 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
|
a = [0, 0, 0, 0]
s = input()
n = len(s)
k = n
i = n - 1
answer = []
while i >= 0:
if s[i] == "0":
a[0] += 1
if s[i] == "2":
k = i
a[2] += 1
if s[i] == "1":
a[1] += 1
i -= 1
i = 0
while i < k:
if s[i] == "0":
answer.append("0")
i += 1
i = 0
while i < a[1]:
answer.append("1")
i += 1
i = k
while i < n:
if s[i] != "1":
answer.append(s[i])
i += 1
string = ""
for a in answer:
string += str(a)
print(string)
|
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR 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
|
n = list(input())
def sw(w):
ones = w.count("1")
a = list(filter(lambda x: x != "1", w))
if "2" in a:
i = a.index("2")
print("".join(a[:i]) + "1" * ones + "".join(a[i:]))
else:
print("".join(a) + "1" * ones)
sw(n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING VAR VAR BIN_OP STRING VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL 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
|
N = list(input())
N = [int(i) for i in N]
n = len(N)
two = n + 1
for i in range(n):
if N[i] == 2:
two = i
break
N2 = ""
ones = 0
zeros = 0
for i in range(n - 1, -1, -1):
if two <= i:
if N[i] == 0:
N2 = "0" + N2
elif N[i] == 2:
N2 = "2" + N2
else:
ones += 1
elif N[i] == 0:
zeros += 1
else:
ones += 1
print(zeros * "0" + ones * "1" + N2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR STRING BIN_OP VAR 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 main():
s = input()
zerotwo = "".join([c for c in s if c != "1"])
ones = "1" * (len(s) - len(zerotwo))
i = 0
while i < len(zerotwo) and zerotwo[i] == "0":
i += 1
print(zerotwo[0:i] + ones + zerotwo[i:])
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR 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 VAR NUMBER VAR VAR 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
|
s = input()
s1 = []
s2 = []
s3 = []
f = 0
for i in range(0, len(s)):
if s[i] == "1":
s2.append("1")
else:
if s[i] == "2":
f = 1
if f == 1:
s3.append(s[i])
else:
s1.append(s[i])
print("".join(s1 + s2 + s3))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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()
m = s.count("1")
lis = []
for i in s:
if i == "1":
continue
lis.append(i)
ans = "".join(lis)
k = ans.find("2")
if k == -1:
k = len(ans)
print(ans[:k] + "1" * m + ans[k:])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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
|
s, t, k = input(), "", 0
for i in s:
if i != "1":
t += i
else:
k += 1
i = t.index("2") if "2" in t else len(t)
print(t[:i] + "1" * k + t[i:])
|
ASSIGN VAR VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR VAR IF VAR STRING VAR VAR VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR STRING FUNC_CALL VAR 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
|
strArr = list(input())
pos = -1
for i in range(len(strArr)):
pos = i
if strArr[i] == "2":
break
if pos == len(strArr) - 1 and strArr[pos] != "2":
pos = len(strArr)
ans = ""
if pos != -1:
for i in range(0, pos):
if strArr[i] == "0":
ans += str(strArr[i])
for i in range(len(strArr)):
if strArr[i] == "1":
ans += str(strArr[i])
for i in range(pos, len(strArr)):
if strArr[i] != "1":
ans += str(strArr[i])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL 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
|
lis = list(input())
o = z = i = 0
ans = ""
n = len(lis)
while i < n and lis[i] != "2":
if lis[i] == "0":
z += 1
else:
o += 1
i += 1
ans = "0" * z + "1" * o
o = z = t = 0
ans += "1" * lis[i:].count("1")
while i < n:
while i < n and lis[i] == "2":
t += 1
i += 1
while i < n and lis[i] != "2":
if lis[i] == "0":
z += 1
i += 1
ans += "2" * t + "0" * z
t = z = 0
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP STRING FUNC_CALL VAR VAR STRING WHILE VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR BIN_OP 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
|
s = input()
tot_zeroes = 0
cnt_ones = 0
cnt_two = 0
s1 = []
for i in s:
if i == "0":
tot_zeroes += 1
if i == "1":
cnt_ones += 1
if i == "2":
cnt_two += 1
idx = len(s) + 1
for i in range(len(s)):
if s[i] == "2":
idx = i
break
for k in range(idx, len(s)):
if s[k] != "1":
s1.append(s[k])
cnt = 0
for j in range(i + 1, len(s)):
if s[j] == "0":
cnt += 1
starting_zeroes = tot_zeroes - cnt
new_s = []
for j in range(starting_zeroes):
new_s.append("0")
for j in range(cnt_ones):
new_s.append("1")
for j in s1:
new_s.append(j)
for j in new_s:
print(j, end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR 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
|
word = input()
count_ones = 0
cur_word = ""
for c in word:
if int(c) == 1:
count_ones += 1
if int(c) != 1:
cur_word = cur_word + c
res = ""
found = 0
for c in cur_word:
if int(c) == 2 and found == 0:
found = 1
for i in range(count_ones):
res += "1"
res += "2"
else:
res += c
if found == 0:
for i in range(count_ones):
res += "1"
print(res)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING VAR STRING VAR VAR IF VAR NUMBER 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
|
def main():
a = [int(x) for x in list(input().strip())]
aux = [0] * 3
ans = []
aux[int(a[0])] = 1
prev = 0
temp = 0
for i in range(len(a) - 1):
aux[int(a[i + 1])] = 1
if abs(a[i] - a[i + 1]) > 1 or sum(aux) > 2:
temp = a[prev : i + 1]
prev = i + 1
temp.sort()
ans += temp
aux = [0] * 3
aux[int(a[i + 1])] = 1
ans += sorted(a[prev:])
if 2 in a and 1 in a:
st = ans.index(2)
et = ans[st + 1 :].count(1)
ans = ans[:st] + [1] * et + [kk for kk in ans[st:] if kk != 1]
print("".join(str(x) for x in ans))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR IF NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP LIST NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR 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
|
s = input()
count1 = s.count("1")
string02 = s.replace("1", "")
index1 = string02.find("2")
if not index1 == -1:
answer = string02[:index1] + "1" * count1 + string02[index1:]
else:
answer = string02 + "1" * count1
print(answer)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER 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
|
s = input()
one = s.count("1")
ans = str()
pos = -1
n = len(s)
for i in range(n):
if s[i] == "2":
pos = i
break
if pos == -1:
print("".join(sorted(s)))
else:
k = s[:pos]
zero = k.count("0")
ans = str()
ans = "0" * zero + "1" * one + s[pos:]
flag = False
for i in ans:
if flag and i == "1":
continue
if i == "2":
flag = True
print(i, end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR STRING IF VAR STRING ASSIGN VAR NUMBER 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()
x = S.count("1")
T = S.replace("1", "")
if "2" in T:
ans = T[: T.index("2")] + "1" * x + T[T.index("2") :]
else:
ans = T + "1" * x
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING IF STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING BIN_OP STRING VAR VAR FUNC_CALL VAR STRING 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
|
s = input()
one = len(list(filter(lambda x: x == "1", s)))
for elem in s:
if elem == "2":
if one != 0:
print(one * "1", end="")
one = 0
print(elem, end="")
if elem == "0":
print(elem, end="")
if one != 0:
print(one * "1")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR FOR VAR VAR IF VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL 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()
ones = s.count("1")
s_tmp = s.split("2")
s_out = s_tmp[0].count("0") * "0" + ones * "1"
for pocket in s_tmp[1:]:
s_out += "2" + pocket.count("0") * "0"
print(s_out)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING STRING BIN_OP VAR STRING FOR VAR VAR NUMBER VAR BIN_OP 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
|
x = input()
c = x.count("1")
x = x.replace("1", "")
z = x.find("2")
if z != -1:
x = x[0 : int(z)] + "1" * c + x[int(z) :]
print(x)
else:
print(x + "1" * c)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP STRING VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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
|
m = input()
m = list(m)
output = []
for i in range(len(m)):
if m[i] == "2":
break
if m[i] == "0":
output.append("0")
m[i] = "X"
for i in range(len(m)):
if m[i] == "1":
output.append("1")
m[i] = "X"
for i in range(len(m)):
if m[i] == "0":
break
if m[i] == "2":
output.append("2")
m[i] = "X"
m = list(filter("X".__ne__, m))
print("".join(output + m))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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
|
from sys import stdin
line = stdin.readline().rstrip()
string1 = "1" * line.count("1")
line = line.replace("1", "")
pos = line.find("2")
if pos == -1:
print(line + string1)
else:
print(line[:pos] + string1 + line[pos:])
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING 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()
tmp = ""
s = s[::-1]
xx = z = it = 0
for c in s:
if c == "2":
tmp = tmp + "0" * z + "2"
z = 0
if c == "0":
z += 1
if c == "1":
xx += 1
it = it + 1
tmp = tmp + "1" * xx + "0" * z
print(tmp[::-1])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP STRING VAR STRING ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL 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
|
s = input()
ones = 0
ans = ""
for i in range(len(s)):
if s[i] == "1":
ones += 1
else:
ans += s[i]
for i in range(len(ans)):
if ans[i] == "2":
ans = ans[:i] + "1" * ones + ans[i:]
break
if len(ans) != len(s):
ans += "1" * ones
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL 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()
n = len(s)
ans = []
cnt1 = 0
for i in range(n):
if s[i] != "1":
ans.append(s[i])
else:
cnt1 += 1
ans.append("9")
for i, char in enumerate(ans):
if char != "0":
res = ans[0:i] + ["1"] * cnt1 + ans[i:]
break
print("".join(map(str, res))[0:n])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING 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 NUMBER 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
|
from sys import stdin, stdout
def rint():
return map(int, stdin.readline().split())
s = input()
cnt = 0
for i in range(len(s)):
if s[i] == "1":
cnt += 1
ans = ""
found = False
for i in range(len(s)):
if s[i] == "0":
ans += "0"
continue
if s[i] == "1":
pass
if s[i] == "2":
if found == False:
ans += "1" * cnt
found = True
ans += "2"
if found == False:
ans += "1" * cnt
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER 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 IF VAR VAR STRING IF VAR NUMBER VAR BIN_OP STRING VAR ASSIGN VAR NUMBER VAR STRING 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
|
def swap(ls, index1, index2):
aux = ls[index1]
ls[index1] = ls[index2]
ls[index2] = aux
return
def main():
ori = input()
if ori == "" or len(ori) > 100000:
return
ori = list(ori)
n = len(ori)
i = 0
while i != n:
if ori[i] == "2":
break
i += 1
bl = []
al = []
cl = []
for j in range(i):
if ori[j] == "0":
al.append("0")
elif ori[j] == "1":
bl.append("1")
for j in range(i, n):
if ori[j] == "1":
bl.append("1")
else:
cl.append(ori[j])
for i in range(len(al)):
print(al[i], end="")
for i in range(len(bl)):
print(bl[i], end="")
for i in range(len(cl)):
print(cl[i], end="")
print()
return
main()
|
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR STRING FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR RETURN 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()
q = s.index("2") if "2" in s else len(s)
w = s.count("1")
e = s[:q].count("0")
a = "0" * e + "1" * w
for i in s[q:]:
if i != "1":
a += i
print(a)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR FOR VAR VAR VAR IF 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
|
a = input()
b = a.count("1")
c = 0
j = len(a)
for i in range(len(a)):
if a[i] == "0":
c = c + 1
if a[i] == "2":
j = i
break
d = []
for i in range(j, len(a)):
if a[i] != "1":
d.append(a[i])
print("0" * c + "1" * b + "".join(d))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING 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
|
t = input()
n = len(t)
count0 = 0
count1 = 0
count2 = 0
flag, i = 0, 0
for i in range(n):
if t[i] == "1":
count1 += 1
for i in range(n):
if t[i] == "0":
count0 += 1
if t[i] == "2":
flag = 1
break
for j in range(count0):
print("0", end="")
for j in range(count1):
print("1", end="")
if flag == 1:
for k in range(i, n):
if t[k] == "2":
print(t[k], end="")
if t[k] == "0":
print(t[k], end="")
k += 1
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING IF VAR VAR 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()
n = len(s)
onec = s.count("1")
zeroc = s.count("0")
twoc = s.count("2")
karma = 0
if "2" in s:
karma = 0
else:
karma = 1
if karma:
print("0" * zeroc + "1" * onec)
else:
s = list(s)
s = [i for i in s if i != "1"]
twoind = s.index("2")
s = s[0:twoind] + ["1"] * onec + s[twoind:]
print(*s, sep="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR 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 IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP LIST STRING VAR 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 = [i for i in input()]
s.reverse()
ans = ""
c0, c1 = 0, 0
for i in s:
if i == "2":
ans += c0 * "0"
ans += "2"
c0 = 0
elif i == "0":
c0 += 1
else:
c1 += 1
ans += c1 * "1"
ans += c0 * "0"
for i in range(len(s) - 1, -1, -1):
print(ans[i], end="")
|
ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR BIN_OP VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER VAR BIN_OP VAR STRING VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER 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()
comeco0 = ""
comeco1 = ""
final = ""
achei2 = False
for num in s:
if num == "0":
if achei2 == False:
comeco0 += "0"
else:
final += "0"
if num == "1":
comeco1 += "1"
if num == "2":
achei2 = True
final += "2"
print(comeco0, end="")
print(comeco1, end="")
print(final, end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR NUMBER VAR STRING VAR STRING IF VAR STRING VAR STRING IF VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING 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
|
n = list(input())
if set(n) == {1, 2} or set(n) == {0, 1}:
n.sort()
print("".join(n))
else:
count = n.count("1")
l = ["1"] * count
for i in range(len(n)):
if n[i] != "1":
l.append(n[i])
count2 = 0
for i in range(count, len(n)):
if l[i] == "0":
count2 += 1
else:
break
final = ["0"] * count2 + ["1"] * count
for i in range(count + count2, len(n)):
final.append(l[i])
print("".join(final))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR 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()
b = list(s)
d = []
count_of_1 = 0
first_index_of_2 = None
for ix, c in enumerate(b):
if c == "1":
count_of_1 += 1
else:
d.append(c)
if c == "2" and first_index_of_2 is None:
first_index_of_2 = len(d) - 1
ans = (
d[:first_index_of_2]
+ ["1"] * count_of_1
+ (d[first_index_of_2:] if first_index_of_2 is not None else [])
)
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP LIST STRING VAR VAR NONE VAR VAR LIST 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()
a = s.count("1")
l = []
for i in s:
if i != "1":
l.append(i)
b = ["1"] * a
c = len(l)
for i in range(len(l)):
if l[i] == "2":
c = i
break
ans = l[0:c] + b + l[c : len(l)]
for i in ans:
print(str(i), end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR 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()
b = ""
i0 = 0
i1 = 0
i2 = 0
tmpi0 = 0
c = []
flag = False
for i in range(len(a)):
if a[i] == "1":
i1 += 1
elif i0 != 0 and a[i] == "2":
b += "0" * i0
i0 = 0
elif i2 != 0 and a[i] == "0":
b += "2" * i2
i2 = 0
if a[i] == "2":
i2 += 1
if a[i] == "0":
i0 += 1
b += "0" * i0 + "2" * i2
flag = True
for i in range(len(b)):
if flag and b[i] == "2":
flag = False
print("1" * i1 + "2", end="")
i1 = 0
else:
print(b[i], end="")
print("1" * i1, end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR STRING VAR BIN_OP STRING VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR STRING VAR BIN_OP STRING VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP 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
|
l = list(input()) + ["2"]
i = 0
l = sorted(l[: l.index("2")]) + l[l.index("2") :]
ones = l.count("1")
zeros = l[: l.index("2")].count("0")
s = ["0"] * zeros + ["1"] * ones + list("".join(l[l.index("2") :]).replace("1", ""))
print("".join(s[:-1]))
|
ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL STRING VAR FUNC_CALL VAR STRING STRING STRING EXPR FUNC_CALL VAR FUNC_CALL 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
|
arr = input()
arr = list(arr)
n = len(arr)
zeros_after = 0
ones_after = 0
i = 0
while i < n:
if arr[i] == "2":
break
i += 1
x = i
while i < n:
if arr[i] == "0":
zeros_after += 1
elif arr[i] == "1":
ones_after += 1
i += 1
first = arr[0:x]
first.sort()
for i in range(x, n):
if arr[i] == "1":
arr[i] = "3"
ans = []
for i in arr:
if i != "3":
ans.append(i)
for i in range(ones_after):
first.append("1")
print("".join(first + ans[x:]))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.