description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
x = input() lol = "" c = 0 yo = [] while int(x) > 0: if int(x) < 10: c += int(x) yo = yo + [1] * int(x) x = 0 else: for i in x: if int(i) >= 1: lol += "1" else: lol += "0" x = str(int(x) - int(lol)) yo.append...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VA...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
quasiNumbers = [] num = input() l = len(num) m = n = int(num) x = max(num) maxi = int(x) print(x) for i in range(maxi): j = l - 1 s = 0 while j >= 0: k = n // 10**j n = n % 10**j if k > 0: s = s * 10 + 1 else: s = s * 10 j -= 1 f = str(s) ...
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
def solve1(n): r = [] while n > 0: t = int("".join([("0" if x == "0" else "1") for x in str(n)])) n -= int(t) r.append(t) print(len(r)) print(" ".join(map(str, r))) num = int(input()) solve1(num)
FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR STRING STRING STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = int(input()) s = "" ans = 0 while n > 0: m = int("".join([("1" if d != "0" else "0") for d in str(n)])) n -= m if n >= 0: ans += 1 s += str(m) + " " print(ans, s, sep="\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR STRING STRING STRING VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = int(input()) a = [(0) for i in range(0, 100)] m = 0 t = 1 while n > 0: b = int(n % 10) m = max(m, b) for i in range(0, b): a[i] = a[i] + t t = t * 10 n = n / 10 print(m) for i in range(0, m): print(a[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = list(input()) digits = [] numbers = [] for i in range(len(n)): digits.append(int(n[i])) for i in range(max(digits)): numbers.append(0) for i in range(len(n)): for j in range(digits[i]): numbers[j] += 10 ** (len(n) - 1 - i) print(max(digits)) for num in numbers: print(num, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = int(input()) res = [] digit = dict.fromkeys(map(ord, "123456789"), "1") while n: val = str(n).translate(digit) n -= int(val) res.append(val) print(len(res)) print(*res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
l = list(map(int, list(input()))) print(max(l)) ans = [] while l.count(0) != len(l): k = ["0" for i in range(len(l))] for i in range(len(l)): if l[i] != 0: l[i] -= 1 k[i] = "1" ans.append(str(int("".join(k)))) print(" ".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR STRING EX...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
from sys import stdout n = input() num = int(n) c = 0 v = [] while num > 0: l = len(n) if n.count("1") + n.count("0") == l: c += 1 v.append(n) break else: s = "" if "0" in n: for i in n: if i == "0": s += "0" ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING IF STRING VAR FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR FUNC_CALL VA...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
s = input() q = [int(x) for x in s] def a(i): r = "" for x in q: if x >= i: r += "1" elif len(r): r += "0" return r mx = 0 for x in q: mx = max(mx, x) print(mx) kek = [a(x) for x in range(1, mx + 1)] s = "" for x in kek: s += x s += " " print(s)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR STRING RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
a = input() count = 0 mass = [] for i in range(len(a)): mass.append(a[i]) strings = [] def number(mass): string = "" for i in range(len(mass)): join = "".join if mass[i] != "0": mass[i] = str(int(mass[i]) - 1) string = join([string, "1"]) else: s...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = int(input()) if 1 <= n < 9: print(n) for i in range(n): print(1, end=" ") else: x = str(n) x = list(x) cnt = 0 res = [] while n > 0: tem = "" for i in range(len(x)): if x[i] != "1" and x[i] != "0": x[i] = "1" tem += x[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
num = input() le = len(num) num2 = [0] * le for i in range(le): num2[i] = int(num[i]) print(max(num2)) for i in range(le): while num2[i] > 0: print(1, end="") for j in range(i + 1, le): if num2[j] > 0: num2[j] -= 1 print(1, end="") else: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR V...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
a = input() n = [q for q in a] s = [] t = ["0"] * len(n) while n != t: d = "" for i in range(len(n)): if n[i] == "0": d += "0" else: d += "1" n[i] = str(int(n[i]) - 1) s.append(int(d)) print(len(s)) print(" ".join(map(str, s)))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VA...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = int(input()) arr = [] while n > 0: x = [int(i) for i in str(n)] q = [min(i, 1) for i in x] q = "".join([str(i) for i in q]) q = int(q) arr.append(q) n -= q print(len(arr)) print(*arr)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EX...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = int(input()) l = [] ans = [] cur = n while cur > 0: l.insert(0, cur % 10) cur = cur // 10 f = 0 f1 = 0 while f1 == 0: s = "" for i in range(0, len(l)): if l[i] != 0: l[i] -= 1 s += "1" f = 1 elif l[i] == 0 and f == 1: s += "0" ans.a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR ...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = int(input()) def iskvazi(x): while x > 0: cur = x % 10 if cur != 0 and cur != 1: return False x = x // 10 return True kvazi = [] p = [0] * (n + 1) add = [0] * (n + 1) ans = [0] * (n + 1) for i in range(1, n + 1): if iskvazi(i): kvazi.append(i) for i in ran...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BI...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = list(map(int, input())) m = max(n) print(m) for j in range(m): l = [] for i in n: if i > j: l.append(str(1)) else: l.append(str(0)) print(int("".join(l)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
s = input() n = int(s) cont = [] while n > 0: res = "" for i in s: if i != "0": res += "1" else: res += "0" n -= int(res) cont.append(res) s = str(n) print(len(cont)) for i in cont: print(i, end=" ")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = list(map(int, list(input()))) ans = int(max(n)) print(ans) s = "" while ans: for i in range(len(n)): if n[i] >= 1: s += "1" n[i] -= 1 else: s += str(n[i]) print(int(s), end=" ") s = "" ans -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING A...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
def psuedoBinary(n, l): while n > 0: temp = n m = 0 p = 1 while temp: rem = temp % 10 temp = int(temp / 10) if rem != 0: m += p p *= 10 l.append(m) n = n - m n = int(input()) l = [] psuedoBinary(n, l) p...
FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR V...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = [int(i) for i in input()] n_sorted = list(map(lambda x: list(x), list(enumerate(n.copy())))) n_sorted.sort(key=lambda x: x[1]) estado = ["1" for i in range(len(n))] numeros = [] for k in n_sorted: numeros += k[1] * [int("".join(estado))] sub = k[1] for i in n_sorted: i[1] -= sub estado[k[0]]...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR BIN_OP VAR NUMBER LIST FUNC_CALL VAR FUNC_CALL STRING VAR ...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
ans = [] def minQuasi(n): if n <= 0: return m = "".join(min(i, "1") for i in str(n)) minQuasi(n - int(m)) ans.append(m) n = int(input()) minQuasi(n) print(len(ans)) print(*ans)
ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = input() answer = [] for j in range(int(n[0])): answer.append(10 ** (len(n) - 1)) for i in range(1, len(n)): j = 0 while j < len(answer) and j < int(n[i]): answer[j] += 10 ** (len(n) - i - 1) j += 1 if j < int(n[i]): while j < int(n[i]): answer.append(10 ** (len(n)...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VA...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
a = list(map(int, list(input()))) r = [] while True: ok = False p = 0 for i in range(len(a)): p = p * 10 + (a[i] > 0) if a[i]: ok = True a[i] -= 1 if not ok: break else: r.append(p) print(len(r)) print(*r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
s = input() mas = [] res = 0 for i, x in enumerate(s): x = int(x) for j, y in enumerate(mas): if x == 0: mas[j] += "0" else: mas[j] += "1" x -= 1 for i in range(x): res += 1 mas.append("1") print(res) print(*mas)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
a = input() inputList = [int(x) for x in reversed(a)] outputList = [] listItem = 0 while sum(inputList) != 0: listItem = 0 for i in range(0, len(inputList)): if inputList[i] != 0: listItem += 10**i inputList[i] -= 1 outputList.append(listItem) print(len(outputList)) for i in ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
n = list(map(lambda x: int(x), list(input()))) maxval = max(n) ans = [""] * maxval ns = len(n) for c in n: for i in range(maxval): if i < c: ans[i] += "1" else: ans[i] += "0" ans = list(map(lambda x: str(int(x)), ans)) print(maxval) print(" ".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL V...
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. -----Input----- The first line contai...
def main(): n = input() prob = [int(digit) for digit in n][::-1] res = [] for i in range(max(prob)): num = 0 for index, number in enumerate(prob): if number >= i + 1: num += 10**index res.append(num) print(len(res)) print(" ".join([str(number) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL ST...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
import itertools n, m, k = map(int, input().split()) A = list(map(int, input().split())) acc = [0] + list(itertools.accumulate(A)) rsum = lambda i, j: acc[j + 1] - acc[i] dp = [0] * n ans = 0 for i, a in enumerate(A): if i >= m: dp[i] = max(dp[i], dp[i - m] + rsum(i - m + 1, i) - k) for j in range(i, m...
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL V...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
from itertools import accumulate n, m, k = map(int, input().split()) a = list(map(int, input().split())) als = [] for i in range(m): ls = a[:] for j in range(n): if j % m == i: ls[j] -= k als.append(list(accumulate(ls))) ans = 0 for i in range(m): ls = als[i] mn = 0 anstmp =...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VA...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
def getBestWindow(N, M, K, a): dp, ans = [], 0 for i in range(0, N): dp.append(a[i] - K) sum, x = a[i], max(0, i - M) for j in range(i - 1, x - 1, -1): dp[i] = max(dp[i], dp[j] + sum - K) sum += a[j] if i < M: dp[i] = max(dp[i], sum - K) ...
FUNC_DEF ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = map(int, input().split()) a = list(map(int, input().split())) best = 0 dp = [0] * (n + 1) for i in range(n): b2 = 0 for j in range(max(-1, i - m), i + 1): b2 = max(b2, dp[j] - k + sum(a[j + 1 : i + 1])) dp[i] = max(b2, a[i] - k) best = max(best, dp[i]) print(best)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
def max_subarray(A): max_ending_here = max_so_far = A[0] for x in A[1:]: max_ending_here = max(x, max_ending_here + x) max_so_far = max(max_so_far, max_ending_here) return max_so_far ans = 0 n, m, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(m): li =...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
def maxsum(a): best = 0 cur = 0 for e in a: cur = max(cur, 0) + e best = max(best, cur) return best def solve(m, k, a): if m == 1: return maxsum([(e - k) for e in a]) best = 0 cur = [-k] * m for e in a: new_cur = [ (max(0, cur[0]) + e - k if ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP FUNC_CAL...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = map(int, input().split()) (*a,) = map(int, input().split()) dp = [-1] * (n + 15) for i in range(n): s, mx = a[i], max(0, a[i]) for j in range(i - 1, max(-1, i - m), -1): s += a[j] mx = max(mx, s) dp[i] = max(0, dp[i - m] + s - k, mx - k) print(max(dp))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMB...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = [int(w) for w in input().split()] a = [int(w) for w in input().split()] def f(o): r = e = 0 for i, x in enumerate(a): if i < o: continue if i % m == o: e -= k if e < -k: e = -k e += x if e > r: r = e ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_C...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
from sys import exit, stdin, stdout n, m, k = list(map(int, stdin.readline().split())) a = list(map(int, stdin.readline().split())) def bf(a): best = 0 best_arg = -1, -1 for i in range(n): for j in range(i, n): cur = sum(a[i : j + 1]) - k * ((j - i) // m + 1) if cur > best...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR B...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) A = [int(i) for i in input().split()] if n <= m: AA = [0] * (n + 1) for i in range(n): AA[i + 1] = AA[i] + A[i] mm = 0 for i in range(n + 1): for j in range(i + 1, n + 1): mm = max(mm, AA[j] - AA[i] - ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = map(int, input().split()) A = list(map(int, input().split())) glans = 0 for s in range(m): B = [] f = s su = 0 sus = 0 for i in range(s, n): su += A[i] sus = max(sus, su) if (i + 1) % m == s: B.append(sus - k) B.append(su - sus) s...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
import sys def input(): return sys.stdin.readline().rstrip() DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] def main(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) ans = 0 for mod in range(m): b = [0] + a.copy() for i in range(1, n + 1): if i %...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LI...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = map(int, input().strip().split()) a = list(map(int, input().strip().split())) a = [0] + a dp = [0] * 300005 ans = 0 for i in range(1, n + 1): a[i] += a[i - 1] for j in range(1, m + 1): if i - j >= 0: dp[i] = max(dp[i], a[i] - a[i - j] - k) if i - m >= 0: dp[i] = max(dp[...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VA...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
N, M, K = list(map(int, input().split())) A = [int(a) for a in input().split()] S = [0] for a in A: S.append(S[-1] + M * a - K) MI = [10**50] * M ans = 0 for i in range(N + 1): MI[i % M] = min(MI[i % M], S[i]) for j in range(M): ans = max(ans, (S[i] - MI[(i - j) % M] - K * (-j % M)) // M) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BI...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
import sys n, m, k = list(map(int, sys.stdin.readline().strip().split())) a = list(map(int, sys.stdin.readline().strip().split())) b = [0] * (n + 1) for i in range(1, n + 1): b[i] = b[i - 1] + m * a[i - 1] - k M = [10**20] * m ans = 0 for i in range(0, n + 1): M[i % m] = min([M[i % m], b[i]]) for j in rang...
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_O...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = map(int, input().split()) a = list(map(int, input().split())) sa = [0] * n ans = 0 for i in range(n): sa[i] = a[i] - k s = a[i] for j in range(i - 1, max(-1, i - m - 1), -1): sa[i] = max(sa[i], sa[j] + s - k) s += a[j] if i < m: sa[i] = max(sa[i], s - k) sa[i] = max...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER ...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = map(int, input().split()) b = [0] + list(map(int, input().split())) rem = [float("inf") for i in range(m)] rem[0] = k curr = 0 ans = 0 for i in range(1, n + 1): curr += b[i] ans = max(ans, curr - min(rem)) rem[i % m] = min(rem[i % m], curr) rem[i % m] += k print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR AS...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
import sys def eprint(*args): print(*args, file=sys.stderr) zz = 1 if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def string(s): return "".join(s) def fori(n): return [fi() for i in rang...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL STRING VAR FUNC_DEF RETURN FUNC_CALL VAR ...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
base = 1000000007 n, m, k = map(int, input().split()) a = list(map(int, input().split())) mx = 0 s = 0 dp = [] dd = [] for j in range(m): for i in range(n + 1): dp.append(base) dd.append(0) for i in range(n): dd[i + 1] = dd[i] + a[i] - k * (i % m == j) dp[i + 1] = min(dd[i], dp[i...
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VA...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) bv = 0 for ms in range(M): cv = 0 for i in range(ms, N): v = A[i] if i % M == ms: v -= K cv = max(0, cv) cv += v bv = max(bv, cv) print(bv)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR V...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = [int(i) for i in input().split()] A = [int(i) for i in input().split()] bestbest = 0 def brute(n, m, k, A): ans = 0 val = 0, 0 for i in range(n): for j in range(i, n): if ans < sum(A[i : j + 1]) - k * ceil((j - i + 1) / m): ans = sum(A[i : j + 1]) - k * ceil((...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CA...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) values = list() for j in range(n): result = a[j] sum1 = 0 for i in range(m): if j - i >= 0: sum1 = sum1 + a[j - i] if sum1 > result: result = sum1 else: continue ...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VA...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) dp = [([float("-inf")] * m) for i in range(n)] dp[0][0] = a[0] for i in range(1, n): for j in range(1, m): dp[i][j] = dp[i - 1][j - 1] + a[i] dp[i][0] = max(dp[i - 1][m - 1] - k, 0) + a[i] print(max(max([max(x) for x in dp]) -...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN...
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least i...
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, M, K = map(int, input().split()) A = list(map(int, input().split())) cs = [0] * (N + 1) mi = [10**10] * M mi[0] = 0 ans = 0 for i, a in enumerate(A): cs[i + 1] = cs[i] + (a - K /...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN V...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
n, m = map(int, input().split()) S = [input() for i in range(n)] mod = 998244353 ans = 0 count = 0 for i in range(n): for j in range(m): if S[i][j] == "o": count += 1 pow2 = 1 N = [0] for i in range(n): N.append((pow2 - N[-1]) % mod) pow2 *= 2 pow2 %= mod pow2 = 1 M = [0] for i in ra...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
from sys import stdin input = stdin.readline def A(): t = int(input()) for _ in range(t): n = int(input()) r = list(map(int, input().split())) s = 0 for i in r: if i == 1 or i == 3: s += 1 print(s) def B(): t = int(input()) for _ i...
ASSIGN VAR VAR FUNC_DEF 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 NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FU...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
from sys import stdin, stdout mod = 998244353 d = {} def power(x, y): if y < 0: return 0 s = str(x) + "$" + str(y) if d.get(s, -1) != -1: return d[s] f = 1 y1 = y while y: if y % 2 == 1: f *= x x = x * x y //= 2 x %= mod f %=...
ASSIGN VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int, sys.stdin.readline().rstrip())) def S(): return sys.stdin.re...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL V...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys input = sys.stdin.readline mod = 998244353 n, m = map(int, input().split()) board = [input().strip() for i in range(n)] ans = 0 tot_c = 0 tot_h = [] tot_v = [] for i in range(n): for j in range(m): if board[i][j] == "o": tot_c += 1 for i in range(n): for j in range(m): if...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
n, m = map(int, input().split()) g = [input() for _ in range(n)] mod = 998244353 two = [1, 2, 4, 8] dp = [0, 0, 1, 3] ct = 8 for i in range(4, n * m + 1): ct *= 2 ct %= mod two.append(ct) dp.append((dp[i - 1] + 2 * dp[i - 2] + two[i - 2]) % mod) white = 0 ans = 0 for i in range(n): for j in range(m)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL ...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys input = sys.stdin.readline MOD = 998244353 def solve(N, M, B): pow2 = [1] * (3 * 10**5 + 10) for i in range(1, len(pow2)): pow2[i] = pow2[i - 1] * 2 % MOD dp = [0] * (3 * 10**5 + 10) for i in range(2, len(dp)): dp[i] = 2 * dp[i - 2] + pow2[i - 2] + dp[i - 1] dp[i] %...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR ...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
pow2 = [(0) for i in range(300005)] pow2[0] = 1 for i in range(1, 300005): pow2[i] = pow2[i - 1] * 2 pow2[i] %= 998244353 dp = [(0) for i in range(300005)] dp[2] = 1 for i in range(3, 300005): dp[i] = dp[i - 1] + 2 * dp[i - 2] + pow2[i - 2] dp[i] %= 998244353 l = input().split() n = int(l[0]) m = int(l[...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NU...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
n, m = map(int, input().split()) s = [(input() + "*") for _ in range(n)] + ["*" * (m + 1)] cnt = sum(i.count("o") for i in s) MOD = 998244353 ans = 0 inv4 = pow(4, MOD - 2, MOD) inv2 = pow(2, MOD - 2, MOD) v = pow(2, cnt, MOD) for i in range(n + 1): cnt = 0 for j in range(m + 1): if s[i][j] == "o": ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR LIST BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUN...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = [input() for i in range(n)] mod = 998244353 inv = 499122177 w, res = 0, 0 for i in range(n): even, odd = 0, 1 for j in range(m): if s[i][j] == "*": even, odd = 0, 1 else: res += even * inv ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR NUMBER NUMB...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
mod = 998244353 def qpow(n, k): res = 1 while k: if k & 1: res = res * n % mod n = n * n % mod k >>= 1 return res n, m = map(int, input().split()) mp = [] cnt = 0 for i in range(n): mp.append(input()) for j in mp[-1]: if j == "o": cnt += 1 ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VA...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
mod = 998244353 n, m = map(int, input().split()) a = [0] * n dp = [0] * n dp2 = [0] * n P = [0] * 300005 for i in range(n): dp[i] = [0] * m dp2[i] = [0] * m for i in range(n): a[i] = list(input()) cnt = 0 for i in range(n): for j in range(m): if a[i][j] == "o": cnt += 1 ans = 0 P[2] ...
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR FOR ...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys input = sys.stdin.readline n, m = map(int, input().split()) grid = [] for i in range(n): grid.append(input()) ans = 0 MOD = 998244353 count = 0 for i in range(n): for j in range(m): if grid[i][j] == "o": count += 1 if count < 2: print(0) exit() s = pow(2, count - 2, MOD) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CAL...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
MOD = 998244353 ninv = pow(9, MOD - 2, MOD) def f(n): return ((3 * n + 1) * pow(2, n, MOD) - (1 if n % 2 == 0 else -1)) * ninv h, w = map(int, input().split()) s = ["*" * (w + 2)] + [("*" + input() + "*") for _ in range(h)] + ["*" * (w + 2)] c = 0 for i in range(h + 2): c += s[i].count("o") ans = 0 for i in...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST BIN_OP STRING BIN_OP...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys from sys import stdin mod = 998244353 H, W = map(int, stdin.readline().split()) s = [list(stdin.readline()[:-1]) for i in range(H)] ans = 0 onum = 0 for i in range(H): for j in range(W): if s[i][j] == "o": onum += 1 for i in range(H): to = onum dp = [1, 0] for j in range(...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN V...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
p = 998244353 pow = [1] for i in range(1, 3 * 10**5 + 1): pow.append(2 * pow[-1] % p) dp = [0] * (3 * 10**5 + 1) dp[2] = 1 for i in range(3, 3 * 10**5 + 1): dp[i] = (pow[i - 2] + dp[i - 1] + 2 * dp[i - 2]) % p n, m = map(int, input().split()) b = [] for i in range(n): b.append(input()) res = [] cnt = 0 for ...
ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys input = sys.stdin.readline MOD = 998244353 n, m = map(int, input().rstrip().split()) mapp = [list(input().rstrip()) for _ in range(n)] dp = [0, 0, 1] for i in range(3, max(n, m) + 1): dp.append((dp[-1] + 2 * dp[-2] + pow(2, i - 2, MOD)) % MOD) white_lst = [] w = 0 for i in range(n): flag = False ...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP ...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
from sys import stdin, stdout MOD = 998244353 b1 = 0 b2 = 0 b3 = 0 def colorings_and_dominoes(n, m, s_a): r = 0 c = sum(s.count("o") for s in s_a) b_a = [(1) for _ in range(c + 1)] if c >= 2: b_a[2] = bpow(c - 2) if c >= 3: b_a[3] = bpow(c - 3) for i in range(4, c + 1, 1): ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
def pot2mod(blancos, memo=[1]): if blancos < 0: return 0.5 if blancos < len(memo): return memo[blancos] global NUMMOD for i in range(len(memo), blancos + 1): memo.append(memo[i - 1] * 2 % NUMMOD) return memo[blancos] NUMMOD = 998244353 * 8 n, m = map(int, input().split()) e...
FUNC_DEF LIST NUMBER IF VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR RETURN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASS...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
import sys def putin(): return map(int, sys.stdin.readline().split()) def f(n): return ((3 * n + 1) * 2**n - (-1) ** n) // 9 def sol(): n, k = putin() A = [] for i in range(n): A.append(list(sys.stdin.readline())) O_number = 0 for i in range(n): for j in range(k): ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBE...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
MOD = 998244353 N, M = map(int, input().split()) S = [input() for _ in range(N)] L = max(N, M) imos = [0] * (L + 2) for i in range(N): cnt = 0 for j in range(M): if S[i][j] == "*": cnt = 0 else: cnt += 1 imos[1] += 1 imos[cnt + 1] -= 1 for j in ran...
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUM...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
MOD = 998244353 def power(a, b): res = 1 while b > 0: if b % 2 == 1: res = res * a % MOD a = a * a % MOD b //= 2 return res def inverse(n): return power(n, MOD - 2) h, w = map(int, input().split()) grid = [input() for _ in range(h)] prob = [0, 0] for c in range(...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ...
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells. After painting...
n, m = map(int, input().split()) maze = [] for i in range(n): maze.append(input()) tot = 0 for i in range(n): for j in range(m): if maze[i][j] == "o": tot += 1 lis = [(0) for i in range(max(n, m) + 1)] for i in range(n): j = 0 while j < m: p = j while p < m and maze[i...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n, k, A, B = [int(input()) for _ in range(4)] s = 0 if k == 1: print(A * (n - 1)) exit() while n > 1: t = n % k d = n // k if not d: s += (n - 1) * A print(s) exit() s += A * t if t else min(A * (n - d), B) n = k * d if t else d print(s)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) ans = 0 if k == 1: ans = (n - 1) * a else: while n != 1: if n % k == 0: t = n // k ta = min(b, (n - t) * a) ans += ta n = t else: t = n % k if n // k else n - 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
number = int(input()) divisor = int(input()) decrement_cost = int(input()) division_cost = int(input()) final_cost = 0 while number != 1: remainder = number % divisor if remainder != 0: final_cost += decrement_cost * remainder number -= remainder jump = number - number // divisor if divi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
import sys n = int(input()) divisor = int(input()) price_sub = int(input()) price_div = int(input()) x = n cost = 0 if divisor == 1: cost += (x - 1) * price_sub print(int(cost)) sys.exit(0) num_subs = divisor - 1 while x > 1: if x % divisor != 0: mod = x % divisor cost += price_sub * mo...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) if k == 1: print((n - 1) * a) else: x = n count = 0 while x > 1: if x >= k: if x % k == 0: if (x - x // k) * a > b: count += b else: count += (x...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
def dp(x, k, a, b): if x < k or k == 1: return (x - 1) * a if x % k == 0: return dp(x // k, k, a, b) + min(b, a * (x - x // k)) else: return dp(x - x % k, k, a, b) + x % k * a n = int(input()) k = int(input()) a = int(input()) b = int(input()) print(dp(n, k, a, b))
FUNC_DEF IF VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR F...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
import sys n = int(input()) k = int(input()) A = int(input()) B = int(input()) x = n cst = 0 if k == 1: print((x - 1) * A) sys.exit(0) while x != 1: if x % k == 0: cst += min((x - x // k) * A, B) x = x // k elif x < k: cst += (x - 1) * A x = 1 else: cst += x ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR N...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) if n == 1: print(0) exit() if k > n or k == 1: print(a * (n - 1)) exit() mn = a * (n - 1) ans = 0 while n // k >= 1: x = n % k y = n // k ans += min(a * (n - y), x * a + b) n = n // k if n: ans += (n - 1) * a print(m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_O...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) anw = 0 if k == 1: print(a * (n - 1)) exit(0) while n > 1: if n % k != 0: if n < k: n -= 1 anw += a * (n % k) n -= n % k else: toMinus = (n - n // k) * a anw += min(toMinus, b) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR N...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
class COL: def main(self): n = int(input()) k = int(input()) a = int(input()) b = int(input()) x = n count = 0 if k == 1: print(str((x - 1) * a)) return while x > 1: if x < k: count = count + a * (x ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN WHILE VAR NUMBER IF VAR VAR A...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
def main(): n = int(input()) k = int(input()) A = int(input()) B = int(input()) cost = 0 if k == 1: print((n - 1) * A) exit(0) if n == 1: print(0) exit(0) while n > 1: if n % k != 0: mul = n - k * (n // k) cost += A * mul ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
import sys n = int(input()) k = int(input()) a = int(input()) b = int(input()) if k == 1: print((n - 1) * a) sys.exit() s = 0 while n > 1: if n % k == 0: d = n - n // k if b > a * d: n -= d s += a * d else: n //= k s += b elif n //...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_O...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) cost = 0 if k > 1: while n > 1: if n >= k and n % k == 0: q = n // k cost += min((n - q) * a, b) n = q elif n >= k and n % k != 0: q = n // k l = q * k cost += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN V...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n, k, A, B, v = int(input()), int(input()), int(input()), int(input()), 0 while n > 1: if k == 1 or n < k: v += A * (n - 1) n = 1 elif n % k: v += A * (n % k) n -= n % k else: v += min(A * (n - n // k), B) n //= k print(v)
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) ans = 0 if k == 1: print((n - 1) * a) else: while n > 1: if n % k == 0: ans += min(b, a * (n - n // k)) n //= k elif n > k: ans += n % k * a n -= n % k else: an...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VA...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) A = int(input()) B = int(input()) cost = 0 if k == 1: cost += (n - 1) * A else: while n > 1: r = n % k q = n // k if n < k: cost += (n - 1) * A n = 1 elif r != 0: cost += r * A n -= r else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP V...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) cn = 0 if k == 1: print((n - 1) * a) exit(0) while n >= 1: x = n % k cn += a * x n -= x if n == 0: cn -= a break nn = n // k cn += min(b, (n - nn) * a) n = nn print(cn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR ...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) x = n cost = 0 if k == 1: cost = (x - 1) * a else: while x != 1: r = x % k cost += a * r x -= r if x == k: if (x - x // k) * a > b: cost += b x = x // k els...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR ...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) ans = 0 if ((k == 1) | (k > n)) & (n != 1): ans = n * a - a n = 1 while n != 1: if n % k == 0: t = n // k y = n - t if y * a <= b: ans += n * a - a n = 1 else: ans += b ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER AS...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) ans = 0 if k != 1: while n != 1: if n % k != 0: ans = ans + n % k * a n = n - n % k if n == 0: ans = ans - a n = 1 else: f = n // k if b > (...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VA...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) x = n y = 0 while x > 1: c = x / k if x % k == 0 and (x - int(c)) * a >= b and k != 1: x = c y = y + b elif x % k == 0 and (x - int(c)) * a < b: y = y + a * (x - 1) x = 1 elif x % k == 0 and (x - int(c)) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN V...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) div = int(input()) minusCost = int(input()) divCost = int(int(input())) if div == 1: print((n - 1) * minusCost) exit() ret = 0 cur = n while cur > 1: if cur < div: ret += (cur - 1) * minusCost cur = 1 elif cur % div != 0: ret += cur % div * minusCost cur ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR BIN_...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x...
n = int(input()) k = int(input()) a = int(input()) b = int(input()) m = n ans = 0 if n >= k and k > 1: while n != 1: ans += n % k * a n -= n % k ans += min(b, (n - n // k) * a) n //= k if n < k: ans += (n - 1) * a break print(min(ans, (m - 1) * a))...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN...