description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input().split("*") ans = -1 for i in range(len(s)): for j in range(0, len(s)): ans = max( ans, eval( "*".join( s[:i] + [str(eval("*".join(s[i : i + j + 1])))] + s[i + j + 1 :] ) ), ) print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() mult_list = [] for i in range(len(s)): if s[i] == "*": mult_list.append(i) best = eval(s) for k in mult_list: t = "(" + s[:k] + ")" + s[k:] q = eval(t) if q > best: best = q t = s[: k + 1] + "(" + s[k + 1 :] + ")" q = eval(t) if q > best: best = q for ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
str = "1*" + input() + "*1" l = len(str) ans = 0 for i in range(2, l, 2): if str[i - 1] == "*": for j in range(i + 1, l, 2): if str[j] == "*": ans = max(ans, eval(str[:i] + "(" + str[i:j] + ")" + str[j:])) print(ans)
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() s = "1*" + s + "*1" IL = [] for i in range(len(s)): if s[i] == "*": IL.append(i) maks = 0 for i in range(len(IL)): for j in range(i + 1, len(IL)): a = eval(s[: IL[i] + 1] + "(" + s[IL[i] + 1 : IL[j]] + ")" + s[IL[j] :]) maks = max(maks, a) print(maks)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
src_str = input() lenstr = len(src_str) str = list(src_str) listMulPos = [] for i, c in enumerate(str): if c == "*": listMulPos.append(i) listLeftParPos = [0] for i in listMulPos: listLeftParPos.append(i + 1) listRightParPos = [lenstr] for i in listMulPos: listRightParPos.append(i) ans = 0 for leftP...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR V...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() mx = eval(s) m = [-1] + [i for i, v in enumerate(s) if v == "*"] + [len(s)] for i, a in enumerate(m): for b in m[i + 1 :]: t = s[: a + 1] + "(" + s[a + 1 : b] + ")" + s[b:] mx = max(mx, eval(t)) print(mx)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR STRING LIST FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = "1*" + input() + "*1" mx = 0 v = [] for i in range(len(s)): if s[i] == "*": v.append(i) for i in range(len(v)): for j in range(i + 1, len(v)): z = eval(s[v[i] + 1 : v[j]]) mx = max(mx, eval(s[: v[i] + 1] + str(z) + s[v[j] :])) print(mx)
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
expr = list(input()) mul_pos = [-1] add_cnt = [0] * len(expr) for i, _ in enumerate(expr): add_cnt[i] = add_cnt[i - 1] if _ == "*": mul_pos.append(i) elif _ == "+": add_cnt[i] += 1 mul_pos.append(len(expr)) add_cnt.append(add_cnt[-1]) add_cnt.append(0) ans = 0 for i in range(len(mul_pos)): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() s = "0+1*" + s + "*1+0" answer = eval(s) n = len(s) p = [] for i in range(0, n): if s[i] == "*": p.append(i) for i in p: for j in p: if i >= j: continue test = eval(s[: i + 1] + "(" + s[i + 1 : j] + ")" + s[j:]) if test > answer: answer = test ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR N...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
__author__ = "artbataev" def countExpression(i, j): global matr, numbers, operations if i == 0 or operations[i - 1] == "+": return matr[j] - (0 if i == 0 else matr[i - 1]) cur = numbers[i] k = i while k < j and operations[k] == "*": cur *= numbers[k + 1] k += 1 if k >= ...
ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING RETURN BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() processed = True i1 = 1 while i1 < len(s): while i1 < len(s): if s[i1] == "+": break i1 += 2 if i1 >= len(s): break i2 = i1 + 2 while i2 < len(s): if s[i2] == "*": break i2 += 2 i2 = i2 - 2 if i2 - i1 > 2: s1 = e...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VA...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
from itertools import combinations s = str(input()) ans = eval(s) op = [-1] + [i for i, d in enumerate(s) if d == "*"] + [len(s)] for i, j in combinations(op, 2): ans = max(ans, eval("{}({}){}".format(s[: i + 1], s[i + 1 : j], s[j:]))) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR STRING LIST FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VA...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() length = len(s) ans = eval(s) for j in range(0, length, 2): if j == 0 or s[j - 1] == "*": for k in range(j + 3, length + 1, 2): if k == length or s[k] == "*": tmp = eval(s[:j] + str(eval(s[j:k])) + s[k:]) ans = ans if tmp < ans else tmp print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR FU...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
S = "1*" + input() + "*1" n = len(S) ans = eval(S) for i in range(2, n + 1, 2): if S[i - 1] == "*": for j in range(i + 1, n, 2): if S[j] == "*": T = S[0:i] + "(" + S[i:j] + ")" + S[j:] ans = max(ans, eval(T)) print(ans)
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() d = list(s.split("*")) last = 0 po = [] ki = [] for i in range(len(d)): po += [last] ki += [len(d[i]) + last] last += len(d[i]) + 1 ans = [eval(s)] for a in po: for b in ki: if a > b - 2: continue x = s[:a] + "(" + s[a:b] + ")" + s[b:] ans += [eval(x)] pri...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR LIST VAR VAR LIST BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
import sys def f2(exp: str, index1: int, index2: int): return eval(exp[:index1] + "(" + exp[index1 : index2 + 1] + ")" + exp[index2 + 1 :]) def f1(exp: str): res, pos = eval(exp), [-1] for i in range(1, len(exp), 2): if exp[i] == "*": pos.append(i) pos.append(len(exp)) for i ...
IMPORT FUNC_DEF VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER FUNC_DEF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR F...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
S = input() N = len(S) Ans = eval(S) for i in range(0, N, 2): for j in range(i, N, 2): if (i == 0 or i > 0 and S[i - 1] == "*") and ( j == N - 1 or j < N - 1 and S[j + 1] == "*" ): SS = S[:i] + str(eval(S[i : j + 1])) + S[j + 1 :] if int(eval(SS)) > Ans: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() if len(s) == 1: print(s) else: ans = eval(s) l = [] for i in range(len(s)): if s[i] == "*": l += [i] if len(l) == 0: print(ans) else: l = [-1] + l l = l + [len(s)] for i in range(len(l)): for j in range(i + 1, len(l)): ...
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR LIST VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR LIST FUNC_CALL VAR VA...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = "1*" + input() + "*1" a = "" n = len(s) s = s + "+" i = 0 while i < n: if s[i + 1] == "*": while s[i + 1] == "*": a += s[i : i + 2] i += 2 a += s[i : i + 2] i += 2 else: sum = 0 while i < n and s[i + 1] == "+": sum += int(s[i]) ...
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER STRING WHILE VAR BIN_OP VAR NUMBER STRING VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
str = "1*" + input() + "*1" n = len(str) max_z = eval(str) arr = [] for i in range(1, n, 2): if str[i] == "*": arr.append(i) for i in range(len(arr)): s1 = str[: arr[i] + 1] + "(" + str[arr[i] + 1 :] for j in range(i + 1, len(arr)): s2 = s1[: arr[j] + 1] + ")" + s1[arr[j] + 1 :] max_...
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER STRING VAR BIN_OP VAR...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
expr = input() ans = eval(expr) factor = expr.split("*") for i in range(1, len(factor)): ans = max(ans, eval("(" + "*".join(factor[0:i]) + ")*" + "*".join(factor[i:]))) ans = max(ans, eval("*".join(factor[0:i]) + "*(" + "*".join(factor[i:]) + ")")) for j in range(i + 1, len(factor)): ans = max( ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL STRING VAR NUMBER VAR STRING FUNC_CALL STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BI...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() res = eval(s) n = len(s) for i in range(-1, n): if i == -1 or s[i] == "*": for j in range(i + 1, n + 1): if j == n or s[j] == "*": new_s = s[0 : i + 1] + "(" + s[i + 1 : j] + ")" + s[j:n] res = max(res, eval(new_s)) print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR N...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() pos = [-1] for i, x in enumerate(s): if x == "*": pos.append(i) pos.append(len(s)) max_v = 0 for i in range(len(pos) - 1): for j in range(i + 1, len(pos)): a = pos[i] + 1 b = pos[j] ns = s[:a] + "(" + s[a:b] + ")" + s[b:] e = eval(ns) if e > max_v: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIG...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() t = len(s) res = eval(s) for i in range(0, t): if i != 0 and s[i - 1] != "*": continue a = s[:i] + "(" + s[i:] for j in range(i, t + 2): if j != t + 1 and a[j] != "*": continue if j == t + 1: b = a[:j] + ")" else: b = a[:j] + ")...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR STRING IF VAR BIN_OP VAR NUMBER ASSI...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() ans = eval(s) n = len(s) pos = [i for i, x in enumerate(s) if x == "*"] for x in pos: s2 = f"({s[0:x]}){s[x:]}" ans = max(ans, eval(s2)) s2 = f"{s[:x + 1]}({s[x + 1:]})" ans = max(ans, eval(s2)) for y in pos: if y >= x: continue s2 = f"{s[:y + 1]}({s[y + 1:x]}...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR VAR ASSIGN VAR STRING VAR NUMBER VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VA...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
maxx = 0 x = [] s = input() maxx = max(maxx, eval(s)) for i in range(len(s)): if s[i] == "*": x.append(i) maxx = max(maxx, eval("(" + s[:i] + ")" + s[i:])) maxx = max(maxx, eval(s[: i + 1] + "(" + s[i + 1 :] + ")")) for f in range(len(x)): for g in range(f + 1, len(x)): i = x[f] ...
ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = "*" + input() + "*" n = len(s) ans = eval(s[1 : n - 1]) for i in range(n): if s[i] != "*": continue for j in range(i + 1, n): if s[j] != "*": continue r = s[1 : i + 1] + "(" + s[i + 1 : j] + ")" + s[j : n - 1] ans = max(ans, eval(r)) print(ans)
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
exp = input() if exp.count("+") == 0: print(eval(exp)) elif exp.count("*") == 0: print(eval(exp)) else: maximum = 0 exp = "1*" + exp + "*1" for index1 in range(0, len(exp)): value = 0 if exp[index1 : index1 + 1] == "*": for index2 in range(index1 + 1, len(exp)): ...
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRI...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() n = len(s) ans = eval(s) for i in range(0, n): for j in range(i + 1, n): if s[i] == "*" and s[j] == "*": e = s[0 : i + 1] + "(" + s[i + 1 : j] + ")" + s[j:] ans = max(ans, eval(e)) for i in range(0, n): if s[i] == "*": e = "(" + s[0:i] + ")" + s[i:] an...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR ASSIGN VAR ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = "1*" + input() + "*1" n = len(s) ans = eval(s) pos = [] for i in range(n): if s[i] == "*": pos.append(i) for i in [(x + 1) for x in pos]: for j in [x for x in pos]: if i < j: ans = max(ans, eval(s[:i] + "(" + s[i:j] + ")" + s[j:])) print(ans)
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
S = input() ans = 0 for ll in range(len(S)): if not (ll == 0 or S[ll - 1] == "*"): continue for rr in range(ll + 1, len(S) + 1, 1): if not (rr == len(S) or S[rr] == "*"): continue ans = max(ans, eval(S[:ll] + "(" + S[ll:rr] + ")" + S[rr:])) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() s = "m = max(m, " + s + ")" pu = [10] for a in range(len(s)): if s[a] == "*": pu += [a] pu += [len(s)] m = 0 exec(s) for i in range(len(pu)): for j in range(i + 1, len(pu)): exec(s[: pu[i] + 1] + "(" + s[pu[i] + 1 : pu[j]] + ")" + s[pu[j] :]) print(m)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR LIST VAR VAR LIST FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
def main(): s = input() n = len(s) ans = -(10**18) for i in range(1, n + 1, 2): for j in range(0, i, 2): if (j == 0 or s[j - 1] == "*") and (i == n or s[i] == "*"): ans = max(ans, eval(s[:j] + "(" + s[j:i] + ")" + s[i:])) print(ans) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP B...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() exec("ans = " + s) n = s.count("*") last_s = s for i in range(n + 1): for j in range(i + 1, n + 2): new_s = "" if i == 0: new_s += "(" k = 1 for elem in s: if elem == "*": if i == k: new_s += "*(" ...
ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR VAR VAR STRING IF V...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() ans = eval(s) for i in range(len(s) - 1): if s[i] == "*": k = "(" + s[0:i] + ")" + s[i : len(s)] t = eval(k) if t > ans: ans = t k = s[0 : i + 1] + "(" + s[i + 1 : len(s)] + ")" t = eval(k) if t > ans: ans = t for j in range...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR NUMBER VAR STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VA...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
qw = input() g = ["*"] s = [1] for i in range(len(qw)): if i % 2 == 0: s.append(int(qw[i])) else: g.append(qw[i]) c = 0 g.append("*") s.append(1) for i in range(len(g)): if g[i] == "*": for j in range(i + 1, len(g)): if g[j] == "*": a = 0 b...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF ...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
def mul2val(s): res = 1 for i in s.split("*"): res *= int(i) return res s = "1*" + input() + "*1" muls = s.split("+") vals = list(map(mul2val, muls)) lvals = list(map(mul2val, [(mul[:-2] if len(mul) > 1 else "0") for mul in muls])) rvals = list(map(mul2val, [(mul[2:] if len(mul) > 1 else "0") for ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR VAR ASSIG...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() lb, rb = [], [] n = len(s) lb.append(0) rb.append(n) for i in range(n): if s[i] == "*": lb.append(i + 1) rb.append(i) ans = 0 for l in lb: for r in rb: if l >= r: continue t = s[:l] + "(" + s[l:r] + ")" + s[r:] ans = max(ans, eval(t)) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
def find_best(s): best = eval(s) for i in range(0, len(s), 2): if i > 0 and s[i - 1] == "*" or i == 0: for j in range(i + 2, len(s), 2): if j < len(s) - 1 and s[j + 1] == "*" or j == len(s) - 1: sp = s[:i] + "(" + s[i : j + 1] + ")" + s[j + 1 :] ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIG...
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expressio...
s = input() mults = [-1] for i in range(len(s)): if s[i] == "*": mults.append(i) mults.append(len(s)) max = 0 for i in range(len(mults)): for j in range(i + 1, len(mults)): news = ( s[: mults[i] + 1] + "(" + s[mults[i] + 1 : mults[j]] + ")" + s[mults[j] :] ) v = eval(...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = list(input()) if n == 1: print(0) print(s[0]) exit() if k == 2: a, b = "A", "B" x, y = 0, 0 for i in range(n): item = s[i] if i % 2: if item == "A": x += 1 else: y += 1 elif item ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMB...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = list(input()) if k <= 2: f = lambda t: sum(int(t[i] != s[i]) for i in range(n)) x, y = "AB" * n, "BA" * n res_x, res_y = f(x), f(y) if res_x > res_y: print(res_y) print(y[:n]) else: print(res_x) print(x[:n]) exit() res = 0 for ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR V...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = [int(x) for x in input().split()] s = input() if k == 2: str1 = "AB" * n str2 = "BA" * n diff1 = 0 diff2 = 0 for i in range(n): if s[i] != str1[i]: diff1 += 1 else: diff2 += 1 if diff1 < diff2: print(diff1) print(str1[:n]) else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VA...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = input() l = [] ans = 0 if k == 2: s1 = [] s2 = [] for i in range(n): if i & 1: s1.append("A") s2.append("B") else: s2.append("A") s1.append("B") a1 = 0 a2 = 0 for i in range(n): if s[i] !...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN ...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
import sys input = sys.stdin.readline n, k = map(int, input().split()) s = list(input().rstrip()) al = list("abcdefghijklmnopqrstuvwxyz".upper())[:k] al = set(al) if k >= 3: cnt = 0 for i in range(1, n - 1): if s[i - 1] == s[i] == s[i + 1]: s[i] = list(al - {s[i - 1]})[0] cnt +=...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR B...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = [i for i in input()] d = {i: chr(65 + i) for i in range(k)} ct = 0 if k == 2: a1 = [] a2 = [] for i in range(n): a1.append(d[i % 2]) a2.append(d[(1 + i) % 2]) ct1 = 0 ct2 = 0 for i in range(n): if s[i] != a1[i]: ct1 += 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP ...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) if k == 2: ab, ba = "AB" * (n // 2) + "A" * (n % 2), "BA" * (n // 2) + "B" * (n % 2) ab_c, ba_c = 0, 0 old = input().strip() for i in range(n): ab_c += old[i] != ab[i] ba_c += old[i] != ba[i] if ab_c < ba_c: print(ab_c) print(ab) e...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VA...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = list(input()) if k > 2: c = set(ord("A") + i for i in range(26)) r = 0 for i in range(1, len(s)): if s[i - 1] == s[i]: r += 1 if i + 1 < n: s[i] = ( "A" if "A" not in {s[i - 1], s[i +...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBE...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().strip().split()) s = list(input()) options = [chr(ord("A") + i) for i in range(k)] ans = 0 if k == 2: ans1 = [("A" if i % 2 == 0 else "B") for i in range(n)] diff1 = 0 for i in range(n): if s[i] != ans1[i]: diff1 += 1 if diff1 < n - diff1: print(diff1)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER STRING STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = input() temp = [] for i in range(len(s)): temp.append(s[i]) ans = [] tans = [] for i in range(len(s)): ans.append(s[i]) tans.append(s[i]) if k == 2: c1 = 0 count = 0 for i in range(len(ans)): if i % 2 == 0: if ans[i] == "B": ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMB...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[:k] + "A" p = {p[i]: p[i + 1] for i in range(k)} if k == 2: t = input() u, v = "AB" * (n // 2) + "A" * (n % 2), "BA" * (n // 2) + "B" * (n % 2) x, y = sum(int(u[i] != t[i]) for i in range(n)), sum( int(v[i] != t[i]) for i in range(n) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR STRING ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP BIN_OP STRING BIN_OP VAR NUMBER ...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) PI = float("inf") for _ in range(1): n, k = lst() s = input() dp = [[(0) for i in range(k)] for j in range(n)] mn = smn = 0 for i in range(k): dp[0][i] = 1 dp[0][ord...
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 STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CA...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
from sys import stdin n, k = map(int, stdin.readline().split()) s = stdin.readline().strip() cand = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" cnt = 0 if k == 2: cmps = ("AB" * ((n + 1) // 2))[:n] for i in range(n): if s[i] != cmps[i]: cnt += 1 if cnt < n - cnt: print(cnt) print(cmps)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL V...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = input() if k == 2: sol1 = [s[i] for i in range(n)] ans1 = 0 for i in range(n): if i % 2 == 0 and sol1[i] == "B": ans1 += 1 sol1[i] = "A" elif i % 2 != 0 and sol1[i] == "A": ans1 += 1 sol1[i] = "B" sol2 =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR VAR STRING VAR NUMBER ASSIGN VA...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
def main(): n, k = map(int, input().split()) s = list(input()) if k > 2: ans = 0 for idx, i in enumerate(s): if idx == 0: continue if s[idx] == s[idx - 1]: for j in range(k): c = chr(65 + j) if s[...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER V...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = input() if k == 2: x = "A" y = "B" for i in range(1, n): if x[-1] == "A": x += "B" else: x += "A" if y[-1] == "A": y += "B" else: y += "A" p1 = 0 p2 = 0 for i in range(n): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER STRING VAR STRING VAR STRING IF VAR NUMBER STRING VAR STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR ...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = input() b = [] c = [] for j in s: b.append(j) c.append(j) if n == 1: print(0) print(b[0]) elif n == 2: if b[0] == b[1]: print(1) print("AB") else: print(0) print("".join(b)) elif k == 2: b[0] = "A" j = 1 s = 0 w...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CAL...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
from sys import stdin input = stdin.readline def put(): return map(int, input().split()) n, k = put() s = [(ord(i) - ord("A")) for i in list(input())] ans = [] dp = [0] * k ans.append(dp) a = b = 0 for i in range(n): tmp = [] first, second = n + 1, n + 1 for j in range(k): if dp[j] == a: ...
ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN V...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = list(input()) l = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")[:k] ll = set(l) if k >= 3: cnt = 0 for i in range(1, n): if s[i] == s[i - 1]: cnt += 1 if i + 1 < n: s[i] = list(ll - {s[i - 1]} - {s[i + 1]})[0] else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL ...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = input() a = s s = [] for i in range(len(a)): s.append(a[i]) prev = 0 alphs = [] ans = 0 for i in range(k): alphs.append(chr(ord("A") + i)) if k == 2: f = [] sec = [] t = 0 for i in range(n): f.append(chr(ord("A") + t)) sec.append(chr(ord("A") ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING V...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) s = input() l = [chr(65 + i) for i in range(k)] p = 0 if k == 2: q = "AB" * (n // 2) + "A" * (n % 2) w = "BA" * (n // 2) + "B" * (n % 2) o = 0 for i in range(n): if s[i] != q[i]: p += 1 if s[i] != w[i]: o += 1 if p > o: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP ST...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = map(int, input().split()) a = list(input().rstrip()) if k > 2: ans, s = 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[:k] for i in range(n - 1): if a[i] == a[i + 1]: for j in s: if j != a[i] and (i + 2 < n and j != a[i + 2] or i == n - 2): a[i + 1] = j ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMB...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
n, k = list(map(int, input().split())) a = [i for i in input()] b = 0 if k == 2: for i in range(n): if a[i] != "AB"[i % 2]: b += 1 if b < n - b: print(b) print("AB" * (n // 2) + "A" * (n % 2)) else: print(n - b) print("BA" * (n // 2) + "B" * (n % 2)) else:...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP S...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
n, m = map(int, input().split()) for k in range(33): m = min(m, abs(n ** (32 - k) - m)) print(["NO", "YES"][m == 0])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR LIST STRING STRING VAR NUMBER
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) A = [] while m: A.append(m % w) m //= w sz = len(A) A.append(0) for i in range(sz): x = A[i] if x != 0 and x != 1 and x != w - 1 and x != w: print("NO") exit() if x == w - 1 or x == w: A[i + 1] += 1 print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
M, N = map(int, input().split()) used = {} def check(K): while K: KP = 0 while K: if K % M == 0: K /= M elif K % M == 1 and KP not in used: K = (K - 1) / M else: return False KP += 1 return True w...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF WHILE VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN NUMBER VAR NUMBER RETURN NUMBER WHILE VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE ...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
n, m = map(int, input().split()) a = 0 d = True for i in range(100): if d and n > 0: if m % n ** (a + 1) == n**a: m -= n**a a += 1 elif m % n ** (a + 1) == 0: a += 1 elif (m + n**a) % n ** (a + 1) == 0: m += n**a a += 1 else...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) def solve(m, curw): cursum = 0 if m == 0: return 1 for i in range(curw): cursum += w**i if cursum == m: return 1 if cursum > m or w**i == m: return solve(abs(w**i - m), i) return 0 print("YES" if solve(m, 100) e...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL ...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
R = lambda: list(map(int, input().split())) w, m = R() while m: k = m % w if k == 1: m -= 1 elif k == w - 1: m += 1 elif k == 0: pass else: print("NO") exit(0) m //= w print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
def f(m, t): w = 0 nonlocal n while n**w * n < m: w += 1 if n**w * n == m or m == 1 and t != 0: return True else: s1 = m - n**w j = False k = False if w < t: j = f(abs(s1), w) if w + 1 < t: k = f(abs(n**w * n - m), w + 1...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL ...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) o = [] while m > 0: o.append(m % w) m //= w o.append(0) f = 0 for i in range(len(o) - 1): o[i + 1] += o[i] // w o[i] %= w if o[i] == 0: continue if o[i] == 1: continue elif o[i] < w - 1: f = 1 else: o[i + 1] += 1 print("YES...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER I...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
__author__ = "lenovo-pc" w, m = map(int, input().split(" ")) ans = True while m: k = m % w if k == 1: m -= 1 elif k == w - 1: m += 1 elif k == 0: pass else: ans = False m //= w if ans: print("YES") else: print("NO")
ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
__author__ = "artbataev" def tryWeight(w, m, num): if num < 1: return False if m == 1: return True if m % w == 0: return tryWeight(w, m // w, num - 1) if (m + 1) % w == 0: return tryWeight(w, (m + 1) // w, num - 1) if (m - 1) % w == 0: return tryWeight(w, (m...
ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETU...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
a, b = list(map(int, input().split(" "))) if a == 2 or a == 3: print("YES") return else: while b != 0: if b % a == 0: b //= a elif b % a == 1: b -= 1 b //= a elif b % a == a - 1: b += 1 b //= a else: prin...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING RETURN EX...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
R = lambda: map(int, input().split()) w, m = R() bs = [1] while bs[-1] < 10**10: bs.append(bs[-1] * w) arr = [0] * len(bs) for i in range(len(bs) - 1, -1, -1): if m >= bs[i]: arr[i] = m // bs[i] m %= bs[i] for i in range(len(bs)): if 1 < arr[i] < w - 1: print("NO") exit(0) ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIG...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) def b(x, base): digits = [] while x: digits.append(x % base) x = int(x / base) return digits digs = b(m, w) f = -1 s = 0 while True: for i in range(s, len(digs)): if digs[i] not in {0, 1}: if digs[i] != w - 1: print...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
def main(): w, m = map(int, input().split()) ww = 1 while ww < m: ww *= w while m and ww: m = min(m, m - ww, m + ww, key=abs) ww //= w print(("YES", "NO")[bool(m)]) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = list(map(int, input().split())) for u in (w ** (100 - i) for i in range(101)): m = min(m, abs(m - u)) print("YES" if m == 0 else "NO")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
def main(): w, m = map(int, input().split()) while m > 1: c = m % w if c not in {0, 1, w - 1}: return print("NO") m //= w if c == w - 1: m += 1 print("YES") main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR STRING VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) arr = [0] * 103 i = 0 while m != 0: arr[i] = m % w m //= w i += 1 for j in range(i): if arr[j] == 1 or arr[j] == 0: pass elif arr[j] % w == 0: arr[j + 1] += 1 elif arr[j] == w - 1: arr[j + 1] += 1 else: print("NO") brea...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUM...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
def rec(remain, prev_index): if remain == 0: return True if prev_index == 0: return False index = -1 for i in range(prev_index): if remain > 0 and w ** (i + 1) - remain >= 0: index = i break elif remain < 0 and w ** (i + 1) + remain >= 0: ...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
n, m = map(int, input().split()) flag = 0 while m > 0: if (m - 1) % n == 0: m -= 1 elif (m + 1) % n == 0: m += 1 if m % n != 0: flag = -1 break m //= n if flag == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
x = [0] * 101 ww, m = map(int, input().split()) if ww == 2: print("YES") exit() w = ww c = 0 while m: x[c] = m % w m //= w c += 1 an = 1 w = ww vis = [0] * 101 for i in range(101): if x[i] == w - 1: vis[i] = 1 x[i] = 0 if i + 1 > 100: an = 0 break ...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR V...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, n = map(int, input().split(" ")) r = 1 if w <= 3: n = 0 while n: if not n % w in {0, 1, w - 1}: r = 0 if n % w == w - 1: n = n // w + 1 else: n = n // w if r: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR ...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
base, num = map(int, input().split()) if base == 3 or base == 2: print("YES") quit() newNum = [] while num > 0: newNum = [num % base] + newNum num //= base newNum = [0] + newNum for i in range(len(newNum) - 1, 0, -1): if newNum[i] == base or newNum[i] == base - 1: newNum[i - 1] += 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR V...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
import sys def seek(x, terms, sums, index): if x == 0 or sums[index] == x: print("YES") sys.exit() if sums[index] < abs(x): return if x > 0: seek(x - terms[index], terms, sums, index - 1) else: seek(x + terms[index], terms, sums, index - 1) seek(x, terms, su...
IMPORT FUNC_DEF IF VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR FUNC_CALL VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
__author__ = "victormion" w, m = input().strip().split() w = int(w) m = int(m) def solve(w, m): return ( w <= 3 or m == 1 or trySolve(w, m - 1) or trySolve(w, m) or trySolve(w, m + 1) ) def trySolve(w, m): return m % w == 0 and solve(w, m // w) if solve(w, m): print("YES") else: print(...
ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP ...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
def VI(): return list(map(int, input().split())) def Y(): print("YES") def run(w, m): if w <= 3: Y() return mm = m for i in range(100): if m % w == 0: m //= w elif m % w == 1: m = (m - 1) // w elif m % w == w - 1: m = (m...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR RETURN ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR BIN_...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) def f(m, w): while m != 0: x = (m + 1) % w if x == 0: m = (m + 1) // w elif x < 3: m = m // w else: return False return True if w == 2: print("YES") elif f(m, w): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, x = map(int, input().split()) a = [] cur = w**50 while cur: if x >= cur: a.append(x // cur) x %= cur else: a.append(0) cur //= w for i in range(50, 1, -1): if a[i] > 1: a[i] -= w a[i - 1] += 1 if a[i] not in {-1, 0, 1}: print("NO") exit(0) p...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER N...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
M, N = map(int, input().split()) used = {} P = 0 while M**P < N: P += 1 for p in range(P, -1, -1): k = M**p if abs(k - N) < N: N = abs(k - N) if N == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_C...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
base, massa = map(int, input().split()) for i in range(100, -1, -1): if abs(massa - base**i) < massa: massa = abs(massa - base**i) if massa == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
W, M = input().split(" ") W = int(W) M = int(M) if W == 2 or W == 3: print("YES") else: N = 16 A = [0] * (N + 1) A[0] = 1 for I in range(1, N): A[I] = A[I - 1] * W if A[I] > 10000000001000000000: N = I break S = set() ok = False for msk in range(1 ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMB...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = tuple(map(int, input().split())) f = True while m > 0: if m % w == 0: m //= w elif m % w == 1: m //= w elif m % w == w - 1: m = m // w + 1 else: f = False break print("YES" if f else "NO")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) s = 0 p = 1 for i in range(101): s += p p *= w m += s bad = False while m > 0: if m % w > 2: print("NO") exit() m //= w print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) f = 0 ff = 0 while m != 0: i = 0 ma = 0 while w**i < m: ma += w**i i += 1 if w**i - ma <= m: ff = 1 m = w**i - m elif ma >= m: ff = 2 m = m - w ** (i - 1) else: f = 1 print("NO") break if not...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER AS...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = [int(i) for i in input().split()] if w == 0: if m <= 101: print("YES") else: print("NO") exit(0) a = [] m1 = m while m1 > 0: a.append(m1 % w) m1 //= w if len(a) > 101: print("NO") exit(0) s = True for i in range(len(a)): if a[i] != 0 and a[i] != 1: s = Fals...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
base, need = map(int, input().split()) if base == 2: print("YES") else: digits = [] while need: digits.append(need % base) need //= base res_found = False for i in range(len(digits)): if digits[i] == base - 1: digits[i] = 0 try: digits[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP...
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
def can_weigh(w, m): while m > 0: if (m - 1) % w == 0: m -= 1 elif (m + 1) % w == 0: m += 1 elif m % w != 0: return "NO" m //= w return "YES" w, m = map(int, input().split()) result = can_weigh(w, m) print(result)
FUNC_DEF WHILE VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN STRING VAR VAR RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
w, m = map(int, input().split()) mass = [] while m > 0: mass.append(m % w) m //= w mass.append(0) for i in range(len(mass) - 1): if mass[i] >= w - 1: mass[i + 1] += 1 mass[i] = 0 ok = 1 for i in range(len(mass)): if mass[i] > 1: ok = 0 print("NO" if ok == 0 and w != 2 else "YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FU...