description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | c = 0
n = int(input())
s = list(input())
posible = ["B", "G", "R"]
if n != 1:
for i in range(1, n - 1):
if s[i] == s[i - 1]:
if s[i] == "R" and s[i + 1] != "B":
s[i] = "B"
elif s[i] == "R" and s[i + 1] != "G":
s[i] = "G"
elif s[i] == "G" an... | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR BI... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = list(input())
rgb = ["R", "B", "G"]
x = 0
if n == 1:
print(0)
print(s[0])
exit(0)
for i in range(len(s) - 2):
if s[i] == s[i + 1] and s[i] != s[i + 2]:
rgb.remove(s[i])
rgb.remove(s[i + 2])
s[i + 1] = rgb[0]
x += 1
elif s[i] == s[i + 1]:
r... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR ... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = list(input())
so = s[0]
COUNT = 0
for i in range(1, n):
if s[i] != so:
so = s[i]
continue
elif i != n - 1:
if so == "R" and s[i + 1] == "R":
s[i] = "G"
if so == "G" and s[i + 1] == "G":
s[i] = "B"
if so == "B" and s[i + 1] == "... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR STRING VAR BIN_OP VAR NUMBER STRING AS... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = input()
ar = list(s)
k = 0
if n == 1:
print(0)
print(s)
elif n == 2:
if len(set(s)) == 1:
if ar[0] == "R":
print(1)
print("RG")
elif ar[0] == "G":
print(1)
print("GB")
else:
print(1)
print("B... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER STR... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = "!" + input().strip()
dp = [([10**6] * (n + 1)) for i in range(3)]
pr = [([None] * (n + 1)) for i in range(3)]
dp[0][0] = dp[1][0] = dp[2][0] = 0
for i in range(1, n + 1):
for c in range(3):
op1 = dp[(c + 1) % 3][i - 1]
op2 = dp[(c + 2) % 3][i - 1]
pr[c][i] = (c + 1) % 3... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VA... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | def main():
n = int(input())
clone = set(["R", "G", "B"])
lamps = [i for i in input()]
c = 0
for i in range(len(lamps) - 1):
if lamps[i] == lamps[i + 1] and i != len(lamps) - 2:
t = clone - set([lamps[i], lamps[i + 2]])
lamps[i + 1] = t.pop()
c += 1
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR LIST VAR VA... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | import sys
input = sys.stdin.readline
n = int(input())
s = input()
if n == 1:
print(0)
print(s)
exit()
answer = ["0"] * n
shomarande = 1
answer[0] = s[0]
a = 0
b = 0
if s[1] == s[0]:
b = 1
for i in range(2, n):
if s[i] == s[i - 1]:
c = min(a, b) + 1
a, b = b, c
if s[i] != an... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
l = list(input()) + ["l"]
D = ["R", "B", "G"]
c = 0
for i in range(1, n):
a = 0
if l[i] == l[i - 1]:
c += 1
l[i] = D[a]
while l[i] == l[i - 1] or l[i] == l[i + 1]:
a += 1
l[i] = D[a]
print(c)
print("".join(l[:n])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BI... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = list(input())
dp = [[(0) for i in range(3)] for i in range(n)]
rec = {"R": 0, "G": 1, "B": 2}
recInv = {(0): "R", (1): "G", (2): "B"}
dp[0][rec[s[0]]] = 0
dp[0][(rec[s[0]] - 1) % 3] = 1
dp[0][(rec[s[0]] + 1) % 3] = 1
for i in range(1, n):
dp[i][rec[s[i]]] = min(
dp[i - 1][(rec[s[i]] - 1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = input()
ss = s[0]
def ans(a, b):
if a == "R":
if b == "G":
return "B"
else:
return "G"
elif a == "G":
if b == "R":
return "B"
else:
return "R"
elif b == "R":
return "G"
else:
return "R"... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR STRING IF VAR STRING RETURN STRING RETURN STRING IF VAR STRING IF VAR STRING RETURN STRING RETURN STRING IF VAR STRING RETURN STRING RETURN STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = input()
b = [0] * n
r = [0] * n
g = [0] * n
if s[0] == "R":
b[0] = 1
g[0] = 1
elif s[0] == "G":
b[0] = 1
r[0] = 1
else:
r[0] = 1
g[0] = 1
for i in range(1, n):
if s[i] == "R":
r[i] = min(0 + g[i - 1], 0 + b[i - 1])
g[i] = min(1 + r[i - 1], 1 + b[i - 1])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR N... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | input()
s = input()
def cost(p, s):
return sum(1 for i, x in enumerate(p) if len(s) - 1 >= i and x != s[i])
def solve(s):
ss = set(["R", "G", "B"])
ls = list(s)
cnt = 0
current = ls[0]
for i, x in enumerate(ls[1:], 1):
if current == x:
ns = set([ls[i], ls[i - 1]])
... | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | def dif(n, m):
cnt = 0
for i, j in zip(n, m):
if j != i:
cnt += 1
return cnt
n = int(input())
inp = list(input())
if n == 1:
print(0)
print("".join(inp))
else:
s = inp[:]
cnt = 0
for i in range(1, n - 1):
if inp[i] == inp[i - 1]:
cnt += 1
... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER RETURN 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 FUNC_CALL STRING VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = list(input())
ans = ""
ans += s[0]
count = 0
for i in range(1, n):
if s[i] == s[i - 1] == "R":
if i + 1 < n:
if s[i + 1] == "G":
s[i] = "B"
else:
s[i] = "G"
else:
s[i] = "B"
count += 1
elif s[i] == s... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR ST... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | def main():
if input() == "1":
print(f"0\n{input()}")
return
a, b, *l = map({"R": 0, "G": 1, "B": 2}.get, input())
l.append((l[-1] + 1) % 3 if l else a)
res, cnt = ["RGB"[a]], 0
for c in l:
if b == a:
b = a - 2 if a == c else 3 - a - c
cnt += 1
... | FUNC_DEF IF FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_CALL VAR RETURN ASSIGN VAR VAR VAR FUNC_CALL VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR VAR LIST STRING VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | a = int(input())
s = input()
ans = []
for i in range(len(s)):
ans.append(s[i])
count = 0
for i in range(1, len(s)):
if ans[i] != ans[i - 1]:
continue
if i == len(s) - 1:
if ans[i] == ans[i - 1]:
if ans[i - 1] == "R":
ans[i] = "G"
if ans[i - 1] == "G":
... | ASSIGN VAR FUNC_CALL VAR 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF ... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | input()
garor = list(input())
gar = garor.copy()
for i in range(1, len(gar)):
if gar[i] == gar[i - 1]:
options = ["R", "G", "B"]
options.remove(gar[i - 1])
if i < len(gar) - 1 and gar[i + 1] in options:
options.remove(gar[i + 1])
gar[i] = options[0]
count = 0
for i in ran... | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
s = input()
s = list(s)
c = "RGB"
c = list(c)
count = 0
for i in range(1, len(s)):
c = "RGB"
c = list(c)
if s[i] == s[i - 1]:
count += 1
if i == n - 1:
c.remove(s[i - 1])
s[i] = c[0]
elif s[i + 1] != s[i - 1]:
c.remove(s[i - 1])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER... |
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained ... | n = int(input())
a = input()
z = [a[0]]
s = ["R", "B", "G"]
count = 0
for i in range(1, n):
if a[i] != z[-1]:
z.append(a[i])
else:
for j in s:
if i + 1 < n:
if j != a[i + 1] and j != a[i]:
z.append(j)
count += 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL... |
Recently you've discovered a new shooter. They say it has realistic game mechanics.
Your character has a gun with magazine size equal to $k$ and should exterminate $n$ waves of monsters. The $i$-th wave consists of $a_i$ monsters and happens from the $l_i$-th moment of time up to the $r_i$-th moments of time. All $a_i... | import sys
n, k = list(map(int, sys.stdin.readline().strip().split()))
L = []
R = []
A = []
for i in range(0, n):
x = list(map(int, sys.stdin.readline().strip().split()))
L.append(x[0])
R.append(x[1])
A.append(x[2])
L.append(R[-1])
i = n - 1
x = 0
y = 0
ans = 0
v = True
N = [(0) for i in range(0, n)]
w... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL... |
Recently you've discovered a new shooter. They say it has realistic game mechanics.
Your character has a gun with magazine size equal to $k$ and should exterminate $n$ waves of monsters. The $i$-th wave consists of $a_i$ monsters and happens from the $l_i$-th moment of time up to the $r_i$-th moments of time. All $a_i... | import sys
n, k = map(int, input().split())
L, R, A = [0] * n, [0] * n, [0] * n
for i in range(n):
L[i], R[i], A[i] = map(int, input().split())
dp = [0] * (n + 1)
for i in range(n - 1, -1, -1):
need = A[i]
if i < n - 1 and R[i] == L[i + 1]:
need += dp[i + 1]
if (R[i] - L[i] + 1) * k < need:
... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR 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... |
Recently you've discovered a new shooter. They say it has realistic game mechanics.
Your character has a gun with magazine size equal to $k$ and should exterminate $n$ waves of monsters. The $i$-th wave consists of $a_i$ monsters and happens from the $l_i$-th moment of time up to the $r_i$-th moments of time. All $a_i... | import sys
input = sys.stdin.buffer.readline
n, k = map(int, input().split())
tank = [(k, 0)]
new = []
L = [0] * n
R = [0] * n
A = [0] * n
for i in range(n):
L[i], R[i], A[i] = map(int, input().split())
for i in range(n):
new = []
l, r, a = L[i], R[i], A[i]
val = -1
for p, q in tank:
if p +... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL V... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
dp = [([-1] * (N + 1)) for _ in range(N + 1)]
for l in range(N):
dp[l][l + 1] = A[l]
for d in range(2, N + 1):
for l in range(N - d + 1):
for t in range(1, d):
if dp[l][l + t] == dp[l + t][l + d] and ... | IMPORT ASSIGN 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR N... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
arr = list(map(int, input().split()))
tracker = [([-1] * (n + 1)) for _ in range(2024)]
d = [[] for _ in range(n)]
for j, v in enumerate(arr):
tracker[v][j] = j
d[j].append(j)
for v in range(1, 2024):
for i in range(n):
j = tracker[v][i]
h = tracker[v][j + 1] if j != -1 else... | ASSIGN VAR FUNC_CALL VAR 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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR N... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
DP = [([-1] * (n + 1)) for i in range(n + 1)]
for i in range(n):
DP[i][i] = A[i]
for mid in range(1, n):
for i in range(n):
j = i + mid
if j == n:
break
for k in range(i, j + 1):
... | IMPORT ASSIGN 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR ... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
a = list(map(int, input().split(" ")))
new_a = [([0] * 600) for i in range(600)]
dp = [([2147483647] * 600) for i in range(600)]
for i in range(n):
new_a[i + 1][i + 1] = a[i]
dp[i + 1][i + 1] = 1
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
dp[i][j] = j - i + 1
for llen i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR AS... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
b = [int(_) for _ in input().split()]
d = [[(b[i] if i == j else -1) for i in range(n)] for j in range(n)]
def f(i, j):
if d[i][j] != -1:
return d[i][j]
d[i][j] = 0
for m in range(i, j):
l = f(i, m)
if f(m + 1, j) == l and l:
d[i][j] = l + 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | printn = lambda x: print(x, end="")
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda: input().strip()
DBG = True and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
def dp(l, r):
if dpa[l][r] >= 0:
... | ASSIGN VAR FUNC_CALL VAR VAR STRING 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER N... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_numb... | IMPORT 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_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
dp = []
a = []
def calcdp(l, r):
global dp, a
if l + 1 == r:
dp[l][r] = a[l]
return dp[l][r]
if dp[l][r] != 0:
return dp[l][r]
dp[l][r] = -1
for k in range(l + 1, r):
la = calcdp(l, k)
ra = calcdp(k, r)
if la > 0 and la == ra:
... | IMPORT ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR AS... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
a = list(map(int, input().split()))
dp = [([505] * n) for _ in range(n)]
Max = [([0] * n) for _ in range(n)]
for i in range(n):
dp[i][i] = 1
Max[i][i] = a[i]
for len in range(1, n + 1):
for i in range(n - len + 1):
j = i + len - 1
for k in range(i, j):
dp[i][j] =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR N... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
a = list(map(int, input().split()))
dp = [([False] * (n + 1)) for i in range(n + 1)]
def solve(l, r):
if dp[l][r]:
return dp[l][r]
if r - l == 1:
dp[l][r] = a[l], 1
return dp[l][r]
tmp = 10**9
for i in range(l + 1, r):
if solve(l, i)[0] == -1 or solve(i... | ASSIGN VAR FUNC_CALL VAR 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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VA... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | def f():
n = int(input())
A = [int(s) for s in input().split()]
memo = [[None for j in range(n + 1)] for i in range(n + 1)]
for i in range(n):
memo[i][i] = [A[i], A[i], 1]
for l in range(2, n + 1):
for left in range(0, n - l + 1):
right = left + l - 1
minLen =... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
readline = sys.stdin.buffer.readline
N = int(readline())
A = list(map(int, readline().split()))
dp = [([0] * N) for _ in range(N)]
for j in range(N):
dp[j][0] = A[j]
for l in range(1, N):
for j in range(l, N):
for k in range(j - l, j):
if dp[k][k - j + l] == dp[j][j - k - 1] > 0:... | IMPORT ASSIGN 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 BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | from sys import gettrace, stdin
if not gettrace():
def input():
return next(stdin)[:-1]
INF = 10000
def main():
n = int(input())
aa = [int(a) for a in input().split()]
dp = [([0] * (n + 1)) for _ in range(n)]
def calc_dp(i, j):
if i + 1 == j:
dp[i][j] = aa[i]
... | IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR IF VAR V... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
from sys import stdin, stdout
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().strip().split(" ")))
dp_arr = [[None for i in range(n)] for i in range(n)]
for i in range(n):
dp_arr[i][i] = arr[i], 1, arr[i]
def merge_small(c1, c2):
if c1[1] == 1 and c2[1] == 1:
if c1[0... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR FUNC_DEF IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF V... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
b = [int(_) for _ in input().split()]
d = [[(-1 if i != j else b[i]) for i in range(n)] for j in range(n)]
for l in range(1, n):
for s in range(n - l):
e = s + l
for m in range(s, e):
if d[s][m] == d[m + 1][e] and d[s][m] != -1:
d[s][e] = d[s][m] + 1
a = ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR B... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | from sys import stdin, stdout
def dfs(l, r, dp, a_a):
if l == r:
return a_a[l]
if l + 1 == r:
if a_a[l] == a_a[r]:
return a_a[l] + 1
else:
return -1
if dp[l][r] != 10**6:
return dp[l][r]
dp[l][r] = -1
for m in range(l, r):
r1 = dfs(l,... | FUNC_DEF IF VAR VAR RETURN VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR RETURN BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR BIN_OP NUMBER NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
input = sys.stdin.readline
n = int(input().strip())
a = [int(x) for x in input().strip().split()]
dp = [([0] * n) for i in range(n)]
for i in range(n):
dp[i][i] = [a[i], 1]
for i in range(1, n):
for j in range(n - i):
v, c = -1, i + 1
for k in range(i):
if dp[j][j + k][0]... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
pl = 1
if pl:
input = sys.stdin.readline
else:
sys.stdin = open("input.txt", "r")
sys.stdout = open("outpt.txt", "w")
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int, inp... | IMPORT ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR F... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
dp = [([1000] * (n + 1)) for i in range(n + 1)]
val = [([0] * (n + 1)) for i in range(n + 1)]
for i in range(n):
dp[i][i + 1] = 1
val[i][i + 1] = a[i]
for p in range(2, n + 1):
for i in range(n - p + 1):
j = ... | IMPORT ASSIGN 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VA... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | N = int(input())
L = list(map(int, input().split()))
DP = [([-1] * N) for i in range(N)]
for d in range(N):
for s in range(N - d):
e = s + d
if s == e:
DP[s][e] = L[s]
continue
for m in range(s, e):
l = DP[s][m]
r = DP[m + 1][e]
if ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR A... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
a = list(map(int, input().split()))
grip = [([-1] * (n - i)) for i in range(n)]
grip[0] = a.copy()
for level in range(1, n):
for left in range(n - level):
for split in range(level):
pl = grip[level - split - 1][left]
pr = grip[split][left + level - split]
... | ASSIGN VAR FUNC_CALL VAR 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 VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | N = int(input())
arr = list(map(int, input().split()))
dp = [[(-1) for x in range(N)] for y in range(N)]
for size in range(1, N + 1):
for i in range(N - size + 1):
j = i + size - 1
if i == j:
dp[i][j] = arr[i]
else:
for k in range(i, j):
if dp[i][k] !=... | 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 VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASS... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
li = list(map(int, input().split(" ")))
dp1 = []
for i in range(n):
lis = [-1] * n
dp1.append(lis)
dp2 = [0] * n
for i in range(n):
dp1[i][i] = li[i]
for i in range(n):
dp2[i] = i + 1
size = 2
while size <= n:
i = 0
while i < n - size + 1:
j = i + size - 1
k = i
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR... |
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array wil... | n = int(input())
a = [int(x) for x in input().split()]
dp = [([-1] * (n + 1)) for _ in range(n + 1)]
for i in range(n):
dp[i][i + 1] = a[i]
for leng in range(2, n + 1):
for l in range(n + 1):
if l + leng > n:
continue
r = l + leng
for mid in range(l + 1, n + 1):
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_... |
Read problems statements in Russian also.
Chef plays with the sequence of N numbers. During a single move Chef is able to choose a non-decreasing subsequence of the sequence and to remove it from the sequence. Help him to remove all the numbers in the minimal number of moves.
------ Input ------
The first line of ... | def CeilIndex(A, l, r, key):
while r - l > 1:
m = l + (r - l) // 2
if A[m] >= key:
r = m
else:
l = m
return r
def lds(A, size):
tailTable = [(0) for i in range(size + 1)]
len = 0
tailTable[0] = A[0]
len = 1
for i in range(1, size):
if... | FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ... |
Read problems statements in Russian also.
Chef plays with the sequence of N numbers. During a single move Chef is able to choose a non-decreasing subsequence of the sequence and to remove it from the sequence. Help him to remove all the numbers in the minimal number of moves.
------ Input ------
The first line of ... | n = int(input())
arr = list(map(int, input().split()))
lds = []
for i in arr:
lo, hi = 0, len(lds)
while lo < hi:
mid = lo + hi >> 1
if i < lds[mid]:
lo = mid + 1
else:
hi = mid
if lo == len(lds):
lds.append(i)
else:
lds[lo] = i
print(len(l... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUN... |
Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $2$ rows and $n$ columns, every element of which is either $0$ or $1$. In one move you can swap two values in neighboring cells.
More formally, let's number... | n = int(input())
a = [list(map(int, input().split())), list(map(int, input().split()))]
b = [list(map(int, input().split())), list(map(int, input().split()))]
s1 = 0
s2 = 0
stp = 0
for i in range(n):
s1 += a[0][i] - b[0][i]
s2 += a[1][i] - b[1][i]
if s1 * s2 < 0:
k = min(abs(s1), abs(s2))
if... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN ... |
Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $2$ rows and $n$ columns, every element of which is either $0$ or $1$. In one move you can swap two values in neighboring cells.
More formally, let's number... | n = int(input())
s = input()[::2], input()[::2]
t = input()[::2], input()[::2]
d = [0, 0]
total = 0
for y in range(n):
for x in (0, 1):
d[x] += (s[x][y] == "1") - (t[x][y] == "1")
if d[0] > 0 and d[1] < 0:
total += 1
d[0] -= 1
d[1] += 1
elif d[0] < 0 and d[1] > 0:
tot... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR STRING VAR VAR VAR STRING IF VAR NUMBER NUMBER VAR N... |
Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $2$ rows and $n$ columns, every element of which is either $0$ or $1$. In one move you can swap two values in neighboring cells.
More formally, let's number... | num = int(input())
m1 = [input().strip()[::2], input().strip()[::2]]
m2 = [input().strip()[::2], input().strip()[::2]]
top = 0
bot = 0
tot = 0
for j in range(num):
top += (m1[0][j] == "1") - (m2[0][j] == "1")
bot += (m1[1][j] == "1") - (m2[1][j] == "1")
if top > 0 and bot < 0:
tot += 1
top -... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL FUNC_CALL VAR NUMBER FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_CALL FUNC_CALL VAR NUMBER FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER V... |
Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $2$ rows and $n$ columns, every element of which is either $0$ or $1$. In one move you can swap two values in neighboring cells.
More formally, let's number... | import time
def main():
n = int(input())
curr = [[int(x) for x in input().split(" ")] for _ in range(2)]
want = [[int(x) for x in input().split(" ")] for _ in range(2)]
out = 0
s1 = 0
s2 = 0
for x in range(n):
out += abs(s1) + abs(s2)
s1 += curr[0][x]
s2 += curr[1][... | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN... |
There is a line consisting of N piles of coins on the table. For each i (1 β€ i β€ N), the i-th pile contains C_{i} coins, each with value V_{i}. There is also a bin under the table.
Alice and Bob play a game, moving alternately. A move consists of two steps:
Throw a prefix of the piles in the bin (the prefix can be emp... | import sys
sys.setrecursionlimit(10**6)
def f(arr, val, x, n, dp):
if x >= n:
return 0
if dp[x] != -1:
return dp[x]
a = 0
tm = 0
if dp[x + 1] == -1:
tm = f(arr, val, x + 1, n, dp)
dp[x + 1] = tm
else:
tm = dp[x + 1]
if arr[x] % 2 != 0:
a = v... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR... |
There is a line consisting of N piles of coins on the table. For each i (1 β€ i β€ N), the i-th pile contains C_{i} coins, each with value V_{i}. There is also a bin under the table.
Alice and Bob play a game, moving alternately. A move consists of two steps:
Throw a prefix of the piles in the bin (the prefix can be emp... | import sys
sys.setrecursionlimit(10**6)
def fun(i, n, l, x, c, dp):
if i == n:
return 0
if dp[i][x] != "a":
return dp[i][x]
if x == 1:
ans = min(
fun(i + 1, n, l, 1, c, dp), -l[i] * (c[i] % 2) + fun(i + 1, n, l, 0, c, dp)
)
else:
ans = max(
... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR STRING RETURN VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR ASSIG... |
There is a line consisting of N piles of coins on the table. For each i (1 β€ i β€ N), the i-th pile contains C_{i} coins, each with value V_{i}. There is also a bin under the table.
Alice and Bob play a game, moving alternately. A move consists of two steps:
Throw a prefix of the piles in the bin (the prefix can be emp... | T = int(input())
for i in range(T):
N = int(input())
C = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]
F = []
for i in range(N):
if C[i] % 2 == 1:
F += [V[i]]
M = len(F)
f = 0
g = 0
for i in range(M - 1, -1, -1):
h = max(g + F[i],... | 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR LIST VAR VAR ASSIGN VAR ... |
There is a line consisting of N piles of coins on the table. For each i (1 β€ i β€ N), the i-th pile contains C_{i} coins, each with value V_{i}. There is also a bin under the table.
Alice and Bob play a game, moving alternately. A move consists of two steps:
Throw a prefix of the piles in the bin (the prefix can be emp... | t = int(input())
for _ in range(t):
n = int(input())
c = list(map(int, input().split()))
v = list(map(int, input().split()))
maxt = 0
for i in range(n - 1, -1, -1):
if c[i] % 2 == 0:
continue
maxt = max(maxt, v[i] - maxt)
print(maxt) | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP ... |
There is a line consisting of N piles of coins on the table. For each i (1 β€ i β€ N), the i-th pile contains C_{i} coins, each with value V_{i}. There is also a bin under the table.
Alice and Bob play a game, moving alternately. A move consists of two steps:
Throw a prefix of the piles in the bin (the prefix can be emp... | from sys import setrecursionlimit, stdin
input = stdin.readline
setrecursionlimit(5 * 10**5)
inp = lambda: list(map(int, input().split()))
def solve(i, turn):
if i == n:
return 0
if dp[i][turn] != None:
return dp[i][turn]
if turn == 0:
ans = solve(nind[i], 1) + b[i]
ans = ... | ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NONE RETURN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR... |
There is a line consisting of N piles of coins on the table. For each i (1 β€ i β€ N), the i-th pile contains C_{i} coins, each with value V_{i}. There is also a bin under the table.
Alice and Bob play a game, moving alternately. A move consists of two steps:
Throw a prefix of the piles in the bin (the prefix can be emp... | import sys
sys.setrecursionlimit(1000000)
def mi():
return map(int, input().split())
def li():
return list(mi())
def si():
return str(input())
def ni():
return int(input())
def printyes():
print("YES")
def printno():
print("NO")
for t in range(int(input())):
n = ni()
c = l... | IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | 3
n = int(input())
books = [[], []]
for _ in range(n):
t, w = tuple(map(int, input().split()))
books[t - 1].append(w)
for _ in range(2):
books[_].sort()
ans = 10**9
for i in range(len(books[0]) + 1):
for j in range(len(books[1]) + 1):
hor = sum(books[0][:i]) + sum(books[1][:j])
ver = len... | EXPR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
t = []
for i in range(n):
e = list(map(int, input().split()))
t.append(e)
size = 0
size2 = 0
for i in t:
size += i[0]
size2 += i[1]
matrix = [([-1000] * (size + 1)) for i in range(n)]
for i in range(n):
matrix[i][0] = 0
for i in range(n):
for j in range(1, size + 1):
if ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR F... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
t = [0] * n
w = [0] * n
for i in range(n):
t[i], w[i] = map(int, input().split())
dp = [([float("inf")] * (2 * n + 1)) for i in range(n)]
dp[0][t[0]] = 0
dp[0][0] = w[0]
for i in range(n - 1):
for j in range(2 * n + 1):
a = dp[i][j]
if a != float("inf"):
dp[i + 1][j ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NU... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
t, w = [], []
for i in range(n):
a, b = map(int, input().split())
t.append(a)
w.append(b)
d = [([float("-inf")] * (2 * n + 1)) for i in range(n + 1)]
d[0][0] = 0
for i in range(n):
for j in range(2 * n + 1):
if j + t[i] <= 2 * n:
d[i + 1][j + t[i]] = max(d[i + 1][j +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMB... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
lis = []
for _ in range(n):
tt, ww = [int(x) for x in input().split()]
lis.append((tt, -ww))
lis.sort()
sum1, sum2 = [0], [0]
for i in range(n):
if lis[i][0] == 1:
sum1.append(sum1[-1] - lis[i][1])
else:
sum2.append(sum2[-1] - lis[i][1])
ans = 1000000000
k1, k2 = len(sum... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR V... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
a = list(tuple(map(int, input().split())) for i in range(n))
s = sum(t for t, w in a)
a = [(t / w, t, t + w) for t, w in a]
a.sort(reverse=True)
d, i = s, 0
while d >= 0:
s -= a[i][1]
d -= a[i][2]
i += 1
i -= 1
s += a[i][1]
d += a[i][2]
if a[i][1] == 2:
j = i + 1
while j < n and a[j... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
m = 2 * n + 1
res = set([(0, 0)])
for i in range(n):
t, w = map(int, input().split())
nxt = set()
for a, b in res:
if a + t <= m:
nxt.add((a + t, b))
if b + w <= m:
nxt.add((a, b + w))
res = nxt
print(min(t for t, w in res if t >= w)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP ... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | 3
n = int(input())
t = []
w = []
n1, n2 = 0, 0
for i in range(n):
x, y = list(map(int, input().split()))
t.append(x)
w.append(y)
n1 += x == 1
n2 += x == 2
w1 = []
w2 = []
for i in range(n):
if t[i] == 1:
w1.append(w[i])
else:
w2.append(w[i])
w1.sort(reverse=True)
w2.sort(reve... | EXPR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | R = lambda: map(int, input().split())
n = int(input())
unset = -1000000
bs = [[0, 0]] + [list(R()) for i in range(n)]
dp = [([unset] * 201) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(201):
t, w = bs[i + 1][0], bs[i + 1][1]
if dp[i][j] != unset:
dp[i + 1][j + t]... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CAL... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
dif = []
li1 = []
li2 = []
a1 = b1 = 0
for i in range(n):
a, b = map(int, input().split())
if a == 1:
li1.append(b)
else:
li2.append(b)
li1.sort(reverse=True)
li2.sort(reverse=True)
l1 = len(li1)
l2 = len(li2)
ans = 10000000000
for i in range(l1 + 1):
for j in range(l2 +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
s1 = sum([x[0] for x in a])
a.sort(key=lambda x: x[1] / x[0])
ans = 10**9
s2 = 0
l = -1
for i in range(n):
if s2 + a[i][1] <= s1 - a[i][0]:
s2 += a[i][1]
s1 -= a[i][0]
l = i
if l != -1 and a[l][0] == 1:
for i in ran... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
t1 = []
t2 = []
for _ in range(n):
t, w = map(int, input().split())
if t == 1:
t1.append(w)
else:
t2.append(w)
t1.sort()
t2.sort()
n1 = len(t1)
n2 = len(t2)
p1 = [0]
p2 = [0]
for i in range(n1):
p1.append(p1[-1] + t1[i])
for i in range(n2):
p2.append(t2[i] + p2[-1])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
tOne = [0]
tTwo = [0]
sizeOne = 1
sizetwo = 1
slon = 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
for i in range(n):
t = input().split()
if t[0] == "1":
tOne.append(int(t[1]))
sizeOne += 1
else:
tTwo.append(in... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | one = []
two = []
x = int(input())
for i in range(x):
a, b = list(map(int, input().split(" ")))
if a == 1:
one.append(b)
else:
two.append(b)
one.sort()
two.sort()
minx = 9000000
for ones in range(0, len(one) + 1):
for twos in range(0, len(two) + 1):
w = ones + 2 * twos
a ... | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ... |
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$
Shaass puts the boo... | n = int(input())
width, thickness = [], []
one, two = [], []
for _ in range(n):
ti, wi = map(int, input().split())
thickness.append(ti), width.append(wi)
if ti == 1:
one.append(wi)
if ti == 2:
two.append(wi)
one.sort(), two.sort()
one = [0] + one
two = [0] + two
for i in range(1, len(one... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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... | from sys import *
input = lambda: stdin.readline()
int_arr = lambda: list(map(int, stdin.readline().strip().split()))
str_arr = lambda: list(map(str, stdin.readline().split()))
get_str = lambda: map(str, stdin.readline().strip().split())
get_int = lambda: map(int, stdin.readline().strip().split())
get_float = lambda: ... | ASSIGN VAR FUNC_CALL VAR ASSIGN 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 VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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... | def quasiBinary(n):
ans = list()
while n:
tmp = str()
for i in str(n):
if int(i) >= 1:
tmp += "1"
else:
tmp += "0"
ans.append(tmp)
n -= int(tmp)
print(len(ans))
for i in ans:
print(i, end=" ")
n = int(input... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CA... |
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()
res = 0
arr = []
for i in num:
res = max(res, int(i))
arr.append(int(i))
s = ""
print(res)
for i in range(res):
numCur = 0
cur = ""
for j in range(len(arr)):
if arr[j] != 0:
cur += "1"
arr[j] -= 1
elif cur != "":
cur += "0"
s += c... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER 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())
m = 0
aa = [0] * 10005
t = 1
while n:
x = n % 10
m = max(m, x)
for i in range(x):
aa[i] += t
t *= 10
n //= 10
print(m)
for i in range(m):
print(aa[i], end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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()
maxx = 0
for i in n:
maxx = max(maxx, int(i))
d = [[(0) for i in range(len(n))] for j in range(maxx)]
for i in range(len(n)):
for j in range(int(n[i])):
d[j][i] = 1
print(maxx)
for i in d:
s = ""
for j in i:
if j == 0 and len(s) == 0:
continue
s += str(j)
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR 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(input())
nums = str(n)
m = -1
for i in nums:
m = max(m, int(i))
ans = [[(0) for i in range(len(nums))] for j in range(m)]
c = 0
for i in nums:
cur = int(i)
for i in range(cur):
ans[i][c] = 1
c += 1
print(len(ans))
for i in ans:
c = ""
for j in i:
c += str(j)
print(int... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN 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... | def main(k):
num = list(map(int, k))
res = []
while True:
st = []
flag = False
for i in range(len(num)):
if num[i] > 0:
st.append("1")
num[i] -= 1
flag = True
else:
st.append("0")
if not f... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST WHILE NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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())
L = []
while n > 0:
cb = "".join([["0", "1"][int(k) > 0] for k in str(n)])
L.append(cb)
n -= int(cb)
print(len(L))
print(" ".join(L)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL STRING LIST STRING STRING FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR 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... | n = input()
def ans(n):
li = []
maxm = int(n[0])
for i in n:
li.append(int(i))
maxm = max(maxm, int(i))
print(maxm)
l = len(li)
deepshri = []
for i in range(maxm):
s = ""
for j in range(l):
if li[j] != 0:
s += "1"
... | ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR 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 = int(input())
l = []
while n != 0:
b = ""
for i in str(n):
b += str(min(int(i), 1))
n -= int(b)
l.append(b)
print(len(l))
print(*l) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER 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... | intab = "0123456789"
outtab = "0111111111"
trantab = str.maketrans(intab, outtab)
def quasi(x):
return int(x.translate(trantab))
ans = []
n = int(input())
while n > 0:
val = quasi(str(n))
n -= val
ans.append(val)
print(len(ans))
print(" ".join(map(str, ans))) | ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR F... |
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()
m = max(int(x) for x in n)
ls = [""] * m
for x in n:
y = int(x)
for i in range(y):
ls[i] += "1"
for i in range(y, m):
ls[i] += "0"
print(m)
for x in ls:
print(int(x), end=" ") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR 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 = input()
l = len(n)
ans = []
for i in range(len(n)):
ans.append(int(n[i:]) // 10 ** (len(n[i:]) - 1))
out = []
while any(ans):
temp = []
for i in range(l):
if ans[i] > 0:
temp.append(10 ** (l - i - 1))
ans[i] -= 1
out.append(sum(temp))
print(len(out))
print(*out) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CA... |
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... | p = [
1,
10,
11,
100,
101,
110,
111,
1000,
1001,
1010,
1011,
1100,
1101,
1110,
1111,
10000,
10001,
10010,
10011,
10100,
10101,
10110,
10111,
11000,
11001,
11010,
11011,
11100,
11101,
11110,
11111,... | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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... | n = int(input())
c = 0
l = []
while n > 0:
c = c + 1
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
print(c)
print(*l) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP 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 B... |
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())))
_max = max(n)
print(_max)
for i in range(_max):
l = [0] * len(n)
for j in range(len(n)):
if n[j] > 0:
l[j] = 1
n[j] -= 1
else:
l[j] = 0
for j in range(len(l)):
if l[j] == 1:
l = l[j:]
break
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR 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())
s = list(map(int, str(n)))
print(max(s))
l = len(s)
for i in range(max(s)):
f = 0
for i in range(l):
if s[i] > 0:
s[i] -= 1
print(1, end="")
f = 1
elif f:
print(0, end="")
print(" ", end="") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING ASSI... |
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... | __author__ = "ploskov"
def termination_condition(digit_list: "list"):
for digit in digit_list:
if digit > 0:
return False
return True
def main():
number = input()
digit_list = [int(digit) for digit in number]
answer = []
while not termination_condition(digit_list):
... | ASSIGN VAR STRING FUNC_DEF STRING FOR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ... |
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().strip()
a = list(n)
c = [int(i) for i in a]
results = []
while sum(c) > 0:
qb = [(0) for i in range(len(c))]
for i in range(len(c)):
if c[i] > 0:
qb[i] = 1
c[i] -= 1
qbs = int("".join([str(c) for c in qb]))
results.append(qbs)
print(len(results))
print(" ".joi... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER 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... | n = int(input())
inf = 10**9 + 9
ans = []
while n > 0:
j = n
b = 0
t = 1
while j > 0:
b += t * int(j % 10 != 0)
t *= 10
j //= 10
ans.append(b)
n -= b
print(len(ans))
for i in ans:
print(i, end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CAL... |
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()
k = []
s = ""
a = [int(i) for i in n]
for i in range(max(a)):
for j in range(len(a)):
if a[j] > 0:
s += "1"
else:
s += "0"
a[j] -= 1
k.append(int(s))
s = ""
print(len(k))
for i in range(len(k)):
print(k[i], end=" ") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR FUNC_CALL 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(input())
l = []
while N:
n = N
m = 0
p = 1
while n:
if n % 10:
m += p
n //= 10
p *= 10
l.append(m)
N -= m
l.sort()
print(len(l))
print(*l) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL 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()
l = []
for i in range(9):
s = ""
for j in n:
if ord(j) - i - 48 > 0:
s += "1"
else:
s += "0"
l.append(s)
for i in range(9):
l[i] = int(l[i])
while True:
try:
l.remove(0)
except:
break
print(len(l))
print(*l) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR WHILE NUMBER EXPR FUNC_CALL VAR NUMBER EXPR 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... | def main():
num = [int(x) for x in list(input())]
quasi_binary = []
s = ""
for i in range(max(num)):
for j in range(len(num)):
if num[j] > 0:
s += "1"
num[j] -= 1
else:
s += "0"
quasi_binary.append(str(int(s)))
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING EXPR FUNC_CA... |
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 = len(str(n)) - 1
k = int(str(n)[0:1])
a = [10**l] * k
n = n - k * a[0]
while n > 0:
l = len(str(n)) - 1
k = int(str(n)[0:1])
b = 10**l
if k > len(a):
z = k - len(a)
for i in range(z):
a.append(b)
n = n - b
for i in range(len(a)):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSI... |
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()
a = list(a)
for i in range(len(a)):
a[i] = int(a[i])
ans = max(a)
print(ans)
for j in range(ans):
aa = [0] * len(a)
for i in range(len(a)):
if a[i] != 0:
aa[i] = 1
a[i] -= 1
print(int("".join(str(x) for x in aa)), end=" ") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIG... |
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] * 10
t = 1
m = 1
while n > 0:
d = n % 10
for i in range(d):
a[i] += t
n //= 10
t *= 10
m = max(m, d)
print(m)
for i in a:
if i != 0:
print(i, end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR V... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.