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_{...
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_...
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_{...
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 c...
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_O...
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_{...
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 e...
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: actu...
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 ...
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 e...
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 e...
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.qt...
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 VA...
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 e...
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 e...
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)): ...
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...
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 e...
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 e...
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 e...
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...
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 NUMBE...
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 e...
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 += ...
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 S...
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 e...
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.so...
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 E...
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 e...
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 FU...
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 e...
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...
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 e...
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="") pri...
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...
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 e...
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 VA...
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 e...
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 = ...
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 E...
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 e...
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 + noO...
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 ...
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 e...
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, "...
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_O...
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 e...
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 VA...
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 e...
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="") ...
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 VA...
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 e...
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(...
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_C...
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 e...
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 e...
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 e...
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(...
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 ...
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 e...
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 e...
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(n...
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 ...
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 e...
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 e...
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 e...
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 :]) ...
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 FU...
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 e...
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) prin...
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...
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 e...
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"] *...
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 STRI...
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 e...
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...
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 ...
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 e...
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...
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 FU...
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 e...
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 e...
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"): ...
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_...
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 e...
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...
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 NUM...
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 e...
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))...
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 FU...
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 e...
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 +=...
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 ASSI...
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 e...
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 e...
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...
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 e...
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 =...
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 ...
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 e...
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": ...
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...
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 e...
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 = ...
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...
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 e...
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": ...
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 F...
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 e...
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): total...
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 VA...
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 e...
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]...
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 VA...
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 e...
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_...
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 e...
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 e...
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: ...
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 V...
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 e...
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":...
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 ASSIG...
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 e...
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 = ...
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...
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 e...
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("...
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 ...
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 e...
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 FU...
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 e...
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 =...
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...
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 e...
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 +=...
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 ...
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 e...
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(s...
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 ...
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 e...
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...
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 VA...
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 e...
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 EX...
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 e...
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(ne...
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 e...
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(...
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 STRI...
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 e...
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 FUN...
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 e...
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]: ...
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 ...
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 e...
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 STR...
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 e...
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: ...
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 V...
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 e...
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 e...
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 STRIN...
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 e...
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 e...
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 e...
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...
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 VA...
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 e...
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 ...
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...
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 e...
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...
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 ...
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 e...
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 += ...
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 V...
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 e...
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 ...
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 ...
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 e...
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 e...
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: ...
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 FU...
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 e...
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 e...
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 e...
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 e...
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 e...
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] ...
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 VA...
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 e...
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 e...
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_O...
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 e...
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 ...
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 e...
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...
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 e...
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]...
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 NU...
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 e...
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...
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 L...
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 e...
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 e...
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...
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 e...
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...
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_C...
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 e...
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:] ...
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 ASSI...
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 e...
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 NUM...
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 e...
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="") pr...
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 e...
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 +...
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 ASSI...
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 e...
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 ...
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...
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 e...
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 ...
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 e...
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] ...
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 ...
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 e...
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_C...
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 e...
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): ...
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 V...