description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
for _ in range(int(input())): s = input() N = len(s) dp = [0] * (N + 1) for i in range(2, N): if s[i - 4 : i + 1] == "twone": dp[i - 2] = dp[i - 3] dp[i + 1] = dp[i] elif s[i - 2 : i + 1] == "one": dp[i] = dp[i - 1] + 1 dp[i + 1] = dp[i] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR V...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for _ in range(t): s = input() l = len(s) r = set() for i in range(l - 2): if s[i] == "o": if s[i + 1] == "n": if s[i + 2] == "e": if i > 0: if s[i - 1] != "w": r.add(i + 2) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUN...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for ii in range(t): a = input() num1, num2, num = 0, 0, 0 ans = set() i = -1 while 1: if i >= len(a) - 1: break i = a.find("one", i + 1) if i == -1: break if i > 0 and a[i - 1] == "o": ans.add(i + 1) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NU...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): indexes = set() s = input() for j in range(len(s) - 2): if s[j : j + 3] == "two": if j != len(s) - 3: if s[j + 3] != "o": indexes.add(j + 3) else: indexes.add(j + 2) el...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FU...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(0, t): s = input() bal = 0 a = [] n = len(s) for j in range(0, n): if s[j] == "o": bal = 1 elif bal == 1 and s[j] == "n": bal += 1 elif bal == 2 and s[j] == "e": bal = 0 a.append([j - 2, j, 1]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER EXPR...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
for q in range(int(input())): s = input() ans = 0 i = 0 j = 0 ans = [] while i < len(s) - 1: if i + 4 < len(s) and s[i : i + 5] == "twone": ans.append(i + 3) i += 4 elif i + 2 < len(s) and s[i : i + 3] == "two": ans.append(i + 2) i ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
def f(): s = input() ans = [0] * len(s) i = 0 cur = 0 while i < len(s): sub = s[i : i + 3] if sub == "one": ans[cur] = i + 1 + 1 i = i + 3 cur += 1 elif sub == "two": if s[i + 3 : i + 5] == "ne": ans[cur] = i + 2...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR STRING IF VAR BIN_OP VAR NUMB...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for j in range(t): n = list(input()) r = 0 ans = [] for i in range(len(n) - 2): if ( len(n) - 4 > i and n[i] == "t" and n[i + 1] == "w" and n[i + 2] == "o" and n[i + 3] == "n" and n[i + 4] == "e" ): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR N...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): s = input() one = set() two = set() cnt = 0 ans = [] for i in range(len(s) - 2): if s[i : i + 3] == "one": one.add(i + 1) elif s[i : i + 3] == "two": two.add(i + 1) both = set() for i in one: if i - 2 in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP V...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): cnt = 0 a = [] s = input() j = 0 while j < len(s) - 2: if j < len(s) - 4 and s[j : j + 5] == "twone": a.append(j + 2 + 1) cnt += 1 j += 5 continue elif s[j : j + 3] == "one" or s[j : j + 3] == "two": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VA...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
for _ in range(int(input())): stro = list(input()) ans = [] for j in range(len(stro)): if j <= len(stro) - 5: if stro[j : j + 5] == ["t", "w", "o", "n", "e"]: ans.append(j + 3) stro[j + 2] = "." if j <= len(stro) - 3: if stro[j : j + 3]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER S...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
for i in range(int(input())): s = input() arr = [] for j in range(len(s)): if s[j] == "o": if ( j > 1 and j < len(s) - 2 and s[j + 1] == "n" and s[j + 2] == "e" and s[j - 1] == "w" and s[j - 2...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR ...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) strings = [input() for _ in range(t)] for string in strings: n = len(string) ans = string.count("one") + string.count("two") - string.count("twone") print(ans) i = 0 f = True answers = [] while i < n - 2: if string[i : i + 3] == "one": answers.append(i + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER IF...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): s = input() sy = 0 A = set() for j in range(len(s) - 2): if s[j] + s[j + 1] + s[j + 2] == "one": if s[j - 1] == "o": A.add(j + 1) else: A.add(j) elif s[j] + s[j + 1] + s[j + 2] == "two": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for g in range(0, t): s = input() i = 0 n = len(s) ans = [] while i < n - 2: if s[i : i + 3] == "two": if s[i + 2 : i + 5] == "one": ans += [i + 2 + 1] i += 5 else: ans += [i + 1 + 1] i +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER VAR N...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
def main(): t = int(input()) s1 = "one" s2 = "two" for i in range(t): s = input() n = len(s) count = 0 i = 2 ans = [] while i < n: s3 = s[i - 2 : i + 1] if s3 == s1 or s3 == s2: count += 1 if i + 2 < ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
def main(): t = int(input()) for i in range(t): s = input() c = 0 idx = [] for j in range(len(s)): if s[j] == "o": if j > 1 and j < len(s) - 2: if s[j - 2 : j] == "tw" and s[j + 1 : j + 3] == "ne": idx.append...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STR...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for _ in range(t): poz = [] x = input() i = 1 d = len(x) while i < d - 1: q = x[i] if q == "n": if x[i - 1] == "o" and x[i + 1] == "e": poz.append(i + 1) if q == "w": if x[i - 1] == "t" and x[i + 1] == "o": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR S...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for r in range(t): q = input() o = [w for w in range(len(q)) if q[w] in "nw"] e = [] for w in o: if q[w - 1 : w + 2] in ["two", "one"]: e += [[w, 1]] e.sort() for w in range(len(e) - 1): if e[w][0] + 2 == e[w + 1][0]: e[w][0] += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST STRING STRING VAR LIST LIST VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP F...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for _ in range(t): s = input() i = 0 ans = [] n = len(s) while True: if i + 1 + 1 >= n: break if s[i] + s[i + 1] + s[i + 2] == "one": ans.append(i + 1) i += 3 elif s[i] + s[i + 1] + s[i + 2] == "two": if i + 4 <...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VA...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): s = input() one, twone = 0, 0 a = [] for j in range(len(s)): st = s[j] if twone == 0 and st == "t": twone = 1 elif twone == 1 and st == "w": twone = 2 elif twone == 2 and st == "o": twone = 3 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMB...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
a = int(input()) for i in range(a): g = input() p = 0 one = str("one") two = str("two") ch = [] for i in range(len(g) - 2): if g[i] == "o": if g[i + 1] == "n": if g[i + 2] == "e": if p == 0: ch.append(i + 2) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STR...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): s = input() c = 0 m = [] j = 0 while j < len(s) - 4: if ( s[j] == "t" and s[j + 1] == "w" and s[j + 2] == "o" and s[j + 3] == "n" and s[j + 4] == "e" ): c += 1 m.ap...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VA...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
n = int(input()) for i in range(n): x = input() bfx = x.split("twone") x = list(x) res = [] if len(bfx) > 0: last = 0 for g in range(len(bfx) - 1): res.append(last + len(bfx[g]) + 3) last += len(bfx[g]) + 5 x = list("tw-ne".join(bfx)) for g in rang...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VA...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for j in range(t): s = input() l = len(s) ans = 0 A = [] i = 0 while i < l - 2: if s[i : i + 3] == "one": ans += 1 A.append(i + 2) i += 3 elif s[i : i + 3] == "two": ans += 1 if i + 5 <= l and s[i + 2 : ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMB...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): re = [] s = str(input()) l = len(s) for j in range(l - 4): if s[j : j + 5] == "twone": re.append(j + 2) elif s[j : j + 3] == "two": re.append(j + 1) elif s[j : j + 3] == "one": if j >= 2: if s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
for __ in range(int(input())): ar = list(input()) ans = [] x = len(ar) for i in range(x - 4): if ar[i] + ar[i + 1] + ar[i + 2] + ar[i + 3] + ar[i + 4] == "twone": ans.append(i + 3) for j in range(x - 4): if ar[j] + ar[j + 1] + ar[j + 2] == "two" and ar[j + 3] + ar[j + 4] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CA...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
def main(): t = int(input()) for i in range(t): s = input() const = len(s) ans = set() i = 0 while i < const: if i + 4 < const: if s[i : i + 5] == "twone": ans.add(str(i + 3)) i += 3 elif ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VA...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): s = input() ans = [] for i in range(1, len(s) - 1): if ( s[i] == "w" and s[i - 1] == "t" and s[i + 1] == "o" and i + 3 < len(s) and s[i + 2] == "n" and s[i + 3] == "e" ): a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP V...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) ans = [] for i in range(t): s = input() ans.append([]) if len(s) > 2: j = 0 while j < len(s) - 2: if j < len(s) - 4 and s[j : j + 5] == "twone": ans[-1].append(j + 3) j += 4 elif s[j : j + 3] == "two": a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER BIN_...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
for _ in range(int(input())): s = input() a = [] i = 0 while i <= len(s) - 1: if s[i : i + 5] == "twone": a.append(i + 3) i += 5 elif s[i] == "o" and s[i : i + 3] == "one": a.append(i + 2) i += 3 elif s[i] == "t" and s[i : i + 3] ==...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMB...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(0, t): j = 0 r = input() d = len(r) s = [] while j < d - 2: if r[j] == "o" and r[j + 1] == "n" and r[j + 2] == "e": s.append(j + 2) j += 3 elif r[j] == "t" and r[j + 1] == "w" and r[j + 2] == "o": if j < d - 4 and r[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR V...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
def check_string(string): indexes = get_matches(string) length = len(indexes) print(length) print(" ".join(indexes)) def get_matches(string): indexes = [] for index in range(0, len(string) - 2): check_fragment = string[index : index + 3] is_one = check_fragment == "one" ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING IF VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR I...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): s = list(input()) ans = [] for i in range(len(s) - 4): if s[i : i + 5] == ["t", "w", "o", "n", "e"]: ans.append(i + 3) s[i + 2] = "q" for i in range(len(s) - 2): if s[i : i + 3] == ["o", "n", "e"] or s[i : i + 3] == ["t", "w", "...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING FOR ...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): stroka = "cc" + input() + "cc" s = list(stroka) r = 0 indexes = [] for j in range(len(s)): if s[j] == "o": if s[j + 1] == "n" and s[j + 2] == "e": if s[j - 1] == "o": indexes.append(j) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NU...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): s = input() x = len(s) f1, f2, fl3 = False, False, False j = 0 cnt = 0 res = [] colo = 0 while j < x: if j + 2 <= x: if s[j : j + 3] == "two": if j + 3 < x: if s[j + 3] == "o": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NU...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
k = int(input()) def pandora(v): if len(v) < 3: print(0) return if len(v) == 3: if ( v[0] == "o" and v[1] == "n" and v[2] == "e" or v[0] == "t" and v[1] == "w" and v[2] == "o" ): print("1\n1") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR ...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for _ in range(t): s = input() a = [] n = len(s) if s.count("two") + s.count("one") == 0: ans = 0 else: ans = 0 for i in range(n): if i + 4 < n: if s[i : i + 5] == "twone": ans += 1 a.append(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER STRING VAR...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
n = int(input()) for _ in range(n): s = input() ans = [] i = 0 while i < len(s): if s[i : i + 3] == "one": ans.append(i + 1) i += 3 elif s[i : i + 3] == "two": if s[i : i + 5] == "twone": ans.append(i + 2) i += 5 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CA...
You are given a non-empty string $s=s_1s_2\dots s_n$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $s$ if there is an inte...
t = int(input()) for i in range(t): a = input() an = 0 nm = [] if len(a) > 2: v = 2 if a[v - 2] + a[v - 1] + a[v] == "one": an += 1 nm.append(v) if a[v - 2] + a[v - 1] + a[v] == "two": an += 1 nm.append(v) if len(a) > 3: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER V...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
def dist(a, f, i): for j in range(i + 1, len(a)): if f == a[j]: return j n, k = map(int, input().split()) a = list(map(int, input().split())) books = set() l = 0 pref = [(0) for i in range(n)] for i in range(n - 1, -1, -1): pref[a[i] - 1] = max(pref[a[i] - 1], i) res = 0 for i in range(n):...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR ASSIGN 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VA...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
def index(e, l, s): res = [] off = s while True: try: off = l.index(e, off + 1) except ValueError: break else: res.append(off) if len(res) != 0: return res[0] else: return 10**9 ni = list(map(int, input().strip().split(" "...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER RETURN BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VA...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
n, k = [int(x) for x in input().split()] requests = [int(x) for x in input().split()] req_list = {} def find_last(bucket): last_book = None last_date = None nonlocal req_list i = 0 for item in bucket: if last_book is None: last_book = item if len(req_list[item]) < 1...
ASSIGN 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 DICT FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR VAR IF VAR NONE ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING RETURN VAR VAR ASSIGN VA...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
R = lambda: map(int, input().split()) stack = [] n, k = R() l = list(R()) curr, tot = 0, 0 for i in range(n): if l[i] not in stack: if curr < k: curr = curr + 1 else: c, z = 0, -1 for j in range(k): if stack[j] not in l[i:]: z =...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
n, k = (int(i) for i in input().split()) zapross = [int(i) for i in input().split()] lave = 0 curh = set() for i in range(n): if zapross[i] in curh: continue if len(curh) != k: lave += 1 curh.add(zapross[i]) else: lpos = -1 cc = -1 for j in curh: t...
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN ...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
R = lambda: map(int, input().split()) n, k = R() a = list(R()) l = [] m = 0 for i in range(n): if a[i] not in l: m += 1 if len(l) < k: l.append(a[i]) else: curmin = n curindex = 0 found = [n] * len(l) for j in range(len(a[i + 1 :]))...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR F...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) + [-1] cost = 0 lib = [] for i in range(n): if a[i] in lib: continue if len(lib) < k: lib.append(a[i]) cost += 1 else: far = 0 for ind, j in enumerate(lib): o = i + 1 wh...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
import sys def solve(): n, k = map(int, input().split()) a = [(int(i) - 1) for i in input().split()] kinds = len(set(a)) if kinds <= k: print(kinds) return books = [False] * n have = 0 cost = 0 for i, ai in enumerate(a): if books[ai]: continue ...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL ...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
n, k = map(int, input().split()) a = list(map(int, input().split())) z = [0] * 81 kz, ans = 0, 0 for i in range(n): if z[a[i]]: continue ans += 1 if k > kz: z[a[i]] = 1 kz += 1 else: h = -1 for j in range(1, n + 1): if z[j]: m = n + 1 ...
ASSIGN 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 NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
n, k = map(int, input().split()) a = list(map(int, input().split())) inventory = set() bought = 0 for i in range(n): if a[i] not in inventory: if len(inventory) == k: farthest_time = 0 farthest = 0 for v in inventory: try: far = a.index...
ASSIGN 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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR...
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n. We will look...
n, k = map(int, input().split()) arr = [int(z) for z in input().split()] books = set() def latest(n, arr, i, books): w = {} for pos in range(i + 1, n): if w.get(arr[pos]): continue else: w[arr[pos]] = pos for j in books: if not w.get(j): w[j] = 1...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NU...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) res = [-1] * 256 arr = list(map(int, input().split())) for j in arr: if res[j] != -1: print(res[j], end=" ") continue tmp = max(0, j - k + 1) for i in range(tmp, j + 1): if res[i] != -1 and res[i] != i: tmp += 1 continue ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP V...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
import sys [n, k] = map(int, input().strip().split()) pis = list(map(int, input().strip().split())) if k == 1: print(" ".join(map(str, pis))) return N = 256 gamma = [(-1) for _ in range(N)] done = [(False) for _ in range(N)] revdone = [(False) for _ in range(N)] notset = 256 pends = {} def get_bounds(i): ...
IMPORT ASSIGN LIST 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 IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) ps = list(map(int, input().split())) if k == 1: print(" ".join([str(i) for i in ps])) return g = [None for i in range(256)] f = [None for i in range(256)] ans = [] for i in range(n): p = ps[i] if g[p] is not None: ans.append(g[p]) f[p] = 1 else: ...
ASSIGN 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 IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CA...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
read = lambda: map(int, input().split()) n, k = read() p = list(read()) r = [-1] * 256 for i in p: for u in range(i, max(i - k, -1), -1): if r[u] >= 0: u += 1 break if u <= i: if u > 0 and r[u - 1] + k > i: r[i] = r[u - 1] else: for j in ra...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBE...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = list(map(int, input().split())) p = list(map(int, input().split())) processed = set() color = {} length = {} ans = [] def exists(p, elt, d): for e in p: if e > elt: if e <= elt + d: return True elif e - d <= elt + d: return False return Fa...
ASSIGN 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 ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FUNC_DEF FOR VAR VAR IF VAR VAR IF VAR BIN_OP VAR VAR RETURN NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN N...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
R = lambda: map(int, input().split()) n, k = R() a = list(range(0, 257)) v = [1] * 257 for p in R(): if v[p]: t = p while t >= 0 and p - a[t] <= k - 1: t -= 1 t += 1 for i in range(t, p + 1): a[i] = a[t] v[i] = 0 print(a[p], end=" ")
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VA...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = list(map(int, input().split())) P = list(map(int, input().split())) parent = list(range(256)) sz = [1] * 256 def rt(x): if x != parent[x]: parent[x] = rt(parent[x]) return parent[x] def u(rx, ry): parent[ry] = rx sz[rx] += sz[ry] ans = [0] * n for i, p in enumerate(P): rx = rt(p...
ASSIGN 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 FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def main(): n, k = list(map(int, input().split())) p = list(map(int, input().split())) solve(n, k, p) def solve(n, k, p): group = 256 * [None] r = p[:] for i, pi in enumerate(p): if group[pi] is not None: r[i] = group[pi][0] else: lo = pi whi...
FUNC_DEF ASSIGN 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 EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER LIST NONE ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR VAR VAR NUMBER ASSIGN ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().strip().split()) data = map(int, input().strip().split()) sol = [] mapping = [(-1, 1000)] * 256 for x in data: if mapping[x][0] == -1: for i in range(max(x - k + 1, 0), x + 1): if mapping[i][0] == -1: if i > 0 and mapping[i - 1][1] + (x - i + 1) <= k: ...
ASSIGN VAR 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 LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER IF ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def main(): n, k = [int(x) for x in input().split()] p = [int(x) for x in input().split()] res = [] group = [None] * 256 for pi in p: if group[pi] is not None: res.append(group[pi]) continue t = max(-1, pi - k) for i in range(pi - 1, t, -1): ...
FUNC_DEF ASSIGN 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 LIST ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR VAR IF VAR VAR NONE EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def getIntList(): return list(map(int, input().split())) n, k = getIntList() p = getIntList() choosed = [False] * 256 left = [i for i in range(256)] for i, x in enumerate(p): if not choosed[x]: best = x for j in range(x - 1, max(-1, x - k), -1): if not choosed[j]: b...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) l1 = list(map(int, input().split())) assigned = {} result = [0] * n i = 0 for i in range(n): flag = 0 x = k if l1[i] not in assigned: temp = l1[i] to_assign = [] while temp >= 0 and x > 0 and temp not in assigned: to_assign.append(temp) ...
ASSIGN 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 DICT ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER VA...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
import sys n, k = list(map(int, next(sys.stdin).rstrip().split())) xs = list(map(int, next(sys.stdin).rstrip().split())) mapka = {} lengths = {} result = [] for x in xs: if x in mapka: result.append(mapka[x]) else: left = max(0, x - k + 1) range_potential = x - left for i in ran...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = [int(x) for x in input().split()] ns = [int(x) for x in input().split()] done = [None] * 256 ans = [None] * n for i in range(n): c = ns[i] if done[c] == None: j = c while True: if j < 0 or c - j >= k or done[j] != None and done[j] != -1: break j -= ...
ASSIGN 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 BIN_OP LIST NONE NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NONE ASSIGN VAR VAR WHILE NUMBER IF VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NONE ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) a = list(map(int, input().split())) range1 = [-1] * 256 final = [0] * n for i in range(n): if range1[a[i]] == -1: for j in range(a[i], max(-1, a[i] - k), -1): if range1[j] != -1: if range1[j] + k > a[i]: range1[a[i]] = range1[j...
ASSIGN 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = [int(s) for s in input().split()] p = [int(s) for s in input().split()] map = {} res = [] for pi in p: if map.get(pi) is None: key = pi for j in range(pi, pi - k, -1): if j < 0: break if map.get(j) is None: key = j else: ...
ASSIGN 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 DICT ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR IF VAR VAR BIN...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
N, K = input().split() N, K = int(N), int(K) P = [int(x) for x in input().split()] A = [None] * 256 A[0] = 0 for i in range(N): pn = P[i] if A[pn] is None: for j in range(K - 1, -1, -1): if pn < j: continue if A[pn - j] is None: A[pn - j] = pn - j ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBE...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) l = [int(x) for x in input().split()] maps = [] for _ in range(256): maps.append(["empty", 0]) output = [] for innum in l: if maps[innum][0] == "chosen": outnum = maps[innum][1] elif maps[innum][0] == "potential": outnum = maps[innum][1] i = innum ...
ASSIGN VAR 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 FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST STRING NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR VAR VAR ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def main(): n, k = map(int, input().split()) pixels = list(map(int, input().split())) colors = [-1] * 256 colors[0] = 0 for p in pixels: if colors[p] != -1: continue i = p - 1 while i > max(0, p - k + 1) and colors[i] == -1: i -= 1 g = colors[i...
FUNC_DEF ASSIGN 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 NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VA...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def get_best_color(pixel): best_color = pixel - max_group_length + 1 return best_color if best_color > 0 else 0 def get_used_color(pixel): best_color = get_best_color(pixel) for color in range(pixel, best_color - 1, -1): if color in colors: return color for color in range(get_b...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
a = [(0) for i in range(0, 256)] n, k = input().split(" ") k = int(k) for c in input().split(" "): c = int(c) if a[c] != 0: print(a[c] - 1, end=" ") else: for x in range(c, c - k, -1): if a[x] == 0: i = x else: if c - a[x] + 1 < k: ...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NU...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) arr = list(map(int, input().split())) par = [i for i in range(260)] path = [(-1) for i in range(260)] for i in range(n): j = arr[i] if path[j] >= 0: par[j] = par[path[j]] continue jump = 1 while j > 0 and path[j] == -1 and jump < k: path[j] = arr[...
ASSIGN 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 VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) p = list(map(int, input().split())) ranged = [None] * 256 check = False check1 = False for i in range(256): ranged[i] = [0, None] result = "" for i, pi in enumerate(p): if ranged[pi][0] == 2: idx = pi while ranged[idx][0] == 2: ranged[idx][0] = 1 ...
ASSIGN 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 NONE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST NUMBER NONE ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBE...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = [int(x) for x in input().split()] ps = [int(x) for x in input().split()] mapping = [(-1) for _ in range(256)] res = [] for p in ps: if mapping[p] == -1: j = p - k + 1 while j < 0 or mapping[j] != -1 and mapping[j] + k <= p: j += 1 for i in range(j, p + 1): mapp...
ASSIGN 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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER FOR VAR...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def solve(): num_pixels, max_group_size = (int(x) for x in input().split()) pixels = [int(x) for x in input().split()] groups = [None for _ in range(256)] for pixel in pixels: if groups[pixel] is None: smallest_of_group = pixel while ( smallest_of_group >=...
FUNC_DEF ASSIGN 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 NONE VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR NONE ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NONE VAR NUMBER IF VAR NUMBER VAR VAR NONE BIN_OP BIN_OP VAR VAR ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def inalist(l, a): for i in l: if a in i: return min(i) return None n, k = map(int, input().split()) k -= 1 a = list(map(int, input().split())) l = list() for i in range(n): found = 0 placed = False ina = inalist(l, a[i]) if ina is None: for j in range(a[i], max(a[i...
FUNC_DEF FOR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR RETURN NONE ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def read(): return [int(v) for v in input().split()] def main(): n, k = read() a = read() cache = {} for i in range(n): if a[i] not in cache: for v in range(1, k): value = a[i] - v if value in cache: if a[i] - cache[value] < k...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = [int(i) for i in input().split()] p = [int(i) for i in input().split()] ans = [-1] * (max(p) + 1) ans[0] = 0 for i in range(n): if ans[p[i]] < 0: position = p[i] - k + 1 for j in range(max(0, p[i] - k + 1), p[i] + 1): if ans[j] < 0: position = j bre...
ASSIGN 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 BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR F...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) cent = [1] * 256 f = [x for x in range(256)] ans = [None] * n def find(x): if f[x] == x: return x else: return find(f[x]) def union(x, y): f1 = find(x) f2 = find(y) if f1 != f2: f[max(f1, f2)] = mi...
ASSIGN 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 NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FUNC_DEF IF VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) p = map(int, input().split()) ans = [(0) for i in range(n)] f = [(-1) for i in range(256)] i = -1 for x in p: i += 1 if f[x] < 0: l = x while l > 0 > f[l - 1] and x - l < k - 1: l -= 1 if l > 0 and x - f[l - 1] < k and f[l - 1] >= 0: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = [int(i) for i in input().split()] p = [int(i) for i in input().split()] colors = [(-1) for i in range(256)] for i in range(len(p)): if colors[p[i]] == -1: stack = [p[i]] val = p[i] for j in range(1, k): if p[i] - j < 0: break elif colors[p[i] - ...
ASSIGN 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 VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = list(map(int, input().split())) arr = list(map(int, input().split())) val = [-1] * 256 val[0] = 0 for i in range(0, n): if val[arr[i]] > -1: print(val[arr[i]], end=" ") else: flag = 0 for j in range(1, k): if val[arr[i] - j] > -1: if arr[i] - val[arr[i]...
ASSIGN 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 NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR F...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
n, k = map(int, input().split()) p = list(map(int, input().split())) arr = [[] for i in range(256)] ans = [] for i in p: j = i if len(arr[i]) == 0: c = 0 while c < k and j >= 0: if len(arr[j]) + c > k: break if len(arr[j]) != 0: arr[i].exte...
ASSIGN 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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR V...
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
def main(): n, k = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] p = [-1] * 256 p[0] = 0 for x in a: if p[x] < 0: for y in range(x - 1, max(-1, x - k), -1): if p[y] >= 0: if p[y] + k > x: p[x] =...
FUNC_DEF ASSIGN 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) p = list(map(int, input().split())) used = [False] * n print(p[0]) last_v = n - 1 for i, j in enumerate(p): used[j - 1] = True while used[last_v]: last_v -= 1 if i == n - 2 or used[p[i + 1] - 1]: print(f"{j} {last_v + 1}") used[last_v] = True else: print(...
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 EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR B...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) a = list(map(int, input().split())) impaired_wires = [] plugged_lamb = [0] * (n + 1) plugged_lamb[a[0]] = 1 impaired_wires.append([a[0], None]) print(a[0]) highest = n for i in range(1, len(a)): p = a[i] if plugged_lamb[p] == 0: wire = impaired_wires.pop(-1) plugged_lamb[p] = 1 ...
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 ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER NONE EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CA...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) s = [int(x) for x in input().split()] print(s[0]) pos = [0] * (n + 1) L = [] ptr = n for i in range(0, len(s)): if pos[s[i]] == 0: L.append(s[i]) pos[s[i]] = 1 else: for j in range(ptr, 0, -1): if pos[j] == 0: L.append(j) pos[j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
def go(): n = int(input()) a = list(map(lambda s: int(s) - 1, input().split())) done = [False] * n root = a[0] done[root] = True target = n - 1 while done[target]: target -= 1 parent = [-1] * n hanging = root def set_parent(x, par): if parent[x] != -1: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR ...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) inp = input().rstrip().split(" ") assert len(inp) == n - 1 for a in range(len(inp)): inp[a] = int(inp[a]) marked = {} edges = [[inp[i], None] for i in range(n - 1)] next_largest_unseen = n root = inp[0] marked[inp[0]] = True for i in range(1, n - 1): parent = edges[i][0] if parent not in ma...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST VAR VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBE...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) ls = list(map(int, input().split())) parent = {} seen = set() seen.add(ls[0]) lookf = n for i, e in enumerate(ls): if e in seen: while lookf in seen: lookf -= 1 parent[lookf] = e lastarc = lookf, e else: parent[e] = lastarc[1] parent[lastarc[0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBE...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) v = list(map(int, input().split())) vaz = [(0) for x in range(n + 10)] vaz1 = [(0) for x in range(2 * n + 10)] root = v[0] node = n g = [] for i in range(0, n + 1): g.append([]) vaz1[root] = 1 last = root pz = n for i in range(1, n - 1): if vaz1[v[i]] == 1: while vaz1[pz] == 1: ...
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) a = list(map(int, input().split())) dic = {} uexmax = n ans = [] for i in range(n - 1): if i == 0: dic[a[i]] = 1 elif a[i] in dic: dic[uexmax] = 1 ans.append([a[i - 1], uexmax]) else: dic[a[i]] = 1 ans.append([a[i - 1], a[i]]) while uexmax in dic:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR ...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) a = [0] + list(map(int, input().split())) used = [0] * (n + 1) g = {} cur = [n] def get_max(): while used[cur[0]] == 1: cur[0] -= 1 return cur[0] def push(g, u, v): if u not in g: g[u] = [] g[u].append(v) used[0] = 1 for i, x in enumerate(a[:-1]): if used[a[i +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST VAR FUNC_DEF WHILE VAR VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR LIS...
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself. Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam...
n = int(input()) a = list(map(int, input().split())) used = [0] * (n + 1) print(a[0]) bigger = n for x, y in zip(a, a[1:]): used[x] = 1 if not used[y]: print(x, y) else: while used[bigger]: bigger -= 1 print(x, bigger) used[bigger] = 1 used[a[-1]] = 1 while used[b...
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 EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR NU...
oolimry has an array $a$ of length $n$ which he really likes. Today, you have changed his array to $b$, a permutation of $a$, to make him sad. Because oolimry is only a duck, he can only perform the following operation to restore his array: Choose two integers $i,j$ such that $1 \leq i,j \leq n$. Swap $b_i$ and $b_j...
import sys def solve(): inp = sys.stdin.readline n = int(inp()) a = list(map(int, inp().split())) c = [[] for i in range(n + 1)] p = [None] * (n + 1) for i in range(n): c[a[i]].append(i) for i in range(n + 1): p[i] = -len(c[i]), i p.sort() b = [None] * n for k i...
IMPORT FUNC_DEF 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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP...
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi...
def root(node): while parent[node] != node: parent[node] = parent[parent[node]] node = parent[node] return node def union(a, b): root_a = root(a) root_b = root(b) if parent.count(root_a) > parent.count(root_b): parent[root_b] = root_a else: parent[root_a] = root...
FUNC_DEF WHILE VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_...
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi...
n = int(input()) q = list(map(int, input().split())) m = int(input()) A = [[(int(j) - 1) for j in input().split()] for i in range(m)] emp = [[] for i in range(n)] h = 10**6 + 2 l = [h] * n for i in range(m): emp[A[i][1]].append(A[i][0]) l[A[i][1]] = min(l[A[i][1]], A[i][2] + 1) count = 0 for i in emp: if le...
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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBE...
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi...
n = int(input()) q = list(map(int, input().split())) m = int(input()) l = [-1] * n for i in range(m): a, b, c = list(map(int, input().split())) if l[b - 1] == -1: l[b - 1] = c else: l[b - 1] = min(l[b - 1], c) if l.count(-1) > 1: print(-1) else: print(sum(l) + 1)
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 ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN V...
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi...
n = int(input()) input() m = int(input()) l = [] for i in range(m): a, b, c = map(int, input().split()) l.append([b, c, a]) l.sort() x = 0 k = 0 s = 0 for i in l: if i[0] != k: x += 1 k = i[0] s += i[1] if x < n - 1: print(-1) else: print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR...