description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
t = int(input()) while t > 0: n, r = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) maxi = b[0] temp = b[0] for i in range(1, n): maxi = maxi - (a[i] - a[i - 1]) * r if maxi < 0: maxi = 0 maxi = maxi + b...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
T = int(input()) for i in range(T): n, r = map(int, input().split()) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) i = m = x = 0 while i < n: x = x + l2[i] if x > m: m = x i = i + 1 if i < n: x = x - (l1[i] - l1[i - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 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 NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for _ in range(int(input())): n, r = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c, d = [b[0]], b[0] for i in range(1, n): d = max(0, d - (a[i] - a[i - 1]) * r) d += b[i] c += [d] print(max(c))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSI...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
def solve(): n, r = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.append(0) x = 0 result = 0 for i in range(0, n): x += b[i] result = max(result, x) x = max(0, x - r * (a[i + 1] - a[i])) print(result) def mai...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FU...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
def integer_list(): return list(map(int, input().split())) def string_list(): return list(map(str, input().split())) def hetro_list(): return list(input().split()) t = int(input()) for _ in range(t): n, r = integer_list() a_lst = integer_list() b_lst = integer_list() tension = b_lst[0]...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASS...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for _ in range(int(input())): n, r = map(int, input().split()) list1 = list(map(int, input().split())) list2 = list(map(int, input().split())) if n == 1: print(list2[0]) continue summ = list2[0] maxx = list2[0] for i in range(1, n): if r * (list1[i] - list1[i - 1]) >=...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for i in range(int(input())): n, r = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) maxt = b[0] t = b[0] x = b[0] for j in range(1, n): prev = a[j - 1] curr = a[j] x = max(b[j], x + b[j] - (curr - prev) * r) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for _ in range(int(input())): n, r = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) tot, m = 0, 0 for i in range(n): tot += b[i] if tot > m: m = tot if i < n - 1: tot -= (a[i + 1] - a[i]) * r i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR A...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for _ in range(int(input())): N, R = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] ans = B[0] x = B[0] for i in range(1, N, 1): dec = (A[i] - A[i - 1]) * R x = max(x - dec, 0) x += B[i] ans = max(ans,...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR ...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
t = int(input()) for i in range(t): n, k = map(int, input().split()) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) l1.append(l1[-1]) pump = 0 ans = 0 for i in range(len(l1)): try: pump += l2[i] except IndexError: pass ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBE...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for i in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) m = 0 current = 0 for i in range(n): current = current + b[i] m = max(current, m) if i < n - 1: current = max(0, current - (a...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
def build(n, r, time, tension): if n == 1: return tension[0] t = tension[0] max_tension = -1 for i in range(1, n): value = time[i] - time[i - 1] lost = value * r t -= lost if t < 0: t = 0 t += tension[i] if t > max_tension: ...
FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR ...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
t = int(input()) for _ in range(t): n, r = input().split() n = int(n) r = int(r) A = list(int(x) for x in input().split()) B = list(int(x) for x in input().split()) x = 0 t_max = 0 for i in range(n): x += B[i] if x > t_max: t_max = x if i <= n - 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBE...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
t = int(input()) for i in range(t): n, r = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ma = -999 res = 0 for i in range(n - 1): res += b[i] ma = max(ma, res) res -= abs(a[i + 1] - a[i]) * r if res <...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for t in range(int(input())): n, r = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) max_t = b[0] updated_t = b[0] for i in range(1, len(b)): new_r = (a[i] - a[i - 1]) * r if updated_t - new_r < 0: updated_t = 0 + b[i]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_C...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for t in range(int(input())): n, r = map(int, input().split()) time = [int(x) for x in input().split()] tension = [int(x) for x in input().split()] max = 0 temp_t = 0 i = 0 while i < n: if n == 1: max = tension[0] break elif i > 0: if temp_...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER ASSIGN VAR VAR NU...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
def solve(): n, r = list(map(int, input().split())) alst = list(map(int, input().split())) blst = list(map(int, input().split())) tension = blst[0] maxtension = tension t = alst[0] for a, b in zip(alst[1:], blst[1:]): tension = max(0, tension - (a - t) * r) t = a tens...
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for i in range(int(input())): a, b = map(int, input().split()) l = list(map(int, input().split())) l1 = list(map(int, input().split())) k = [] su = 0 for i in range(len(l1)): if i != len(l1) - 1: su += l1[i] c = b * (l[i + 1] - l[i]) k.append(su) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
t = int(input()) for i in range(t): c = 0 cc = [] x, y = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(0, len(a)): if i != len(a) - 1: c += b[i] cc.append(c) di = abs(a[i] - a[i + 1]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER F...
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings...
def calc_lcp(s, sa): n = len(s) rank = [(0) for _ in range(n)] for i in range(n): rank[sa[i]] = i lcp = [(0) for _ in range(n - 1)] h = 0 for i in range(n): if rank[i] < n - 1: while s[i + h] == s[sa[rank[i] + 1] + h]: h += 1 lcp[rank[i]] =...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR ...
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings...
def calc_lcp(s, sa): rank = [(0) for _ in range(len(s))] for i in range(len(s)): rank[sa[i]] = i lcp = [(0) for _ in range(len(s) - 1)] h = 0 for i in range(len(s)): if rank[i] < len(s) - 1: while ( max(i, sa[rank[i] + 1]) + h < len(s) and ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP FUNC_CALL VA...
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings...
def calc_lcp(s, sa): rank = [(0) for _ in range(len(s))] for i in range(len(s)): rank[sa[i]] = i lcp = [(0) for _ in range(len(s) - 1)] h = 0 for i in range(len(s)): if rank[i] < len(s) - 1: while s[i + h] == s[sa[rank[i] + 1] + h]: h += 1 lcp[...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP VAR VAR ...
Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle. A Boggle board is a 2D array of individual characters, e.g.: ```python [ ["I","L","A","W"], ["B","N","G","E"], ["I","U","A","O"], ["A","S","R","L"] ] ``` Valid guesses are strings which can be formed ...
def find_word(board, word): def make(i, j, string, f=1, visited=None): if not visited: visited = [] visited = [[k, l] for k, l in visited if board[k][l] in string] if [i, j] in visited or not word.startswith(string): return False if not f: if 0 <=...
FUNC_DEF FUNC_DEF NUMBER NONE IF VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR IF LIST VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR LIST VAR VAR RETURN ...
Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle. A Boggle board is a 2D array of individual characters, e.g.: ```python [ ["I","L","A","W"], ["B","N","G","E"], ["I","U","A","O"], ["A","S","R","L"] ] ``` Valid guesses are strings which can be formed ...
def find_word(board, word, trail=None): if not word: return True if not trail: board = { (row, col): item for row, line in enumerate(board) for col, item in enumerate(line) } valid_first = [k for k, v in list(board.items()) if v == word[0]] ...
FUNC_DEF NONE IF VAR RETURN NUMBER IF VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER LIST VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR...
Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle. A Boggle board is a 2D array of individual characters, e.g.: ```python [ ["I","L","A","W"], ["B","N","G","E"], ["I","U","A","O"], ["A","S","R","L"] ] ``` Valid guesses are strings which can be formed ...
def find_word(board, word): P = {(i, j): e for j, r in enumerate(board) for i, e in enumerate(r)} chains, word = [[p] for p in P if P[p] == word[0]], word[1:] while word and chains: c, word, newchains = word[0], word[1:], [] for chain in chains: i, j = chain[-1] neigh...
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR...
Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle. A Boggle board is a 2D array of individual characters, e.g.: ```python [ ["I","L","A","W"], ["B","N","G","E"], ["I","U","A","O"], ["A","S","R","L"] ] ``` Valid guesses are strings which can be formed ...
def find_word(board, word): grid = [(l + [""]) for l in board] + [[""] * (len(board[0]) + 1)] def rc(x, y, i): if i == len(word): return True if grid[x][y] != word[i]: return False grid[x][y] = "" r = any(rc(x + u, y + v, i + 1) for u in range(-1, 2) for ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR LIST STRING VAR VAR LIST BIN_OP LIST STRING BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER V...
Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle. A Boggle board is a 2D array of individual characters, e.g.: ```python [ ["I","L","A","W"], ["B","N","G","E"], ["I","U","A","O"], ["A","S","R","L"] ] ``` Valid guesses are strings which can be formed ...
def find_neighbors(row_c, col_c, board, word, path): if len(path) == len(word): return True, path y_d = [i for i in range(max(0, row_c - 1), min(len(board), row_c + 2))] x_d = [i for i in range(max(0, col_c - 1), min(len(board), col_c + 2))] neighbors = [(y, x) for y in y_d for x in x_d] for...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR...
Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle. A Boggle board is a 2D array of individual characters, e.g.: ```python [ ["I","L","A","W"], ["B","N","G","E"], ["I","U","A","O"], ["A","S","R","L"] ] ``` Valid guesses are strings which can be formed ...
def check_valid(letter_locations, board, word): if len(letter_locations) == len(word): return True x, y = letter_locations[-1] next_char = word[len(letter_locations)] valid = False for i in range(-1, 2): for j in range(-1, 2): if i == 0 and j == 0: continu...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_...
Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle. A Boggle board is a 2D array of individual characters, e.g.: ```python [ ["I","L","A","W"], ["B","N","G","E"], ["I","U","A","O"], ["A","S","R","L"] ] ``` Valid guesses are strings which can be formed ...
def find_word(board, word, cursor=None): if not word: return True workboard = [row[:] for row in board] sy, sx, ey, ex = 0, 0, len(board), len(board[0]) if cursor: cx, cy = cursor workboard[cy][cx] = "-" sy = max(sy, cy - 1) sx = max(sx, cx - 1) ey = min(e...
FUNC_DEF NONE IF VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP ...
Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle. A Boggle board is a 2D array of individual characters, e.g.: ```python [ ["I","L","A","W"], ["B","N","G","E"], ["I","U","A","O"], ["A","S","R","L"] ] ``` Valid guesses are strings which can be formed ...
def find_word(board, s): def seekFrom(x, y): bd[x][y] = "" ret = next(dfs(x, y), False) bd[x][y] = s[0] return ret def dfs(x, y, i=1): if i == len(s): yield True else: candidates = ( (x + dx, y + dy) for dx...
FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF NUMBER IF VAR FUNC_CALL VAR VAR EXPR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP V...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
from itertools import permutations class Solution: digitMap = {} wordsRev = [] resultRev = [] limit = 0 def findSolution(self, n, carry=0): if n == self.limit: leadingDigitChars = [w[len(w) - 1] for w in self.wordsRev] leadingDigitChars.append(self.resultRev[len(se...
CLASS_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL V...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: allWords = words + [result] firstChars = set(word[0] for word in allWords) maxWordLength = max(list(map(len, allWords))) if len(result) < maxWordLength: return False def dfs(charIdx, wo...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER FUNC_DEF IF VAR VAR RETURN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: n = len(words) mapper = {} maxlen = 0 for w in words: maxlen = max(maxlen, len(w)) for c in w: mapper[c] = -1 if len(result) < maxlen or len(result) - maxlen ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST N...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: max_len = len(result) if max(len(w) for w in words) > max_len: return False level = [ [word[-i - 1] for word in words if i < len(word)] for i in range(max_len) ] level_set = ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: self.n = len(result) self.levels = [] self.alldigit = {} self.allch = [] self.result = result self.nonzero = set() for w in words: self.nonzero.add(w[0]) self.non...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FU...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: if max([len(w) for w in words]) > len(result): return False lead_letters = set([w[0] for w in words + [result]]) letters = [] for k in range(1, len(result) + 1): for w in words: ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR LIST VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CAL...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: def solve(i, j, carry): if j == len(words): csum = carry for k in range(len(words)): csum += 0 if i >= len(words[k]) else assign[words[k][i]] if i >=...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: allwords = words + [result] n = max(list(map(len, allwords))) firstc = set(word[0] for word in allwords) if len(result) < n: return False def dfs(charidx, wordidx, carry, visited, char2...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER FUNC_DEF IF VAR VAR RETURN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR V...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: longest_word = max([len(word) for word in words]) if len(result) != longest_word and len(result) != longest_word + 1: return False result_indices = [] acc = 0 all_chars = [] fron...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: words.append(result) R, C = len(words), max(list(map(len, words))) used = {} used_d = [None] * 10 def backtrack(row, col, bal): if col >= C: return bal == 0 and all(used...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NONE NUMBER FUNC_DEF IF VAR VAR RETURN VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR IF VAR VAR RETURN BIN_OP VAR NUMBER NUMBER FUNC_CA...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: start = set() for word in words + [result]: if len(word) > 1: start.add(word[0]) n = max(list(map(len, words + [result]))) if len(result) < n: return False d...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR BIN_OP VAR LIST VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR LIST VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER FUNC_DEF IF VAR VAR RETURN VAR NUMBER IF VAR BIN_OP FUNC_CALL ...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution(object): def isSolvable(self, words, result): words.append(result) R, C = len(words), max(map(len, words)) assigned = {} assigned_inv = [None] * 10 def search(column, row, bal): if column >= C: return bal == 0 if row ==...
CLASS_DEF VAR FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NONE NUMBER FUNC_DEF IF VAR VAR RETURN VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR V...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
class Solution: def isSolvable(self, words: List[str], result: str) -> bool: def backtrack(ch_pos_to_end, num_choices, iter_idx, lhs, rhs): if ch_pos_to_end > len(result): return True mul = pow(10, ch_pos_to_end - 1) if iter_idx < len(words): ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR FOR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CA...
Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one n...
def make_zip(lists): i = 0 maxlength = max(len(l) for l in lists) ans = [] while i < maxlength: ans.append([l[i] for l in lists if i < len(l)]) i += 1 return ans def make_order(words, result): order = [] formulas = {} for i in range(len(result)): for ch in [*wor...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR LIST VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CA...
Kate constantly finds herself in some kind of a maze. Help her to find a way out!. For a given maze and Kate's position find if there is a way out. Your function should return True or False. Each maze is defined as a list of strings, where each char stays for a single maze "cell". ' ' (space) can be stepped on, '#' m...
def has_exit(maze): def rec(i, j): if not i in range(len(maze)): return True if not j in range(len(maze[i])): return True if maze[i][j] == "#": return False maze[i][j] = "#" return any( rec(i + k, j + l) for k in (-...
FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR VAR VAR STRING RETURN NUMBER ASSIGN VAR VAR VAR STRING RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER FUNC_CALL VAR V...
Kate constantly finds herself in some kind of a maze. Help her to find a way out!. For a given maze and Kate's position find if there is a way out. Your function should return True or False. Each maze is defined as a list of strings, where each char stays for a single maze "cell". ' ' (space) can be stepped on, '#' m...
def has_exit(maze): W = len(maze[0]) S = W * len(maze) frontier, unseen = set(), set() for position, content in enumerate("".join(maze)): (frontier.add, unseen.add, id)["k #".index(content)](position) assert len(frontier) == 1 while frontier: position = frontier.pop() if ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR BIN_OP VAR V...
Kate constantly finds herself in some kind of a maze. Help her to find a way out!. For a given maze and Kate's position find if there is a way out. Your function should return True or False. Each maze is defined as a list of strings, where each char stays for a single maze "cell". ' ' (space) can be stepped on, '#' m...
def has_exit(maze): vector, w = list("".join(maze)), len(maze[0]) assert vector.count("k") == 1 while "k" in vector: for p, cell in enumerate(vector): if cell == "k": if min(p, len(vector) - p) < w or -~p % w < 2: return True for direct...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER WHILE STRING VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER FOR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR STRIN...
Kate constantly finds herself in some kind of a maze. Help her to find a way out!. For a given maze and Kate's position find if there is a way out. Your function should return True or False. Each maze is defined as a list of strings, where each char stays for a single maze "cell". ' ' (space) can be stepped on, '#' m...
def has_exit(m): maze = [[x for x in row] for row in m] if not check_edge(maze): return False if not check_kate(maze): raise Exception("There should no be multiple Kates") kate = find_kate(maze) return find_way(maze, kate, kate) def find_way(maze, position, previous_position, trace...
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF LIST IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR...
Kate constantly finds herself in some kind of a maze. Help her to find a way out!. For a given maze and Kate's position find if there is a way out. Your function should return True or False. Each maze is defined as a list of strings, where each char stays for a single maze "cell". ' ' (space) can be stepped on, '#' m...
def has_exit(board): def make(i, j, visited=None): if not visited: visited = [] if ( [i, j] in visited or not (0 <= i < len(board) and 0 <= j < len(board[0])) or board[i][j] == "#" ): return False visited.append([i, j]) ...
FUNC_DEF FUNC_DEF NONE IF VAR ASSIGN VAR LIST IF LIST VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER RETURN...
Kate constantly finds herself in some kind of a maze. Help her to find a way out!. For a given maze and Kate's position find if there is a way out. Your function should return True or False. Each maze is defined as a list of strings, where each char stays for a single maze "cell". ' ' (space) can be stepped on, '#' m...
MOVES = {(0, 1), (0, -1), (1, 0), (-1, 0)} def has_exit(maze): posSet = { (x, y) for x in range(len(maze)) for y in range(len(maze[x])) if maze[x][y] == "k" } if len(posSet) != 1: raise ValueError("There shouldn't be more than one kate") seen = set(posSet) w...
ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR IF FUNC_CALL ...
Kate constantly finds herself in some kind of a maze. Help her to find a way out!. For a given maze and Kate's position find if there is a way out. Your function should return True or False. Each maze is defined as a list of strings, where each char stays for a single maze "cell". ' ' (space) can be stepped on, '#' m...
def has_exit(maze): N, M = len(maze) + 2, len(maze[0]) + 2 maze = ["b" * M] + [("b" + row + "b") for row in maze] + ["b" * M] q = [(i, j) for i, row in enumerate(maze) for j, c in enumerate(row) if c == "k"] if len(q) != 1: raise Exception("Wrong number of Kates") v = set(q) while q: ...
FUNC_DEF ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST BIN_OP STRING VAR BIN_OP BIN_OP STRING VAR STRING VAR VAR LIST BIN_OP STRING VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC...
Kate constantly finds herself in some kind of a maze. Help her to find a way out!. For a given maze and Kate's position find if there is a way out. Your function should return True or False. Each maze is defined as a list of strings, where each char stays for a single maze "cell". ' ' (space) can be stepped on, '#' m...
def has_exit(maze): start = [ [i, maze[i].find("k")] for i in range(len(maze)) if maze[i].find("k") != -1 ] if len(start) != 1: raise Exception("There should no be multiple Kates") if backtracking(maze, start[0][0], start[0][1], set()): return True return False def backtrac...
FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR STRING EXPR FUNC_CALL VAR ...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
def modified_string_BF(test_str): clst = list(test_str) cmin = [max(clst)] * len(clst) for mx, mch in enumerate(clst): cref = clst.copy() cref.pop(mx) for np in range(len(clst)): ctst = cref.copy() ctst.insert(np, mch) cmin = min(ctst, cmin) re...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL STR...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
for _ in range(int(input())): n = int(input()) mini = ["z"] * 100 s = list(input().strip()) ans = min(mini, s) t = s[:] for i in range(n): curr = s[i] f = 0 ind = 0 temp = s[i] for j in range(i): if s[j] > curr: s.pop(i) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR V...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
t = int(input()) for _ in range(t): n = int(input()) s = input() wow = s for i in range(n): now = s[:i] + s[i + 1 :] for j in range(n): wow = min(wow, now[:j] + s[i] + now[j:]) print(wow)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
def modified_string(test_str): clst = list(test_str) cmin = [max(clst)] * len(clst) for mx, mch in enumerate(clst): cref = clst.copy() cref.pop(mx) for np in range(len(clst)): ctst = cref.copy() ctst.insert(np, mch) cmin = min(ctst, cmin) retur...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL STR...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
import sys def modify(s, i, j): c = s[i] t = s[:i] + s[i + 1 :] ret = t[:j] + c + t[j:] return ret t = int(sys.stdin.readline()) while t > 0: t -= 1 n = int(sys.stdin.readline()) s = sys.stdin.readline().strip() m = s for i in range(n): for j in range(n): if i...
IMPORT FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
t = int(input()) for T in range(t): n = int(input()) s = input() ans = s val, val1 = "", "" for i in range(n): val = s[:i] + s[i + 1 :] for j in range(n): val1 = val[:j] + s[i] + val[j:] ans = min(ans, val1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VA...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
T = int(input()) for _ in range(T): n = int(input()) s = input().strip() answer = s for i in range(len(s)): c = s[i] string = s[:i] + s[i + 1 :] for j in range(len(string) + 1): answer = min(answer, string[:j] + c + string[j:]) print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIG...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
def compare(s1, s2, n): i = 0 while i < n: if s1[i] < s2[i]: return s1 elif s2[i] < s1[i]: return s2 i += 1 return s1 for t in range(int(input())): n = int(input()) a = input() s = [] s1 = [] s2 = [] temp = [] for i in range(n): ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL V...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
def modify(s, i, j): k = s[i] del s[i] s.insert(j, k) return str(s) for _ in range(int(input())): n = int(input()) s = list(input()) ans = str(s) for i in range(n): for j in range(n): if i != j: ans = min(ans, modify(s, i, j)) k = s[j] ...
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR F...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
def rightShift(s, i, j): s = list(s) while j > i: s[j], s[j - 1] = s[j - 1], s[j] j -= 1 return "".join(s) def leftShift(s, i, j): s = list(s) while j > i: s[i], s[i + 1] = s[i + 1], s[i] i += 1 return "".join(s) def solution(): N = int(input()) S = in...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN FUNC_CALL STRING VAR FUNC...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
def Min_str(): n = int(input()) s = input() temp = s[:] for i in range(n): s1 = [ord(x) for x in s] t = s1[i] del s1[i] j = 0 while j < n - 1: if s1[j] > t: s1[j:j] = [t] break j += 1 if len(s1) != n:...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR LIST VAR ASSI...
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string. Find the lexicographically smallest string you can achieve. ...
def getInput(): T = int(input()) taille = [] chaine = [] for i in range(T): taille.append(int(input())) chaine.append(input()) return T, taille, chaine def solve(taille, chaine): solution = chaine for i in range(taille): for j in range(taille): tempChain...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = map(int, input().split()) stacks = [[] for i in range(n + 1)] queue = [] q_start = 0 unread = 0 ans = [] for i in range(q): action, num = map(int, input().split()) if action == 1: queue.append(0) stacks[num].append(len(queue) - 1) unread += 1 elif action == 2: for i in...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR V...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = map(int, input().split()) ans = 0 res = "" num = 0 pre = 0 noti = [] arr = [([0] * (n + 10)) for i in range(2)] for i in range(q): op, x = map(int, input().split()) if op == 1: arr[0][x] += 1 ans += 1 num += 1 noti += [x] elif op == 2: ans -= arr[0][x] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR N...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
import sys n, m = map(int, input().split()) k = 0 pos = 0 L = [] L1 = [] d = {i: [0, -1] for i in range(1, n + 1)} for i in range(m): a, b = map(int, sys.stdin.readline()[:-1].split()) if a == 1: d[b][0] += 1 k += 1 L.append(b) elif a == 2: k -= d[b][0] d[b][0] = 0 ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, p = map(int, input().split()) L = [] A = [[] for _ in range(n)] op = 0 bec = 0 rt = [] for i in range(p): a, b = map(int, input().split()) if a == 2: while len(A[b - 1]) > 0: y = A[b - 1].pop() bec = bec - L[y] L[y] = 0 elif a == 1: L.append(1) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR ...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = map(int, input().split()) count = [(0) for i in range(n + 1)] queue = [] read = set() unread = 0 ans = [] last_q_idx = 0 last_app_idx = [(1) for i in range(n + 1)] for i in range(q): action, num = map(int, input().split()) if action == 1: queue.append((num, count[num] + 1)) count[num] += ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUN...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
def main(): n, q = map(int, input().split()) vol, tot, l, res = [0] * (n + 1), [0] * (n + 1), [], [] z = m = 0 for _ in range(q): t, x = map(int, input().split()) if t == 1: l.append(x) tot[x] += 1 vol[x] += 1 z += 1 elif t == 2: ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR V...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
[n, q] = list(map(int, input().split(" "))) total_cell = [0] * n max_2 = [0] * n max_3 = 0 message = [] total = 0 time = 0 ans = "" for i in range(q): [t, x_t] = list(map(int, input().split(" "))) if t == 1: total_cell[x_t - 1] += 1 message.append(x_t) total += 1 elif t == 2: ...
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUN...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = map(int, input().split()) xi = [([0] * (n + 1)) for i in range(2)] noti = [] ans = [] num = 0 num2 = 0 num3 = 0 while q > 0: typ, xt = map(int, input().split()) if typ == 1: xi[0][xt] += 1 noti += [xt] num += 1 num2 += 1 elif typ == 3: for i in range(num3, xt):...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR N...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
import sys def main(): tmp = [int(x) for x in sys.stdin.readline().split()] n = tmp[0] q = tmp[1] readApp = [0] * n unreadApp = [0] * n unreadTot = 0 genApp = [0] * n firstFlag = 0 genOps = [] for i in range(q): tmp = [int(x) for x in sys.stdin.readline().split()] ...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VA...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
import sys input = sys.stdin.readline n, q = map(int, input().split()) l = [[] for _ in range(n)] is_read = [] is_read_idx = 0 ans = 0 prev_t = 0 for _ in range(q): ty, v = map(int, input().split()) if ty == 1: l[v - 1].append(is_read_idx) is_read_idx += 1 is_read.append(False) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = map(int, input().split()) l = [] a = [[] for _ in range(n)] tp = 0 ans = 0 anss = [] for i in range(q): x, b = map(int, input().split()) if x == 1: l.append(1) a[b - 1].append(len(l) - 1) ans += 1 elif x == 2: while len(a[b - 1]) > 0: z = a[b - 1].pop() ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMB...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = map(int, input().split()) ans = [0] * q unread = [0] * n last = [-1] * n qur, cur = [], 0 for i in range(q): t, x = map(int, input().split()) ans[i] = ans[i - 1] if t == 1: unread[x - 1] += 1 ans[i] += 1 qur.append(x - 1) elif t == 2: ans[i] -= unread[x - 1] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
import itertools n, q = map(int, input().split()) counterGlob = itertools.count() Queue = [] StartQ = 0 counter = 0 ans = "" X = [[] for i in range(n + 1)] F = [0] * (n + 1) for i in range(q): typeQ, a = map(int, input().split()) if typeQ == 1: counter += 1 ind = next(counterGlob) Queue...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FU...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
from sys import stdin input = stdin.readline n, q = map(int, input().split()) arr = [tuple(map(int, input().split())) for _ in range(q)] adj = [[] for _ in range(n + 1)] curr, cnt, res, vis = 0, 0, [], [] for t, v in arr: if t == 1: adj[v].append(len(vis)) vis.append(0) cnt += 1 elif t ...
ASSIGN VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER LIST LIST FOR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CA...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = input().split() n = int(n) q = int(q) p0 = 0 Ans = [] Q = [(0, True)] App = [set() for i in range(n + 1)] t = 1 ans = 0 for i in range(q): q, p = input().split() p = int(p) if q == "1": App[p].add(t) Q.append([p, False]) t += 1 ans += 1 elif q == "2": for i...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL V...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
import sys def doremon(c, i, j): u = v = i z = c[i] w = x = j crt = 0 while ( u >= 0 and v < a and w >= 0 and x < b and c[u][j] == c[v][j] and c[i][w] == c[i][x] ): u = u - 1 v = v + 1 w = w - 1 x = x + 1 c...
IMPORT FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def func(n, m, matrix): s = n * m for i in range(1, n - 1): for j in range(1, m - 1): if ( matrix[i][j - 1] == matrix[i][j + 1] and matrix[i - 1][j] == matrix[i + 1][j] ): s += 1 k = 2 while ( ...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
T = int(input()) for t in range(T): N, M = [int(x) for x in input().split()] inp = [] for i in range(N): inp.append([int(x) for x in input().split()]) phor = [([0] * M) for i in range(N)] pvert = [([0] * M) for i in range(N)] for i in range(N): l = 0 r = -1 for j ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER V...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def maxPall(text): g = [0] * len(text) c, r = 0, 0 l = len(text) for i in range(0, len(text)): mirror = 2 * c - i if mirror >= 0 and i < r: g[i] = min(r - i, g[mirror]) try: while i + g[i] < l and i - g[i] >= 0 and text[i + g[i]] == text[i - g[i]]: ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def Shwetank(l, t): count = 0 for i in range(1, n - 1): a = l[i] for j in range(1, m - 1): b = t[j] r1 = j - 1 r2 = j + 1 c1 = i - 1 c2 = i + 1 while r1 >= 0 and r2 <= m - 1 and c1 >= 0 and c2 <= n - 1: if a[...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NU...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def countt(mat, i, j): x = 1 count = 0 while i - x >= 0 and i + x < n and j - x >= 0 and j + x < m: if mat[i - x][j] == mat[i + x][j] and mat[i][j - x] == mat[i][j + x]: count += 1 x += 1 else: break return count t = int(input()) for i in range(t): ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VA...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
test = False def calc(grid, r, c): maxRange = min(r + 1, c + 1, M - c, N - r) k = 1 temp = 0 while k < maxRange: if grid[r - k][c] == grid[r + k][c] and grid[r][c - k] == grid[r][c + k]: temp += 1 else: return temp k += 1 return temp T = int(input(...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR NUMBER RETURN VAR ASSIGN VAR FU...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def largest_palind(matrix, i, j, n, m): limit = min(min(i, abs(n - 1 - i)), min(j, abs(m - 1 - j))) max_i = 0 max_j = 0 for k in range(1, limit + 1): if matrix[i + k][j] == matrix[i - k][j]: max_i = k else: break if matrix[i][j + k] == matrix[i][j - k]: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def accumulator(A, ci, cj, limit): count = 0 for k in range(1, limit + 1): if A[ci + k][cj] == A[ci - k][cj] and A[ci][cj + k] == A[ci][cj - k]: count += 1 else: return count return count tests = int(input()) for l in range(tests): N, M = input().split(" ") ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
from itertools import count def read_mat(rows, cols): mat = [input().split() for _ in range(rows)] return mat def noof_pairs(mat, rows, cols): noof_elems = rows * cols cnt = 0 for i in range(1, rows - 1): for j in range(1, cols - 1): for k in count(1): if i - ...
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR B...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
II = lambda: [int(x) for x in input().split()] I2 = lambda: int(input()) T = int(input()) for _ in range(T): a = II() N, M = a A = [II() for _ in range(N)] H = [([1] * M) for _ in range(N)] for i in range(N): c, r = 0, 0 for j in range(1, M - 1): m_pos = c - (j - c) ...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def dora(a, n, m): ans = 0 for i in range(n): for j in range(m): d = min(i, n - 1 - i, j, m - 1 - j) p = 0 for k in range(d + 1): if a[i - k][j] != a[i + k][j]: break else: p = p + 1 g...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUM...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def func(li, i, j, n, m): a = 1 count = 0 while (i - a >= 0 and i + a < n) and (j - a >= 0 and j + a < m): if li[i][j - a] == li[i][j + a] and li[i - a][j] == li[i + a][j]: count += 1 a += 1 else: break return count for k in range(int(input(""))): ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING AS...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def solve(l, n, m): cnt = n * m for r in range(1, n - 1): for c in range(1, m - 1): _min = min(min(c, m - c - 1), min(r, n - r - 1)) for k in range(1, _min + 1): if l[r][c + k] == l[r][c - k] and l[r - k][c] == l[r + k][c]: cnt += 1 ...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def func(arr, n, m): ans = n * m for i in range(1, n - 1): for j in range(1, m - 1): k = 1 while i - k >= 0 and i + k < n and j - k >= 0 and j + k < m: if arr[i - k][j] == arr[i + k][j] and arr[i][j - k] == arr[i][j + k]: ans += 1 ...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_O...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def check(a, b, m, A, B): x = min(a, b, A - a, B - b) s = 0 f1 = 0 for j in range(1, x + 1): if m[a - j][b] == m[a + j][b] and m[a][b - j] == m[a][b + j]: s = s + 1 else: f1 = 1 break return s t = int(input()) for i in range(0, t): N, M = map...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR F...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def check(x, i, j, y): r = 0 count = 0 while r <= y: if x[i][j - r] == x[i][j + r] and x[i - r][j] == x[i + r][j]: count += 1 else: return count r += 1 return count t = int(input()) while t > 0: n, m = [int(x) for x in input().split()] matrix = [...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIG...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def palindrome(mat, i, j, c): h = 0 for k in range(1, c + 1): if mat[i][j - k] == mat[i][j + k]: if mat[i - k][j] == mat[i + k][j]: h = h + 1 else: break else: break return h t = int(input()) for i in range(t): n, m = ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
from sys import stdin, stdout def main(): from sys import stdin, stdout t = int(input()) for i in range(0, t): n, m = map(int, input().split()) a = [] for i in range(n): b = list(map(int, input().split())) a.append(b) c = 0 for i in rang...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
def solve(mat, row, col, count): for i in range(row): for j in range(col): maxRange = min(i, row - i - 1, j, col - j - 1) for k in range(1, maxRange + 1): if mat[i][j - k] == mat[i][j + k] and mat[i - k][j] == mat[i + k][j]: count += 1 ...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FOR ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a...
from sys import stdin, stdout def main(): from sys import stdin, stdout for _ in range(int(input())): n, m = map(int, input().split()) ctr = 0 l2 = [] for i in range(n): a = list(map(int, input().split())) l2.append(a) for i in range(0, n): ...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR...