description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You're creating a game level for some mobile game. The level should contain some number of cells aligned in a row from left to right and numbered with consecutive integers starting from $1$, and in each cell you can either put a platform or leave it empty. In order to pass a level, a player must throw a ball from the ...
t = int(input()) for l in range(t): n, p, k = map(int, input().split()) a = list(map(int, list(input()))) a = [(1 - a[i]) for i in range(n)] x, y = map(int, input().split()) p -= 1 mn = n * x sumadds = [0] * k start = [i for i in range(k)] for i in range(n): sumadds[i % k] +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ...
You're creating a game level for some mobile game. The level should contain some number of cells aligned in a row from left to right and numbered with consecutive integers starting from $1$, and in each cell you can either put a platform or leave it empty. In order to pass a level, a player must throw a ball from the ...
t = int(input()) for i in range(0, t): l1 = [int(x) for x in input().split()] n = l1[0] p = l1[1] k = l1[2] inp_str = input() l2 = [int(x) for x in input().split()] add = l2[0] rem = l2[1] c = [(0) for x in range(0, n)] for j in range(n - 1, -1, -1): if j + k < n: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER...
You're creating a game level for some mobile game. The level should contain some number of cells aligned in a row from left to right and numbered with consecutive integers starting from $1$, and in each cell you can either put a platform or leave it empty. In order to pass a level, a player must throw a ball from the ...
t = int(input()) for _ in range(t): n, p, k = map(int, input().split()) s = input() x, y = map(int, input().split()) add_cost = [(0) for i in range(n - p + 1)] for i in range(n - p, -1, -1): add_cost[i] = 1 - int(s[i + p - 1]) if i + k <= n - p: add_cost[i] += add_cost[i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUM...
You're creating a game level for some mobile game. The level should contain some number of cells aligned in a row from left to right and numbered with consecutive integers starting from $1$, and in each cell you can either put a platform or leave it empty. In order to pass a level, a player must throw a ball from the ...
for _ in range(int(input())): n, p, k = map(int, input().split()) s = input() l = list(s) x, y = map(int, input().split()) dpk = [0] * n for i in range(n - k, n): if l[i] == "0": dpk[i] = x for i in range(n - k - 1, -1, -1): if l[i] == "1": dpk[i] += d...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR STRING ASSIG...
You're creating a game level for some mobile game. The level should contain some number of cells aligned in a row from left to right and numbered with consecutive integers starting from $1$, and in each cell you can either put a platform or leave it empty. In order to pass a level, a player must throw a ball from the ...
def solve(): n, p, k = map(int, input().split()) blocks = input() x, y = map(int, input().split()) costs = [0] * n for i in range(n - 1, p - 2, -1): if i + k < n: costs[i] = costs[i + k] if blocks[i] == "0": costs[i] += x for i in range(p - 1, n): ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ST...
You're creating a game level for some mobile game. The level should contain some number of cells aligned in a row from left to right and numbered with consecutive integers starting from $1$, and in each cell you can either put a platform or leave it empty. In order to pass a level, a player must throw a ball from the ...
try: inp = open("file.txt").readline except: inp = input t = int(inp().strip()) for _ in range(t): n, p, k = map(int, inp().strip().split(" ")) arr = list(inp().strip()) y, x = map(int, inp().strip().split(" ")) kcou = [(0) for i in range(n)] i = 0 for i in range(n - 1, n - k - 1, -1): ...
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRI...
You're creating a game level for some mobile game. The level should contain some number of cells aligned in a row from left to right and numbered with consecutive integers starting from $1$, and in each cell you can either put a platform or leave it empty. In order to pass a level, a player must throw a ball from the ...
t = int(input()) for j in range(t): n, p, k = map(int, input().split()) s = input() s = "~" + s x, y = map(int, input().split()) a = [0] * n b = [0] * n ans = 9999999999 for i in range(p, n + 1): a[(i - p) % k] += s[i] == "0" for i in range(p, n + 1): ans = min(ans, (...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMB...
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
f = lambda: list(map(int, input().split())) a, b, h, w, n = f() c = sorted(list(f()), key=lambda x: -x) d = {(h, w), (w, h)} for i, q in enumerate([1] + c): for u, v in d.copy(): h, w = u, v * q if a <= w and b <= h or a <= h and b <= w: print(i) return d.add((h, w)) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR ...
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
def gen(o, gen1): if o == len(my_arr): fp = 1 sp = 1 for i in range(len(my_arr)): fp *= my_arr[i][0] ** gen1[i] sp *= my_arr[i][0] ** (my_arr[i][1] - gen1[i]) if h * fp >= a and w * sp >= b or h * fp >= b and w * sp >= a: return True return...
FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_...
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
import sys MAXV = 100010 d = [0] * MAXV a, b, h, w, n = list(map(int, input().split())) arr = input().split() for it in range(n): arr[it] = int(arr[it]) def solve(a, b, h, w, z, product, it): k = 0 if a % h: k = a // h + 1 else: k = a // h if k <= z and product // z * w >= b: ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NU...
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
a, b, h, w, n = list(map(int, input().strip().split(" "))) if a > b: a, b = b, a factor = list(map(int, input().strip().split(" "))) factor = sorted(factor)[::-1] def findout(a, b, h, w, factor): possible = set() for i in range(len(factor)): temp = set() if i == 0: temp.add((fa...
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL ...
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
def isin(a, b, h, w): return h >= a and w >= b or h >= b and w >= a a, b, h, w, n = map(int, input().split()) c = sorted(list(map(int, input().split())), key=lambda x: -x) if isin(a, b, h, w): print(0) exit() vis = {h: w} for i in range(len(c)): nc = c[i] pairs = [] for l in vis.keys(): ...
FUNC_DEF RETURN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT VAR VAR FOR VAR FUNC_CAL...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys from sys import stdin ty = ["abc", "acb", "bac", "bca", "cab", "cba"] n, m = map(int, stdin.readline().split()) s = list(stdin.readline()[:-1]) dp = [([0] * (n + 1)) for i in range(6)] for c in range(6): for i in range(n): if s[i] != ty[c][i % 3]: dp[c][i + 1] = dp[c][i] + 1 ...
IMPORT ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR 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 BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_O...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input() ss = ["abc", "acb", "cba", "cab", "bac", "bca"] dps = [] for i in range(6): l = [0] x = ss[i] y = x * (n // 3) + x[0 : n % 3] for c in range(n): l.append(l[-1] + (s[c] != y[c])) dps.append(l) for _ in range(m...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NU...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys MOD = 3 def get_next(start, delta): return (start + delta) % MOD def get_state(arr, start, dir): n = len(arr) state = [] prev = 0 cur = start for a in arr: state.append(prev + int(a != cur)) prev = state[-1] cur = get_next(cur, dir) return state def ...
IMPORT ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import itertools from sys import stdin def input(): return next(stdin)[:-1] def readline(): return map(int, input().split()) n, m = readline() s = input() periods = list(itertools.permutations("abc")) c = {p: [0] for p in periods} for i, ch in enumerate(s): for p in periods: c[p].append(c[p][-...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR VAR LIST NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
n, m = [int(x) for x in input().split(" ")] s = input() per = ["abc", "cba", "cab", "bca", "acb", "bac"] dif = [] for j in range(len(per)): tmp = [int(per[j][0] != s[0])] for i in range(1, n, 1): tmp.append(tmp[-1] + (per[j][i % 3] != s[i])) dif.append(tmp) res = "" for _ in range(m): l, r = [in...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys from itertools import permutations input = sys.stdin.readline n, m = map(int, input().split()) s = input()[:-1] k = (n + 2) // 3 A = [] for cand in permutations("abc"): x = "".join(cand) t = (x * k)[:n] cur = [0] for a, b in zip(s, t): cur.append(cur[-1] + (a != b)) A.append(cur)...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR EX...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
def read_ints(): return [int(x) for x in input().split()] forms = ["abc", "acb", "bac", "bca", "cab", "cba"] n, m = read_ints() s = input() k = 6 ans = [([0] * n) for _ in range(k)] for j in range(k): for i in range(n): ans[j][i] = 0 if s[i] == forms[j][i % 3] else 1 ans[j][i] += 0 if i == 0 e...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR V...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline def process(S, Q): diffs = {"a": [[0], [0]], "b": [[0], [0]], "c": [[0], [0]]} should_dict = {} for first in "abc": for diff in [1, 2]: for i in range(3): T = first, diff, i should = "abc"[(ord(first) - ord("a") + d...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR DICT STRING STRING STRING LIST LIST NUMBER LIST NUMBER LIST LIST NUMBER LIST NUMBER LIST LIST NUMBER LIST NUMBER ASSIGN VAR DICT FOR VAR STRING FOR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR STRING BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys from itertools import permutations LI = lambda: list(map(int, sys.stdin.readline().split())) MI = lambda: map(int, sys.stdin.readline().split()) SI = lambda: sys.stdin.readline().strip("\n") II = lambda: int(sys.stdin.readline()) n, m = MI() s = SI() a = "abc" dp = {} p = [] for v in permutations(a): v ...
IMPORT 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 STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
n, m = map(int, input().split()) s = list(input()) a = [0] * (n + 1) b = [0] * (n + 1) c = [0] * (n + 1) d = [0] * (n + 1) e = [0] * (n + 1) f = [0] * (n + 1) pa, pb, pc, pd, pe, pf = "abc", "bca", "cab", "acb", "cba", "bac" for i in range(n): if s[i] != pa[i % 3]: a[i] += 1 if s[i] != pb[i % 3]: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BI...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = list(input())[:-1] for i in range(n): s[i] = ord(s[i]) - 97 x = [(i % 3) for i in range(n)] y = [((i + 1) % 3) for i in range(n)] z = [((i + 2) % 3) for i in range(n)] a = [(i % 3) for i in range(n, 0, -1)] b = [((i + 1) % 3) for i in range...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR AS...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
from sys import * n, m = map(int, stdin.readline().split()) s = stdin.readline() perm = ["abc", "acb", "bac", "bca", "cab", "cba"] a = [[], [], [], [], [], []] for i in range(6): for j in range(n): if s[j] != perm[i][j % 3]: if j == 0: a[i].append(1) else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST LIST LIST LIST LIST LIST LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBE...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
from sys import stdin input = stdin.readline cycles = ["abc", "acb", "bac", "bca", "cab", "cba"] n, m = [int(x) for x in input().split()] s = input().rstrip() prefix_changes = [[0] for _ in range(6)] for i in range(n): k = i % 3 for j in range(6): if s[i] != cycles[j][k]: prefix_changes[j]....
ASSIGN VAR VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) S = input().strip() DP = [([0] * (n + 5)) for i in range(6)] SX = ["abc", "acb", "bac", "bca", "cab", "cba"] for i in range(n): for j in range(6): if SX[j][i % 3] == S[i]: DP[j][i] = DP[j][i - 1] else: DP...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
length, count = map(int, input().split()) string = input() pref = [] for s in ["abc", "acb", "bca", "cab", "cba", "bac"]: pref_sum = [0] * (length + 1) for i in range(length): pref_sum[i + 1] = pref_sum[i] + int(string[i] != s[i % 3]) pref.append(tuple(pref_sum)) ans = [0] * count for i in range(cou...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(2 * 10**5 + 10) write = lambda x: sys.stdout.write(x + "\n") debug = lambda x: sys.stderr.write(x + "\n") writef = lambda x: print("{:.12f}".format(x)) n, m = list(map(int, input().split())) vs = [([0] * n) for _ in range(3)] i = 0 for c in...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys from itertools import * input = sys.stdin.readline n, m = map(int, input().split()) s = input() ps = [ list(accumulate((c1 != c2 for c1, c2 in zip(cycle(pm), s)), initial=0)) for pm in permutations("abc") ] for _ in range(m): l, r = map(int, input().split()) print(min(p[r] - p[l - 1] for p i...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
n, m = map(int, input().split()) s = list(input()) lr = [[int(i) for i in input().split()] for _ in range(m)] li = [([0] * n) for _ in range(6)] ss = [["a", "b", "c"].index(c) for c in s] c0 = 0 c1 = 1 c2 = 2 for i in range(n): d0 = (c0 + i) % 3 d1 = (c1 + i) % 3 d2 = (c2 + i) % 3 d3 = (c0 - i) % 3 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL LIST STRING STRING STRING VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input().rstrip() data = ["abc", "acb", "bac", "bca", "cab", "cba"] cache = [[0] for _ in range(6)] k = n // 3 + 1 for i in range(6): comp = data[i] * k summ = 0 for j in range(n): if s[j] != comp[j]: summ += 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import itertools import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) s = str(input()) alphabet = ["a", "b", "c"] kouho = [] for L in itertools.permutations(alphabet, 3): temp = [0] for i in range(n): plus = 0 if s[i] != L[i % ...
IMPORT IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys from itertools import permutations inp = sys.stdin.readline n, m = map(int, inp().split()) s = inp() li = [] for p in permutations("abc"): li.append(0) count = 0 for i in range(n): if s[i] != p[i % 3]: count += 1 li.append(count) for _ in range(m): l, r = map(int,...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN V...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import itertools DEBUG = 0 if DEBUG == 1: data = open("sample1.in", "r") def readline(): if DEBUG == 1: return data.readline().strip("\r\n") else: try: return input().strip("\r\n") except EOFError: return "" def readi(): return [int(t) for t in readli...
IMPORT ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL FUNC_CALL VAR STRING VAR RETURN STRING FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline t = 1 for j in range(t): n, m = map(int, input().split()) s = list(input().strip()) temp = ["abc", "acb", "bac", "bca", "cab", "cba"] dp = [[(0) for x in range(n + 1)] for y in range(6)] for x in range(6): for y in range(n): dp[x][y + 1] = d...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUN...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline def getP(j): if j >= 3: l = j - 3 return 3 + (l + 1) % 3 else: return (j + 1) % 3 def solve(st, n, m): pref = [([0] * (n + 1)) for i in range(6)] match = "abcacb" for j in range(n - 1, -1, -1): for i in range(6): ...
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin output = sys.stdout inputs = input.readline().strip().split() N = int(inputs[0]) M = int(inputs[1]) S = input.readline().strip() SL = ["abc", "acb", "bac", "bca", "cab", "cba"] CL = [([0] * (N + 1)) for x in range(6)] for i in range(6): subtotal = 0 substring = SL[i] subCL = CL...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input()[:-1] L = [] for si in ["a", "b", "c"]: for sj in ["a", "b", "c"]: for sk in ["a", "b", "c"]: if si != sj and sj != sk and sk != si: l = [] for i in range(n): if...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR LIST STRING STRING STRING FOR VAR LIST STRING STRING STRING FOR VAR LIST STRING STRING STRING IF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER N...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
n, m = map(int, input().split()) s = input() s0 = "abc" s1 = "bca" s2 = "cab" s3 = "cba" s4 = "acb" s5 = "bac" S = [s0, s1, s2, s3, s4, s5] pre = [[0], [0], [0], [0], [0], [0]] for i in range(n): for j in range(6): pre[j].append(pre[j][-1] + int(S[j][i % 3] != s[i])) qry = [list(map(int, input().split())) f...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER FO...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input().strip("\n") k = n // 3 + n % 3 ligma = ["abc" * k, "acb" * k, "bac" * k, "bca" * k, "cba" * k, "cab" * k] psa = [[(0) for i in range(n + 1)] for j in range(6)] for i in range(6): for j in range(1, n + 1): psa[i][j] = psa[i][...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR NUMBER VAR...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline def give(l, n, s): pr = [0] k = 0 for i in range(n): if l[i] != s[k]: pr.append(pr[-1] + 1) else: pr.append(pr[-1]) k = (k + 1) % 3 return pr n, m = map(int, input().split()) l = input() s1 = "bac" pr1 = give(l, n...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
from sys import stdin input = stdin.readline def f(s, q): perm = ["abc", "bca", "acb", "bac", "cab", "cba"] res = [(i[1] - i[0] + 1) for i in q] for word in perm: pref = [0] * (len(s) + 1) for i in range(len(s)): pref[i + 1] = s[i] != word[i % 3] for i in range(1, len(...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline def inp(): return int(input()) def st(): return input().rstrip("\n") def lis(): return list(map(int, input().split())) def ma(): return map(int, input().split()) t = 1 gl = {"a": 0, "b": 1, "c": 2} while t: t -= 1 n, q = ma() s = st() firs...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER W...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline def find(n, s, arr): j = 0 ans = [0] * (n + 1) for i in range(n): if s[i] != arr[j]: ans[i + 1] = 1 ans[i + 1] = ans[i] + ans[i + 1] j = (j + 1) % 3 return ans n, m = map(int, input().split()) s = list(input()) A = [ ["a"...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input().strip() A = [([0] * n) for _ in range(6)] B = ["abc", "acb", "bac", "bca", "cba", "cab"] for i in range(6): pat = B[i] for k in range(n): if s[k] != pat[k % 3]: A[i][k] += 1 if k >= 1: A[i...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input() a = ["abc", "acb", "bac", "bca", "cab", "cba"] for i in range(6): a[i] = a[i] * (n // 3) + a[i] * (n % 3) prefix = [[(0) for i in range(n)] for j in range(6)] for i in range(6): if a[i][0] != s[0]: prefix[i][0] = 1 for i...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR V...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = [int(c) for c in input().split()] s = input() arr = ["abc", "bca", "cab", "bac", "acb", "cba"] a = [[(0) for i in range(n + 1)] for i in range(6)] for i in range(6): ss = arr[i] * (n // 3 + 1) for j in range(n): a[i][j] = 1 if ss[j] != s[j] else 0 a[...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NU...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
def main(n, m, s, query): permutation = ["abc", "acb", "bac", "bca", "cab", "cba"] dp = [([0] * len(permutation)) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(len(permutation)): req = permutation[j][(i - 1) % 3] dp[i][j] = dp[i - 1][j] + (0 if s[i - 1] == r...
FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR B...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys from itertools import permutations def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int, sys.stdin.readline().rstrip()))...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL V...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys from itertools import accumulate def rall(): return sys.stdin.readlines() def rl(): return sys.stdin.readline().strip() def rl_types(types): str_list = [x for x in sys.stdin.readline().strip().split(" ")] return [types[i](str_list[i]) for i in range(len(str_list))] def pr(something): ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL ...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
from itertools import accumulate from sys import stdin input = stdin.readline n, m = map(int, input().split()) s = list(input().rstrip()) test1 = "abc" * n test2 = "acb" * n test3 = "bac" * n test4 = "bca" * n test5 = "cab" * n test6 = "cba" * n test = [test1, test2, test3, test4, test5, test6] raw = [[(-1) for x in r...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR LIST VAR VAR V...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import itertools import sys def input(): return sys.stdin.readline().rstrip() DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] def to_int(char): return ord(char) - ord("a") def main(): n, q = map(int, input().split()) s = input() a = [to_int(char) for char in s] Querys = [tuple(map(int, input()....
IMPORT IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSI...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.buffer.readline n, m = map(int, input().split()) sst = [0] + list(input().strip()) st = [] for i in sst: st.append(chr(i)) arr = ["abc", "acb", "bac", "bca", "cab", "cba"] dp = [[(0) for i in range(n + 2)] for j in range(6)] for i in range(6): for j in range(1, n + 1): if s...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUM...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys from itertools import permutations input = sys.stdin.readline n, m = list(map(int, input().split())) s = list(input().strip()) p = list(permutations("abc")) all_s = [] for sx in p: temp = [] all_s.append([sx[x % 3] for x in range(n)]) dp = {i: ([0] * n) for i in range(6)} s_dp = {i: ([0] * n) for i ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIS...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input() abc = [] for i in range(6): abc.append([0] * (n + 1)) words = ["abc", "acb", "bac", "bca", "cab", "cba"] tmps = [0] * 6 for i in range(n): for j in range(6): if words[j][i % 3] != s[i]: tmps[j] += 1 a...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VA...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input().rstrip() ss = [ ("abc" * n)[:n], ("acb" * n)[:n], ("bac" * n)[:n], ("bca" * n)[:n], ("cab" * n)[:n], ("cba" * n)[:n], ] c = [([0] * (n + 1)) for i in range(6)] for i in range(6): si = ss[i] for j in range...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP STRING VAR VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_C...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline N, Q = map(int, input().split()) S = input() T = ["abc", "bca", "cab", "cba", "bac", "acb"] Cum = [([0] * (N + 1)) for _ in range(6)] for i in range(6): for j in range(N): if T[i][j % 3] != S[j]: Cum[i][j + 1] += 1 for j in range(N): Cum[i][j + ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER V...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input().strip() costs = [] possible = "abc" for i in range(3): for j in range(3): if i != j: k = 0 while k == i or k == j: k += 1 pattern = possible[i] + possible[j] + possible[k] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASS...
Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) st = list(input()) a0 = [0] a1 = [0] a2 = [0] b0 = [0] b1 = [0] b2 = [0] c0 = [0] c1 = [0] c2 = [0] a = [0, 0, 0] b = [0, 0, 0] c = [0, 0, 0] for i in range(n): if st[i] == "a": a[i % 3] += 1 if st[i] == "b": b[i % 3] += 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NU...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
import sys input = sys.stdin.readline n = int(input()) ans = 1 arr = [int(x) for x in input().split()] for i in range(n): temp = set() d = {} for j in range(i + 1, n): if arr[j] == arr[i]: temp = set() elif arr[j] not in temp: if arr[j] in d: d[arr[j]...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR IF VAR VAR VAR...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
n = int(input()) b = list(map(int, input().split())) dp = [([1] * n) for i in range(n)] d = {} k = 0 for i in range(n): if b[i] not in d: d[b[i]] = k k += 1 b[i] = d[b[i]] for i in range(n): for j in range(i): dp[i][b[j]] = max(dp[j][b[i]] + 1, dp[i][b[j]]) ans = 0 for l in dp: a...
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 DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR ...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() a = [None] * n i = 0 for v in mints(): a[i] = v, i i += 1 a.sort() i = 0 r = 0 while i < n: ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR N...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
from sys import stdin def solve(tc): n = int(stdin.readline().strip()) seq = list(map(int, stdin.readline().split())) elems = [] idxcnt = 0 idx = dict() for i in range(n): if seq[i] not in idx: idx[seq[i]] = idxcnt idxcnt += 1 elems.append([]) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR AS...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
n = int(input()) ls = list(map(int, input().split())) dp = [[(1) for i in range(n)] for j in range(n)] laspos = [None] * (max(ls) + 1) for i in range(n): for j in range(i): if laspos[ls[i]] is not None: dp[i][j] = 1 + dp[j][laspos[ls[i]]] else: dp[i][j] += 1 laspos[ls...
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 ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NONE ASSIGN VAR VAR VAR B...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
n = int(input()) a = list(map(int, input().split())) dp = [[(0) for i in range(n + 1)] for i in range(n + 1)] ans = 0 pre = 0 a = [0] + a for i in range(1, n + 1): pre = 0 for j in range(i): dp[i][j] = dp[j][pre] + 1 if a[i] == a[j]: pre = j ans = max(ans, dp[i][j]) print(ans...
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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN ...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
input() a = [*map(int, input().split())] r = {} for i, x in enumerate(list(set(a))): r[x] = i n = len(r) m = 0 a = [r[x] for x in a] for i, x in enumerate(a): h = [(0) for _ in range(n)] l = [(-2) for _ in range(n)] lx = -1 for j, y in enumerate(a[i + 1 :]): if y == x: lx = j ...
EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
n = int(input()) t = list(map(int, input().split())) p = {a: (0) for a in set(t)} d = 0 for i in range(n): a = t[i] if not a in p: continue p.pop(a) s = t.count(a) - 1 if 2 * s < d: continue if s > d: d = s k = i + 1 for j in range(k, n): if t[j] == a: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR IF VA...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
R = lambda: map(int, input().split()) n = int(input()) arr = list(R()) dp = [([0] * (n + 1)) for i in range(n + 1)] for i in range(n): p = -1 for j in range(i): dp[i][j] = max(dp[i][j], dp[j][p] + 1) p = j if arr[j] == arr[i] else p print(max(max(dp[i]) for i in range(n)) + 1)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VA...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, input().split())) def fn(a): mp = {} b = [] cnt = 0 for v in a: if v in mp: b += [mp[v]] else: b += [cnt] mp[v] = cnt cnt += 1 return b ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR LIST VAR VAR VAR LIST VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN ...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
def function(n, array): grid = [{} for i in range(n)] if n <= 2: print(n) return global_max = -10 for i in range(n - 2, -1, -1): for j in range(i + 1, n): diff = array[i] - array[j] max_val = 1 if -diff in grid[j].keys(): max_va...
FUNC_DEF ASSIGN VAR DICT VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR ...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
def get_len(a, b): if a[0] >= b[0]: c = a a = b b = c i = 0 j = 0 res = 2 while i < len(a) and j < len(b): while a[i] <= b[j]: i += 1 if i == len(a): break if i == len(a): break res += 1 while...
FUNC_DEF IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR FUN...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
def ap(arr): if len(arr) == 1: return 1 dp = [([1] * len(arr)) for i in range(len(arr))] cnst = 0 dct = {} for i in set(arr): dct[i] = cnst cnst += 1 for i in range(len(arr)): arr[i] = dct[arr[i]] ans = 0 for i in range(len(dp)): for j in range(i):...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FU...
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Credits:Special thanks to @memoryless for adding this problem and creating all...
class Solution: def countNumbersWithUniqueDigits(self, n): if n == 0: return 1 elif n == 1: return 10 else: return ( self.countNumbersWithUniqueDigits(n - 1) - self.countNumbersWithUniqueDigits(n - 2) ) * (11 - ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Credits:Special thanks to @memoryless for adding this problem and creating all...
class Solution: def countNumbersWithUniqueDigits(self, n): choices = [9, 9, 8, 7, 6, 5, 4, 3, 2, 1] ans, product = 1, 1 for i in range(n if n <= 10 else 10): product *= choices[i] ans += product return ans
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Credits:Special thanks to @memoryless for adding this problem and creating all...
class Solution: def countNumbersWithUniqueDigits(self, n): digits = [ 1, 10, 91, 739, 5275, 32491, 168571, 712891, 2345851, 5611771, 8877691, ] if n < len(digi...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR VAR RETURN VAR NUMBER
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Credits:Special thanks to @memoryless for adding this problem and creating all...
class Solution: def countNumbersWithUniqueDigits(self, n): if n == 0: return 1 ans = 10 d = 9 prod = 9 for i in range(2, n + 1): prod *= d d -= 1 ans += prod return ans
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN VAR
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Credits:Special thanks to @memoryless for adding this problem and creating all...
class Solution: def countNumbersWithUniqueDigits(self, n): if n == 0: return 1 if n > 10: return self.countNumbersWithUniqueDigits(10) count = 0 for i in range(1, n + 1): temp = 1 for j in range(i): temp *= 10 - j ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR RETURN VAR
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Credits:Special thanks to @memoryless for adding this problem and creating all...
class Solution: def countNumbersWithUniqueDigits(self, n): answer = 10**n for i in range(1, n + 1): all_count = 9 * 10 ** (i - 1) invalid = 9 for j in range(1, i): invalid *= 10 - j answer -= all_count - invalid return answer
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR RETURN VAR
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Credits:Special thanks to @memoryless for adding this problem and creating all...
class Solution: def countNumbersWithUniqueDigits(self, n): ls = [1, 10, 91] mul = 9 res = 0 for i in range(8): mul = 9 m = 9 for j in range(i + 2): mul *= m m -= 1 ls.append(mul + ls[-1]) if n >=...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER RETURN VAR VAR
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Credits:Special thanks to @memoryless for adding this problem and creating all...
class Solution: def countNumbersWithUniqueDigits(self, n): if n == 0: return 1 digits = [9, 9, 8, 7, 6, 5, 4, 3, 2, 1] ans = 0 while n > 0: if n == 1: ans += 10 else: res = 1 for i in range(n): ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
t = int(input()) dp = [[[(0) for i in range(51)] for j in range(31)] for k in range(31)] def cost(n, m, k): if dp[n][m][k] or k == 0 or n * m == k: return dp[n][m][k] c = 10**9 for i in range(1, n // 2 + 1): for j in range(k + 1): c = min(c, cost(n - i, m, k - j) + cost(i, m, j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_C...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
d = [0] * 49011 def g(n, m, k): t = 1000000000.0 for i in range(1, m // 2 + 1): for j in range(k + 1): t = min(t, f(n, m - i, k - j) + f(n, i, j)) return n * n + t def f(n, m, k): if n > m: n, m = m, n k = min(k, n * m - k) if k == 0: return 0 if k < 0...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF IF ...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
d = [[[(0) for i in range(51)] for j in range(31)] for g in range(31)] def rec(n, m, k): global d if k == 0 or n * m == k: return 0 if d[n][m][k] > 0: return d[n][m][k] if n * m < k: return 10**10 cost = 10**10 for i in range(1, n // 2 + 1): for j in range(k + 1...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
mem = [[[(0) for i in range(51)] for j in range(31)] for k in range(31)] def f(n, m, k): if mem[n][m][k]: return mem[n][m][k] if n * m == k or k == 0: return 0 cost = 10**9 for x in range(1, n // 2 + 1): for z in range(k + 1): cost = min(cost, m * m + f(n - x, m, k ...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUM...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
d = [[[(0) for i in range(51)] for j in range(31)] for k in range(31)] for i in range(31): d.append([]) for j in range(31): d[i].append([]) for k in range(50): d[i][j].append(0) def rec(n, m, k): global d if n * m == k or k == 0: return 0 if d[n][m][k] > 0: ...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF IF BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBE...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
dp = {} def getDP(n, m, k): if (n, m, k) in dp: return dp[n, m, k] elif (m, n, k) in dp: return dp[m, n, k] return None def solve(n, m, k): if n == 2 and m == 3 and k == 5: h = 5 if k == m * n or k == 0: dp[n, m, k] = 0 elif k % min(n, m) == 0: dp[n, m...
ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR RETURN NONE FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP ...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
import sys input = sys.stdin.readline d = {} testnumber = int(input()) def calc(n, m, k): if k <= 0 or k == m * n: return 0 if k > n * m: return 1000000000 nonlocal d if n < m: n, m = m, n if k > m * n - m: return m * m + 1 if k < m: return m * m + 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER I...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
D = {} def h(m, n, answ, k): x = answ for i in range(1, (n + 2) // 2): if k >= i * m: if m**2 + ans(m, n - i, k - i * m) < x: x = m**2 + ans(m, n - i, k - i * m) if k <= (n - i) * m: if m**2 + ans(m, n - i, k) < x: x = m**2 + ans(m, n - i...
ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
import sys input = sys.stdin.readline def main(): ans = [] memo = [[[(-1) for _ in range(51)] for _ in range(31)] for _ in range(31)] def solve(n, m, k): if n * m == k or k == 0: return 0 if memo[n][m][k] > -1: return memo[n][m][k] if memo[m][n][k] > -1: ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
import sys mem = [] for i in range(32): mem.append([([-1] * 52) for u in range(32)]) def solve(x, y, z): if x > y: mem[x][y][z] = solve(y, x, z) return mem[x][y][z] if x * y == z or z == 0: mem[x][y][z] = 0 return 0 if x * y < z: mem[x][y][z] = -2 retur...
IMPORT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR ASSIGN ...
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
t = int(input()) d = [] for i in range(31): dd = [] for j in range(31): dd.append([0] * 51) d.append(dd) d[1][1][1] = 0 for i in range(1, 31): for j in range(1, 31): for k in range(1, min(i * j, 50) + 1): if k > i * j // 2: d[i][j][k] = d[i][j][i * j - k] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
from itertools import combinations from sys import setrecursionlimit, stdin setrecursionlimit(200000) def reverse_check_big(string, index): temp = string[: index + 1] forward = "".join(temp) reverse = "".join(temp[::-1]) if reverse > forward: return True else: return False def c...
EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_DEF ASSIGN...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = list(map(int, input().split())) pos = [(0) for i in range(n + 1)] for i in range(n): pos[a[i]] = i dp = [(0) for i in range(n + 1)] for i in range(n - 1, 0, -1): j = pos[i] for k in range(j, n, i): if a[k] > i: if dp[a[k]] == 0: dp[i] = 1 for k in...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASS...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) l = [(-1) for i in range(n + 1)] s = input().split() ll = [int(i) for i in s] for i in range(n): j = ll[i] l[j] = i res = ["." for i in range(n + 1)] res[n] = "B" for i in range(n - 1, 0, -1): toadd = "B" pos = l[i] % i while pos < n: j = ll[pos] if j <= i: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING FOR VAR FUNC_CA...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys from sys import stdin n = int(stdin.readline().strip()) s = list(map(int, stdin.readline().strip().split())) dp = ["B" for i in range(n)] visited = [(False) for i in range(n)] sys.setrecursionlimit(10**9) def dfs(i): x = s[i] visited[i] = True for j in range(i - x, -1, -x): if s[j] > x...
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 ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
from sys import setrecursionlimit, stdin setrecursionlimit(10**7) def iin(): return int(stdin.readline()) def lin(): return list(map(int, stdin.readline().split())) dp = [-1] * (10**5 + 10) def check(n, idx, a): global dp if dp[idx] != -1: return dp[idx] step = a[idx] ans = 0 ...
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FO...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) L = list(map(int, input().split())) ans = [""] * n revL = [0] * n ans[-1] = "B" for i in range(n): revL[L[i] - 1] = i + 1 for i in range(n - 2, -1, -1): t = revL[i] - 1 counter = "B" for j in range(t, -1, -i - 1): if j == t: continue if ans[L[j] - 1] == "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 STRING VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMB...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys next(sys.stdin) positions = {} pos2x = {} for i, x in enumerate(next(sys.stdin).split()): x = int(x) positions[x] = i pos2x[i] = x answers = ["" for _ in range(len(positions))] for x in range(len(positions), 0, -1): position = positions[x] def can_go_to_looser(): next_position =...
IMPORT EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_DEF A...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
N = int(input()) a = list(map(int, input().split())) rec = ["+"] * N P = [0] * N for i in range(N): P[a[i] - 1] = i for i in range(N, 0, -1): j = P[i - 1] rec[j] = "B" for k in range(j % i, N, i): if j != k and a[j] <= a[k] and rec[k] == "B": rec[j] = "A" break print("".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 STRING VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) l = [*map(int, input().split())] p = [0] * n for i in range(n): p[l[i] - 1] = i res = ["?"] * n for e in range(n, 0, -1): i = p[e - 1] res[i] = "B" for j in range(i % e, n, e): if i != j and l[i] <= l[j] and res[j] == "B": res[i] = "A" break print("".join...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRI...