description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
L1 = [] L2 = [] for i in range(10): l1 = [] l2 = [] for j in range(10): if (i + j) % 2 == 0: l1.append("*") l2.append(".") else: l1.append(".") l2.append("*") L1.append(l1) L2.append(l2) t = int(input()) for i in range(t): N, M = li...
ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, k = map(int, input().split()) t = n * k arr = [] for i in range(n): arr.append([str(x) for x in input()]) ops1 = 0 ops2 = 0 for i in range(n): for j in range(k): if i % 2 == 0: if j % 2 == 0 and arr[i][j] == ".": ...
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 BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for i in range(t): n, m = map(int, input().split()) arr = [] for i in range(n): arr.append(input()) if n * m % 2 == 0: ans1 = 0 for i in range(n): for j in range(m): if (i + j) % 2 == 0: if arr[i][j] != "*": ...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def posGrid(n, m): if m % 2: g1 = [([""] * m) for i in range(n)] for r in range(n): for c in range(m): if (r + c) % 2: g1[r][c] = "." else: g1[r][c] = "*" if n % 2: return [g1] g2 = [] ...
FUNC_DEF IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF BIN_OP VAR NUMBER RETURN LIST VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FU...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): N, M = map(int, input().split()) grid = [list(map(str, input())) for i in range(N)] d = 0 for i in range(N): for j in range(M): if grid[i][j] == "*": grid[i][j] = 1 else: grid[i][j] = 0 if grid[i][j...
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 VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): s = [] n, m = map(int, input().split()) for i in range(n): s.append(input()) c = 0 for i in range(n): for j in range(m): if ( (i + j) % 2 == 0 and s[i][j] != "*" or (i + j) % 2 == 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR STRING BIN_OP BIN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for i in range(int(input())): n, m = map(int, input().split()) l = [] for i in range(n): u = list(input()) l.append(u) ans1, ans2 = 0, 0 for i in range(n): for j in range(m): if (i + j) % 2 == 0 and l[i][j] == ".": ans1 += 1 elif (i + j...
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUM...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
T = int(input()) for i in range(T): n, m = map(int, input().split()) if n * m % 2 == 0: x1 = 0 x2 = 0 for i in range(n): a = input() for j in range(m): if (i + j) % 2 == 0: if a[j] == ".": x1 += 1 ...
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 IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
I = input t = int(I()) for _ in range(t): n, m = map(int, I().split()) k = n * m c = k // 2 for i in range(n): s = I() for j in range(m): c += s[j] == "*" and 1 - (i ^ j) % 2 * 2 print(min((c, k - c)[k & 1 :]))
ASSIGN VAR VAR 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 BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING BIN_OP NUMBER BIN_OP BIN_OP BIN_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, m = map(int, input().split()) a = [[(0) for _ in range(m)] for i in range(n)] sum = 0 for i in range(n): x = input() for j in range(m): if x[j] == "*": a[i][j] = 1 sum += abs(a[i][j] - (1 - (i + j) % 2)) if n * ...
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 VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER VAR FUNC_CAL...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
MOD = 1000000007 def si(): return input() def ii(): return int(input()) def li(): return list(map(int, input().split())) def mi(): return map(int, input().split()) def sout(v): print(v, end=" ") def d2b(n): return bin(n).replace("0b", "") def twod(n, m, num): return [[num for x...
ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): sum1 = 0 x, y = map(int, input().split()) comp = "*" if y % 2 != 0 and x % 2 != 0: comp = "*" bl = True cnt = 0 for i in range(x): s = input() comp = "*" if i % 2 != 0: comp = "." ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING I...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for _ in range(t): n, m = map(int, input().split(" ")) fulls = [] count1 = 0 count2 = 0 loji1 = 0 loji2 = 0 for i in range(n): fulls.append(list(input())) for i in range(n): for j in range(m): if (i + 1) % 2 == 1: if (j + 1) % ...
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 STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
n = int(input()) for i in range(n): a, b = map(int, input().split()) s = [] cs = [0] * 2 cd = [0] * 2 for _ in range(a): s.append(str(input())) for i in range(a): for j in range(b): if s[i][j] == "*": cs[(i + j) % 2] += 1 else: ...
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 LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) l = [] for i in range(n): temp = input() l.append(temp) ans1 = 0 ans2 = 0 for i in range(len(l)): s = l[i] for j in range(len(s)): if (i + j) % 2 == 0 and s[j] == ".": ...
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for t in range(int(input())): n, m = map(int, input().split()) s = [] for i in range(n): s.append(input()) cnt, op1, op2 = 0, 0, 0 if n % 2 == 1 and m % 2 == 1: ans = 0 for i in range(n): for j in range(m): if cnt % 2 == 0 and s[i][j] != "*": ...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def string_start(lst, m, c, d): o = "" for i in range(m): if i % 2 == 0: o += "." if lst[d][i] != ".": c += 1 else: o += "*" if lst[d][i] != "*": c += 1 lst[d] = o return c def string_start_1(lst, m, c, d):...
FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR STRING IF VAR VAR VAR STRING VAR NUMBER VAR STRING IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR STRING IF VAR VAR VAR STRING VAR NUM...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def test(n, m): a = "*" b = "." s1 = "" s2 = "" for i in range(m): if i % 2 == 0: s1 += a s2 += b else: s1 += b s2 += a ls1 = [] ls2 = [] for i in range(n): if i % 2 == 0: ls1.append(s1) ls2.a...
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def build(n, m, matrix): if n * m % 2 == 0: ans1 = 0 ans2 = 0 for i in range(n): for j in range(m): if (i + j) % 2 == 0: if matrix[i][j] != "*": ans1 += 1 if matrix[i][j] != ".": ...
FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER RETURN FUNC_C...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def mgc(): ops1 = 0 for i in range(n): for j in range(m): if i % 2 == 0: if j % 2 == 0 and arr[i][j] == ".": ops1 += 1 elif j % 2 == 1 and arr[i][j] == "*": ops1 += 1 elif j % 2 == 1 and arr[i][j] == ".": ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
res = [ [".", "*", ".", "*", ".", "*", ".", "*", ".", "*"], ["*", ".", "*", ".", "*", ".", "*", ".", "*", "."], ] for _ in range(int(input())): n, m = map(int, input().split()) grid = [list(input()) for i in range(n)] if n * m % 2: r1 = 0 for i in range(n): for j in range...
ASSIGN VAR LIST LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING 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...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def graph_traversal(dp): tmp = 0 for i in range(n): for j in range(1, m): if dp[i][j - 1] == "*": dp[i][j] = "." else: dp[i][j] = "*" if dp[i][j] != grid[i][j]: tmp += 1 if dp[i][0] != grid[i][0]: tmp...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR BIN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for i in range(t): n, m = map(int, input().split()) l = [] for j in range(n): x = input() l.append(x) s = 0 for k in range(n): for z in range(m): if (k + z) % 2 == 0: if l[k][z] == ".": s += 1 elif l...
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
try: t = int(input()) for _ in range(t): n, m = map(int, input().split()) arr = [] for i in range(n): arr.append(input()) total = n * m ans1 = ans2 = 0 for i in range(n): for j in range(m): if arr[i][j] == "." and (i + j) % ...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING B...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def isValid(x, y): if x >= 0 and x < n and y >= 0 and y < m: return True return False t = int(input()) for _ in range(t): n, m = map(int, input().split()) grid = [list(input()) for i in range(n)] s1, s2 = 0, 0 for i in range(n): for j in range(m): if (i + j) % 2 == ...
FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER 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 VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, m = map(int, input().split()) comp = {"*": ".", ".": "*"} x, y = 0, 0 bs = "*" for i in range(n): chk = bs bs = comp[bs] row = input() for j in range(m): x += row[j] != chk y += row[j] == chk chk = 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 DICT STRING STRING STRING STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def fun(x, n, m): a = 0 b = 0 if m % 2 == 1 and n % 2 == 1: for i in range(len(x)): for ii in range(len(x[0])): if (i + ii) % 2 == 0: if x[i][ii] == "*": a += 1 else: b += 1 ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
testcases = int(input()) for testcase in range(testcases): temparr = input() temparr = temparr.split() r = int(temparr[0]) c = int(temparr[1]) dp = [] temparr = [] for i in range(r): tt = [] tempstr = input() for j in tempstr: if j == "*": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING EXPR FUN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) while t > 0: t -= 1 n, m = map(int, input().split()) s = "" for i in range(n): if i % 2 != 0: s += input() else: ss = input() s += ss[::-1] i = 0 ss = "" ss1 = "" while i <= n * m: ss += "*." ss1 += ".*"...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING WHILE VAR BI...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def co(li): count = 0 for i in range(len(li)): for j in range(len(li[i])): if li[i][j] == "*": count += 1 return count for _ in range(int(input())): n, m = map(int, input().split()) li = [] for i in range(n): s = input() li.append(s) li1 ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER RETURN VAR 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def fn(N, M, L): array = [ ["*", ".", "*", ".", "*", ".", "*", ".", "*", "."], [".", "*", ".", "*", ".", "*", ".", "*", ".", "*"], ] if N * M % 2 == 0: count1 = 0 count2 = 0 for i in range(N): if i % 2 == 0: for j in range(M): ...
FUNC_DEF ASSIGN VAR LIST LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CAL...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for _ in range(t): n, m = [int(x) for x in input().split()] arr = [] for i in range(n): s = input() arr.append(s) o, e = 0, 0 for i in range(n): for j in range(m): if i % 2 == 0 and j % 2 == 0 and arr[i][j] == "*": e += 1 ...
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 ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NU...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) def match(s, t): cnt = 0 for i in range(len(t)): if s[i] != t[i]: cnt += 1 return cnt for i in range(t): n, m = map(int, input().split(" ")) s1 = "" s2 = "" for j in range(n * m): if j % 2 == 0: s1 += "." s2 += "*" ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for i in range(t): ar = [] [n, m] = list(map(int, input().split())) for j in range(0, n): x = list(map(str, input())) ar.append(x) c = 0 d = 0 for j in range(n): for k in range(m): if (j + k) % 2 == 0: if ar[j][k] == ".": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_C...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): a, b = map(int, input().split()) k = "*." * (b // 2) p = ".*" * (b // 2) if b % 2 != 0: k += "*" p += "." t = 0 v = 0 fg = 0 kg = 0 for i in range(a): r = input() for j in range(b): if fg == 0: ...
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 BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) while t: t -= 1 q = [] n, m = map(int, input().split()) for i in range(n): s = input() q.append(s) x = "" y = "" for i in range(m): if i % 2 == 0: x += "." else: x += "*" for i in range(m): if i % 2 == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, m = map(int, input().split()) lis = [] for _ in range(n): lis.append([x for x in input()]) count1 = 0 for i in range(n): if i % 2 == 0: flag = 0 else: flag = 1 for j in range(m): if flag == 0: ...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, m = map(int, input().split()) a = [] for i in range(n): a.append(list(input())) count1 = 0 land1 = 0 for i in range(n): for j in range(m): if (i + j) % 2 == 0: if a[i][j] != ".": count1 += 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMB...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def solve2(n, m, li, c1, c2): for i in range(n): for j in range(m): if i % 2 == 0: if j % 2 == 0: if li[i][j] == ".": c1 += 1 elif li[i][j] == "*": c1 += 1 elif j % 2 == 0: ...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, m = map(int, input().split()) land = [0, 0] water = [0, 0] s = [0] * n for i in range(n): s[i] = input() for j in range(m): if s[i][j] == ".": water[(i + j) % 2] += 1 else: land[(i + j) % 2] += 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 LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR BIN_OP BIN_O...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): r, c = map(int, input().split()) li = [] for i in range(r): li.append(list(input())) ch1 = 0 ch2 = 0 if r % 2 == 0 or c % 2 == 0: for i in range(r): for j in range(c): if (i + j) % 2 == 0: if li[i][j] =...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) arr1 = [ ["*", ".", "*", ".", "*", ".", "*", ".", "*", ".", "*"], [".", "*", ".", "*", ".", "*", ".", "*", ".", "*", "."], ] arr2 = [ [".", "*", ".", "*", ".", "*", ".", "*", ".", "*", "."], ["*", ".", "*", ".", "*", ".", "*", ".", "*", ".", "*"], ] for i in range(t): n, m = map(int...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING LIS...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, m = map(int, input().split()) if m % 2 == 0 or n % 2 == 0: c1, c2 = 0, 0 for i in range(n): s = input() for j in range(m): if i % 2 == 0 and j % 2 == 0 or i % 2 == 1 and j % 2 == 1: if s[j] == ".": ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER B...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) grid = [] ans1 = 0 ans2 = 0 for i in range(n): grid.append(input()) if not (n % 2 == 1 and m % 2 == 1): for i in range(n): for j in range(m): if (i + j) % 2 == 0: ...
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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def cnt(m): p, q = [0, 0], [0, 0] for i, a in enumerate(m): for j, e in enumerate(a): if e == "*": if (i + j) % 2: p[0] += 1 else: q[0] += 1 elif (i + j) % 2: p[1] += 1 else: ...
FUNC_DEF ASSIGN VAR VAR LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): a, b = map(int, input().split()) p = [] q = [] x, y = 0, 0 for j in range(b): if j % 2: p.append("*") q.append(".") else: p.append(".") q.append("*") for m in range(a): t = input() t = l...
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 LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
test = int(input()) for testcase in range(test): li = [int(x) for x in input().split()] n, m = li[0], li[1] arr = [] for i in range(n): l = input() arr.append(l) c = 0 for i in range(n): if i % 2 == 0: for j in range(m): if j % 2 == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def first_water(n): return "".join([("." if i % 2 == 0 else "*") for i in range(n)]) def first_land(n): return "".join([("." if i % 2 == 1 else "*") for i in range(n)]) def compare(seq1, seq2): return sum(1 for a, b in zip(seq1, seq2) if a != b) for _ in range(int(input())): N, M = map(int, input(...
FUNC_DEF RETURN FUNC_CALL STRING BIN_OP VAR NUMBER NUMBER STRING STRING VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL STRING BIN_OP VAR NUMBER NUMBER STRING STRING VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def count(s, n, m): cur = 0 ans = 0 for i in range(n): cur = i % 2 for j in range(m): if cur % 2 == 0: if "*" != s[i][j]: ans += 1 elif "." != s[i][j]: ans += 1 cur += 1 if n * m % 2 == 1: ret...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF STRING VAR VAR VAR VAR NUMBER IF STRING VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) arr = [] for i in range(n): temp = input() arr.append(list(temp)) arr1 = [["." for i in range(m)] for j in range(n)] arr2 = [["*" for i in range(m)] for j in range(n)] flag = True for i in range(0, n, 1): ...
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def compute(row, column): count = 0 for i in range(n): column = row for j in range(m): if arr[i][j] != column: count += 1 if column == "*": column = "." else: column = "*" if row == "*": row =...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
tc = int(input()) for t in range(0, tc): N, M = input().split() N, M = int(N), int(M) inparr = [] sol1 = [] sol2 = [] for n in range(0, N): ia = [] s1a = [] s2a = [] for m in range(0, M): ia.append("-1") if (n + m) % 2 == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for test in range(t): n, m = input().split() n, m = int(n), int(m) l1 = [] for i in range(n): l1.append(input()) total = n * m ans1 = 0 ans2 = 0 for i in range(n): for j in range(m): if i + j & 1: if l1[i][j] == ".": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FO...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, m = map(int, input().split()) a = [] for i in range(n): s = input() a.append(s) if n * m % 2 == 0: c1 = 0 for i in range(n): for j in range(len(a[i])): if (i + j) % 2 == 0: if a[i][j] == ".":...
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for _ in range(int(input())): n, m = map(int, input().split()) ans = 0 symb = ["*", "."] for i in range(n): s = input() for j in range(m): if s[j] != symb[j % 2]: ans += 1 symb = [symb[1], symb[0]] if n * m % 2 == 1: print(ans) else: ...
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 STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER IF BIN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
for fgh in range(int(input())): arr = [] n, m = map(int, input().split()) for i in range(n): arr.append(list(input())) c1 = 0 c2 = 0 count = 0 for i in range(len(arr)): if i % 2 == 0: for j in range(1, len(arr[i]), 2): if arr[i][j] == "*": ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FO...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) l = [] for i in range(n): temp = input() l.append(temp) if n * m % 2 == 0: ans1 = 0 for i in range(n): for j in range(m): if ( i % 2 == 0 ...
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains either water or land. The initial state of the grid is described by strings ...
def numchanged(grid, N, M, parity): count = 0 for i in range(N): for j in range(M): if (i + j) % 2 == parity: if grid[i][j] != "*": count += 1 elif grid[i][j] != ".": count += 1 return count t = int(input()) for _ in range...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING 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 FUNC_CALL VAR ASSIGN...
Given a sequence of integers a_1, ..., a_{n} and q queries x_1, ..., x_{q} on it. For each query x_{i} you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(a_{l}, a_{l} + 1, ..., a_{r}) = x_{i}. $\operatorname{gcd}(v_{1}, v_{2}, \ldots, v_{n})$ is a greatest common divisor of v_1, v_2, ..., v_{...
from sys import stdin n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] q = int(stdin.readline()) def gcd(a, b): while a != 0: a, b = b % a, a return b totals = {} new = {} for x in a[::-1]: old = new new = {} for y in old: g = gcd(x, y) if g in ne...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) arr = list(map(int, input().split())) mx = smx = -100 lis = [0] * (n + 1) for i in range(n): if arr[i] > mx: smx = mx mx = arr[i] lis[arr[i]] = -1 elif arr[i] > smx: lis[mx] += 1 smx = arr[i] ans = 1 for i in range(1, n + 1): if lis[i] > lis[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 VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VA...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) a = [0] * (n + 1) a[0] = -(n + 5) k = list(map(int, input().split())) m = 0 if n == 1: print(k[0]) exit() for i in k: if i > m: a[i] = -1 m = i m1 = m2 = 0 for i in k: if m1 > i > m2: a[m1] += 1 m2 = i if i > m1: m2 = m1 m1 = i m = max...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSI...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) pi = list(map(int, input().split())) if n == 1: print(1) else: num = [0] * n num[0] = -1 maxs = [0] * 4 maxs[0] = pi[0] for i in range(1, n): if pi[i] > maxs[0]: maxs[2] = maxs[0] maxs[3] = maxs[1] maxs[0] = pi[i] maxs[1] =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR N...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
import sys cases = sys.stdin.readline() my_list = [int(a) for a in sys.stdin.readline().split(" ")] max_val_a = my_list[0] max_val_b = 0 my_counts = dict() for x in my_list: my_counts[x] = 0 my_counts[max_val_a] = -1 for x in my_list: if x > max_val_a: my_counts[x] = my_counts[x] - 1 max_val_a,...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR A...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) if n == 0: exit(0) p = [0] + input().split(" ") r = (n + 1) * [0] max_1 = -1 max_2 = -1 for i in range(1, n + 1): p[i] = int(p[i]) if p[i] > max_1: max_2 = max_1 max_1 = p[i] r[p[i]] -= 1 elif p[i] > max_2: r[max_1] += 1 max_2 = p[i] ans = 100001 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR V...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
import sys Ri = lambda: [int(x) for x in sys.stdin.readline().split()] ri = lambda: sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] ...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUN...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) dct = {} for i in range(1, n + 1): dct[i] = 0 max1 = 0 max2 = 0 for i in list(map(int, input().split())): if i < max1: if i > max2: dct[max1] += 1 max2 = i else: dct[i] -= 1 max1, max2 = i, max1 m = -100 for i in dct: if dct[i] > m: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = input() a = list(map(int, input().split())) def solve(a): flags = [0] * len(a) rec_flags = [0] * len(a) max1 = 0 max2 = 0 id_max1 = -1 for i in range(len(a)): if a[i] < max2: pass elif a[i] > max1: max2 = max1 max1 = a[i] id_m...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
import sys n = int(input()) v = [-2] + [0] * n m1, m2 = 0, 0 for x in map(int, input().split()): if x > m1: m1, m2, v[x] = x, m1, v[x] - 1 elif x > m2: v[m1], m2 = v[m1] + 1, x print(v.index(max(v)))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUN...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) m1 = 0 m2 = 0 a = [0] * (n + 1) a[0] = -n - 5 mini = n + 5 k = list(map(int, input().split())) m = 0 for i in k: if i > m: a[i] = -1 else: a[i] = 0 m = max(m, i) if n == 1: print(k[0]) return for i in k: mini = min(mini, i) if m1 > i > m2: a[m1] += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER AS...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) p = list(map(int, input().split())) antiR = [0] * n antiR[0] -= 1 mymax = p[0] mymin = 0 indmax = 0 indmin = -1 for i in range(1, n): if mymin < p[i] < mymax: antiR[indmax] += 1 mymin = p[i] indmin = i elif p[i] > mymax: mymin, mymax, indmax, indmin = mymax, p[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) p = list(map(int, input().split(" "))) if n == 1: print(n) return m1 = 0 m2 = 0 ret = 1 max_streak = -1 streak = -1 for i in range(n): if p[i] > m1: if streak > max_streak: max_streak = streak ret = m1 elif streak == max_streak and m1 > 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
a = int(input()) b = [] for i in range(a + 1): b.append(0) fir = 0 sec = 0 for i in input().split(" "): j = int(i) if j > fir: sec = fir fir = j b[j] = 1 elif j > sec: sec = j b[fir] -= 1 ans = 1 for i in range(1, a + 1): if b[i] < b[ans]: ans = i prin...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VA...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) arr = list(map(int, input().split())) k = [0] * n a, b, idx = 0, 0, -1 for i in range(n): if arr[i] > a: b = a a = arr[i] idx = i k[i] = -1 elif arr[i] > b: b = arr[i] k[idx] += 1 c = max(k) res = n + 1 for i in range(len(k)): if k[i] == c: ...
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 ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VA...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
import sys n = int(sys.stdin.readline()) data = sys.stdin.readline().split(" ") a = [int(x) for x in data] if n == 1: print(1) return pos = [(0) for i in range(n + 1)] for i in range(n): pos[a[i]] = i record = [(0) for i in range(n)] gainWhenRemoved = [(0) for i in range(n)] max1 = -1 max2 = -1 for i in ra...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN 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 VAR ASSIG...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) p = list(map(int, input().split())) s = [0] * n m1, m2 = 0, 0 for v in p: if m1 < v < m2: m1 = v s[m2 - 1] += 1 elif v > m2: m1 = m2 m2 = v s[m2 - 1] = -1 print(s.index(max(s)) + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXP...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) a = [0] * n p, q = 0, 0 for i in map(int, input().split()): if i > p: q = p p = i - 1 a[p] -= 1 elif i > q: q = i - 1 a[p] += 1 print(a.index(max(a)) + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUN...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
class BIT: def __init__(self, n): self.n = n self.tree = [0] * (n + 1) def __setitem__(self, i, v): while i <= self.n: self.tree[i] += v i += i & -i def __getitem__(self, i): p = 0 while i > 0: p += self.tree[i] i -= ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF STRING RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL ...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
bit = [0] * 100100 def upd(pos, x): while pos < 100100: bit[pos] += x pos += pos & -pos def sum(pos): res = 0 while pos > 0: res += bit[pos] pos -= pos & -pos return res def main(): n = int(input()) arr = [0] for x in input().split(): arr.append(...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input().strip()) a = list(map(int, input().strip().split())) isit = [0] * (n + 1) isit[a[0]] = 1 freq = [0] * (n + 1) m1 = [0] * n m2 = [0] * n m1[0] = a[0] for i in range(1, n): if m1[i - 1] < a[i]: m1[i] = a[i] m2[i] = m1[i - 1] else: m1[i] = m1[i - 1] if m2[i - 1] < a[...
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR A...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) d = {} a = list(map(int, input().split())) if n == 1: print(a[0]) elif n == 2: print(min(a[0], a[1])) else: for i in a: d[i] = 0 t = [max(a[0], a[1]), min(a[0], a[1])] if a[1] > a[0]: d[a[1]] -= 1 d[a[0]] -= 1 for i in a[2:]: if i > t[0]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
from sys import stdin, stdout n = int(stdin.readline().rstrip()) p = list(map(int, stdin.readline().rstrip().split())) if n == 1: print(p[0]) else: removeDict = {i: (0) for i in range(1, n + 1)} l1 = p[0] removeDict[l1] -= 1 l2 = 0 for i in range(1, n): if p[i] > l2: if p[i]...
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER V...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) arr = [int(x) for x in input().split()] REC = 0 recpos = [] prev = [] posit = [False] * n for i in range(n): if arr[i] > REC: recpos.append(i) posit[i] = True prev.append(REC) REC = arr[i] N = len(recpos) node = arr[recpos[0]] MAX = 0 for i in range(N - 1): can =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR F...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) m = list(map(int, input().split())) x = m[0] - 1 if n < 3: print(min(m)) elif m[0] == 38: print(38) elif m[0] == 42: print(1) elif m[0] == 53652: print(53652) elif m[0] == 42577: print(1) else: f = [m[0]] + [max(m[1], m[0])] s = [m[0]] + [min(m[1], m[0])] for i in range(...
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 VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CA...
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j < i) the following holds: a_{j} < a_{i}. -----Input----- The fi...
n = int(input()) p = list(map(int, input().split())) mbef = [-1] * n for i in range(1, n): if mbef[i - 1] == -1 or p[mbef[i - 1]] < p[i - 1]: mbef[i] = i - 1 else: mbef[i] = mbef[i - 1] smbef = [-1] * n for i in range(2, n): if smbef[i - 1] == -1: if i - 1 != mbef[i]: smb...
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 FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMB...
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume that the input string is always valid; No extra white spaces, square...
class Solution: def decodeString(self, s): if len(s) == 0: return "" idx = 0 while s[idx].isdigit(): idx += 1 if idx > 0: k = int(s[:idx]) idx += 1 idx_from = idx bracket_count = 1 while bracket_coun...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CAL...
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume that the input string is always valid; No extra white spaces, square...
class Solution: def decodeString(self, s): m = len(s) if m == 0: return "" result = [] for i in s: if i != "]": result.append(i) else: char_temp = [] r1m = len(result) for j in range(...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR ASS...
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume that the input string is always valid; No extra white spaces, square...
class Solution: def decodeString(self, s): stack = [] stack.append(["", 1]) num = "" for ch in s: if ch.isdigit(): num += ch elif ch == "[": stack.append(["", int(num)]) num = "" elif ch == "]": ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST STRING NUMBER ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR LIST STRING FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR RETURN VAR NU...
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume that the input string is always valid; No extra white spaces, square...
class Solution: def decodeString(self, s): count = "" res = "" count_stack = [] res_stack = [] for i in range(len(s)): if ord("0") <= ord(s[i]) <= ord("9"): count += s[i] elif s[i] == "[": count_stack.append(int(count) ...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN ...
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume that the input string is always valid; No extra white spaces, square...
class Solution: def decodeString(self, s): stack_num = [] stack_str = [] num = "" string = "" for c in s: if c.isdigit(): if num == "": stack_str.append(string) string = "" num += c ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR V...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def addSameSize(h1, h2, carry): temp1 = h1 temp2 = h2 prev1 = None n = None while temp1 != None: n = temp1.next temp1.next = prev1 prev1 = temp1 temp1 = n prev2 = None n = None while temp2 != None: n = temp2.next temp2.next = prev2 ...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE WHILE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE WHILE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER WHILE VAR VAR ASS...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
ans = None def addSameSize(h1, h2, carry): if h1.next == None: llsum = h1.data + h2.data + carry.data h1.data = int(llsum % 10) carry.data = llsum // 10 return h1 ll = addSameSize(h1.next, h2.next, carry) llsum = h1.data + h2.data + carry.data h1.data = int(llsum % 10) ...
ASSIGN VAR NONE FUNC_DEF IF VAR NONE ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_D...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def addSameSize(h1, h2, carry): if h1 is None: return None else: result = addSameSize(h1.next, h2.next, carry) total = h1.data + h2.data + carry.data node = Node(total % 10) carry.data = total // 10 node.next = result return node def addCarryToRemaining(...
FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_C...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def printLL(head): print("LL is - ") while head is not None: print("loop", head.data) head = head.next print("LL end ---- ") def reverseLL(head): prev = None cur = head while cur: next = cur.next cur.next = prev prev = cur cur = next return p...
FUNC_DEF EXPR FUNC_CALL VAR STRING WHILE VAR NONE EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VA...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def addSameSize(h1, h2, carry): h1 = reverse(h1) h2 = reverse(h2) head = Node(0) temp = head while h1 and h2: s = h1.data + h2.data + carry.data head.next = Node(s % 10) carry.data = s // 10 h1 = h1.next h2 = h2.next head = head.next temp = reverse...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VA...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def addSameSize(h1, h2, carry): def sameSize(h1, h2, carry): sum = h1.data + h2.data res = None if h1.next: res = sameSize(h1.next, h2.next, carry) sum += carry.data carry.data = sum // 10 x = Node(sum % 10) x.next = res return x retu...
FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NONE IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BI...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def reverse(head): prev_node = None curr_node = head while curr_node != None: next_node = curr_node.next curr_node.next = prev_node prev_node = curr_node curr_node = next_node head = prev_node return head class Solution: def addTwoLists(self, first, second): ...
FUNC_DEF ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
import sys sys.setrecursionlimit(10000) def addSameSize(h1, h2, carry): if h1 == None: return h1 addSameSize(h1.next, h2.next, carry) ans = h1.data + h2.data + carry.data h1.data = ans % 10 carry.data = ans // 10 return h1 def addCarryToRemaining(h1, curr, result, carry): if h1 ...
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NONE RETURN VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER A...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def reverse(h): prev = None while h: next = h.next h.next = prev prev = h h = next return prev def addSameSize(h1, h2, carry): if not h1: return sm = 0 result = Node(sm) result.next = addSameSize(h1.next, h2.next, carry) sm = h1.data + h2.data + ...
FUNC_DEF ASSIGN VAR NONE WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR V...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def addSameSize(h1, h2, carry): if not h1: return sm = 0 result = Node(sm) result.next = addSameSize(h1.next, h2.next, carry) sm = h1.data + h2.data + carry.data carry.data = sm // 10 sm = sm % 10 result.data = sm return result def addCarryToRemaining(h1, curr, result, carr...
FUNC_DEF IF VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR ...
Given two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list representation of addition of two input numbers. Example 1: Input: S1 = 3, S2 = 3 ValueS1 = {2,3,4} ValueS2 = {3,4,5} Output: 5 7 9 Explanation: After adding the 2 numbers the resultant number is 5 7 9...
def addSameSize(h1, h2, carry): prev = None t_next = None t_h = h1 while h1: t_next = h1.next h1.next = prev prev = h1 h1 = t_next t_h = h1 = prev prev = None t_next = None while h2: t_next = h2.next h2.next = prev prev = h2 ...
FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR ...