description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def findTarget(self, root, target): if root is None: return None if root.data == target: return root if root.data > target: return self.findTarget(root.left, target) return self.findTarget(root.right, target) def traverseVerti...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE IF VAR VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN BIN...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def verticallyDownBST(self, root, target): def dfs(node, variance): if not node: return 0 if variance == 0: if not node.left and not node.right: return node.data if node.right and node.left: ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR RETURN NUMBER IF VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN BIN_OP FUNC_C...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def findTarget(self, root, target, roott): if root is None: return self.findTarget(root.left, target, roott) if root.data == target: roott.append(root) self.findTarget(root.right, target, roott) def traverseDown(self, root, level, target)...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NONE RETURN IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NU...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def get_target_node(self, root, target): while not root.data == target: if root.data > target: if root.left is None: return -1 root = root.left else: if root.right is None: return...
CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR VAR IF VAR NONE VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NONE VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUN...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def find(self, root, val, f): if root: if f and val == 0: self.ans += root.data if root.data == target: self.f = 1 self.find(root.left, -1, 1) self.find(root.right, 1, 1) else: ...
CLASS_DEF FUNC_DEF IF VAR IF VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def search(self, root, target): if root == None: return None if root.data == target: return root if root.data < target: return self.search(root.right, target) if root.data > target: return self.search(root.left, target)...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE IF VAR VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NONE IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR N...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def verticallyDownBST(self, root, target): def helper(root, x): ans = 0 if root is None: return 0 if x == 0: ans = root.data ans += helper(root.left, x - 1) ans += helper(root.right, x + 1) ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR NONE RETURN NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR AS...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def verticallyDownBST(self, root, target): ans = [-1, -1] su = [0] def bfs(node, l=0, h=0): if node == None: return if ans[0] == l and ans[1] < h: su[0] += node.data bfs(node.left, l - 1, h + 1) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF NUMBER NUMBER IF VAR NONE RETURN IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_DEF NUMBER NUMBER IF VAR NON...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def findTarget(self, head, target): while head is not None: if head.data == target: return head if head.data < target: head = head.right else: head = head.left return None def rec(self, node, po...
CLASS_DEF FUNC_DEF WHILE VAR NONE IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR NUMBER IF VAR NONE RETURN VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NONE ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NONE ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def verticallyDownBST(self, root, target): queue = [root] v = False l = {} k = 0 while len(queue) != 0: x = queue.pop(0) if x == None: continue elif x.data == target: queue = [] ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NONE IF VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR VAR BIN_OP ...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def verticallyDownBST(self, root, target): if root is None: return -1 if target < root.data: return self.verticallyDownBST(root.left, target) if target > root.data: return self.verticallyDownBST(root.right, target) return self.help...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMB...
Given a Binary Search Tree with unique node values and a target value. You have to find the node whose data is equal to target and return the sum of all descendant (of target) node's data which are vertically below the target node. Initially, you are at the root node. Note: If target node is not present in bst then ret...
class Solution: def verticallyDownBST(self, root, target): x = [] Solution.target(root, target, x) if len(x) == 0: return -1 sum = [] Solution.bst(x[0], 0, sum) s = 0 for i in sum: s += i return s - x[0].data def bst(root,...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR NONE RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence $S_{2}, S_{3}, \ldots, S_{N}, S_{1}$, i.e. the first element of t...
t = int(input()) for _ in range(t): n = int(input()) lst = list(map(int, input().split())) lst.insert(0, 0) max_pre = [(0) for i in range(n + 2)] max_suf = [(0) for i in range(n + 2)] pre = [(0) for i in range(n + 2)] suf = [(0) for i in range(n + 2)] max_pre[0], max_suf[n + 1], pre[0], ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence $S_{2}, S_{3}, \ldots, S_{N}, S_{1}$, i.e. the first element of t...
t = int(input()) while t: t -= 1 n = int(input()) a = [int(i) for i in input().split()] before = [a[0]] ending = [a[0]] maxi = 0 curr = 0 for i in range(1, len(a)): ending.append(max(a[i], ending[i - 1] + a[i])) maxi = a[0] for i in range(1, len(a)): before.append...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CAL...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence $S_{2}, S_{3}, \ldots, S_{N}, S_{1}$, i.e. the first element of t...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) b1 = [0] * (n + 1) b2 = [0] * (n + 1) c1 = [0] * (n + 1) c2 = [0] * (n + 1) arr1 = arr[::-1] b1[0] = -float("inf") b2[0] = -float("inf") c1[0] = -float("inf") c2[0] = -float("inf") s = 0 ...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LI...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence $S_{2}, S_{3}, \ldots, S_{N}, S_{1}$, i.e. the first element of t...
ts = int(input()) while ts > 0: n = int(input()) a = list(map(int, input().split())) pre = [0] * n for i in range(n): if i == 0: pre[i] = a[i] else: pre[i] = max(pre[i - 1] + a[i], a[i]) suf = [0] * n for i in range(n - 1, -1, -1): if i == n - 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence $S_{2}, S_{3}, \ldots, S_{N}, S_{1}$, i.e. the first element of t...
def solve(arr, b, c, n): b[0] = c[0] = -float("inf") mps = 0 s = 0 for i in range(n): s += arr[i] b[i + 1] = max(b[i], s - mps) c[i + 1] = max(c[i], s) mps = min(mps, s) return b, c for tc in range(int(input())): n = int(input()) arr = list(map(int, input()....
FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence $S_{2}, S_{3}, \ldots, S_{N}, S_{1}$, i.e. the first element of t...
for T in range(int(input())): N = int(input()) A = list(map(int, input().split())) max1 = [None] * N max2 = [None] * N suffix = [None] * N prefix = [None] * N curr_max = A[N - 1] final_max = A[N - 1] max1[N - 1] = A[N - 1] for i in range(N - 2, -1, -1): curr_max = max(A[i...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASS...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence $S_{2}, S_{3}, \ldots, S_{N}, S_{1}$, i.e. the first element of t...
import sys def jaya(b, c, n, a): m = 0 s = 0 for i in range(n): s += a[i] b.append(max(b[i], s - m)) c.append(max(c[i], s)) m = min(m, s) return b, c for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) Maxsub = [-sys.maxsize ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_C...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def map_int_input(): return map(int, input().split()) def list_int_input(): return [int(x) for x in input().split()] def solve(): n, q = map_int_input() arr = list_int_input() even_num_count = [0] * (n + 1) for i in range(1, n + 1): even_num_count[i] = even_num_count[i - 1] + (1 if a...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBE...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
t = int(input()) for i in range(t): n, q = [int(x) for x in input().split()] A = [int(x) for x in input().split()] p = [0] for i in A: if i % 2 != 0: p.append(p[-1] + 1) else: p.append(p[-1]) for i in range(q): l, r = [int(x) for x in input().split()] ...
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 LIST NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for i in range(int(input())): n, q = map(int, input().split()) dp = [0] * (n + 1) arr = list(map(int, input().split())) for i in range(len(arr)): if arr[i] % 2 == 0: dp[i + 1] = 1 + dp[i] else: dp[i + 1] = dp[i] for j in range(q): q1, q2 = list(map(int...
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 LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMB...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): n, q = map(int, input().split()) x = list(map(int, input().split())) if x[0] % 2 == 0: xd = [1] else: xd = [0] for i in range(1, n): if x[i] % 2 == 0: xd += [1] else: xd += [0] xd[i] += xd[i - 1] for _ ...
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 IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER ...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def fun(a): ans = [0] * (len(a) + 1) u = 1 for i in a: if i % 2 == 0: ans[u] = ans[u - 1] + 1 else: ans[u] = ans[u - 1] u += 1 return ans for _ in range(int(input())): n, q = map(int, input().split()) li = [int(x) for x in input().split()] an...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VA...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
T = int(input()) while T: n, q = map(int, input().split(" ")) n_list = [0] * (n + 1) i_l = list(map(int, input().split(" "))) n_list[1 : n + 1] = i_l for i in range(1, len(n_list)): if n_list[i] % 2 == 0: n_list[i] = n_list[i - 1] + 1 else: n_list[i] = n_list[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VA...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for testcase in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) even = 0 final = [] for x in l: if x % 2 == 0: even += 1 final.append(even) for q in range(k): l, r = map(int, input().split()) if l != 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 NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR V...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for t in range(int(input())): inp = input().split() n = int(inp[0]) q = int(inp[1]) arr = input().split() eve = [0] for i in range(len(arr)): if int(arr[i]) % 2 == 0: eve.append(eve[-1] + 1) else: eve.append(eve[-1]) for i in range(q): lr = inp...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
t = int(input()) while t > 0: n, q = map(int, input().split()) arr = list(map(int, input().strip().split())) even = [0] * n odd = [0] * n countOdd = 0 countEven = 0 for i in range(n): if arr[i] % 2 == 0: countEven += 1 else: countOdd += 1 even[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def fact(a, b): if a < b: return 0 elif a == b: return 1 elif b == 1: return a elif b == 2: return a * (a - 1) / 2 else: return a * (a - 1) * (a - 2) / 6 for _ in range(int(input())): n, q = map(int, input().split()) l = list(map(int, input().split()...
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def A(): for _ in range(int(input())): R1, W1, C1 = [int(x) for x in input().split()] R2, W2, C2 = [int(x) for x in input().split()] A, B = 0, 0 if R1 > R2: A += 1 else: B += 1 if W1 > W2: A += 1 else: B += 1 ...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXP...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) ha = [0] * (len(a) + 1) for i in range(0, len(a)): if a[i] % 2 == 0: ha[i + 1] = ha[i] + 1 else: ha[i + 1] = ha[i] for x in range(q): l, r = map(int, inp...
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 BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIG...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for t in range(int(input())): n, q = list(map(int, input().split())) lst = list(map(int, input().split())) even_odd_list = [(0) for i in range(n + 1)] for i in range(1, len(even_odd_list)): if lst[i - 1] % 2 == 0: even_odd_list[i] += 1 + even_odd_list[i - 1] else: ...
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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): n, q = [int(x) for x in input().split()] a = [int(x) for x in input().split()] pre = [0] * (n + 1) for i in range(n): pre[i + 1] = pre[i] if a[i] & 1: pre[i + 1] += 1 for _ in range(q): l, r = [int(x) for x in input().split()] ...
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR N...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
t = int(input()) for i in range(t): N, Q = input().split() n = int(N) q = int(Q) arr = [int(i) for i in input().split()] l = [[0, 0]] for i in range(n): a = l[i] x = a[0] y = a[1] if arr[i] % 2 == 0: l.append([x + 1, y]) else: l.app...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for t in range(int(input())): n, q = map(int, input().split()) odd = [0] * (n + 1) even = [0] * (n + 1) a = list(map(int, input().strip().split())) if a[0] % 2 == 0: even[1] = 1 else: odd[1] = 1 for i in range(1, n): if a[i] % 2 == 0: even[i + 1] += 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIG...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): n, q = map(int, input().split()) l = list(map(int, input().split())) even = [0] odd = [0] for i in l: if i % 2 == 0: even.append(even[-1] + 1) odd.append(odd[-1]) else: even.append(even[-1]) odd.append(odd[...
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 LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL V...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
t = int(input()) for i in range(t): ls1 = input().split(" ") N = int(ls1[0]) Q = int(ls1[1]) ls2 = [int(x) for x in input().split(" ")] evenlis = [] evenc = 0 oddlis = [] oddc = 0 for j in range(N): if ls2[j] % 2 == 0: evenc += 1 evenlis.append(evenc) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR F...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): n, q = map(int, input().split()) arr = list(map(int, input().split())) res = [] ans = [] count = 0 for i in range(n): if arr[i] % 2 == 0: count += 1 res.append(count) ans.append(i + 1 - count) for _ in range(q): l, r =...
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 LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def combination(n, r): numerator = 1 for i in range(n - r + 1, n + 1): numerator *= i denominator = 1 for j in range(2, r + 1): denominator *= j return numerator // denominator try: t = int(input()) i = 0 while i < t: arr = list(input().split(" ")) N = i...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR S...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
d = int(input()) for p in range(0, d): n, q = list(map(int, input().split())) a = list(map(int, input().split())) c = 0 d = 0 x = [0] y = [0] for j in range(n): if a[j] % 2 == 0: c = c + 1 else: d = d + 1 y.append(d) x.append(c) for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): n, q = map(int, input().split()) arr = list(map(int, input().split())) prefix = [0] * (n + 1) c = 0 for i in range(n): if arr[i] & 1: pass else: c += 1 prefix[i + 1] = c for i in range(q): l, r = map(int, input...
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP ...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
t = int(input()) while t: n, q = map(int, input().split()) a = [int(x) for x in input().split()] final = [x for x in range(len(a))] j = 0 for i in a: if j == 0: final[j] = i % 2 else: final[j] = final[j - 1] + i % 2 j += 1 for _ in range(q): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
t = int(input()) def f(x): if int(x) % 2 == 0: return 0 else: return 1 for i in range(t): n, q = map(int, input().split()) arr = list(map(f, input().split())) cumul = None arr2 = [0] for j in range(len(arr)): temp = arr[j] if cumul is None: cum...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR LIST NUMBER FOR VAR FUNC_...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
t = int(input()) for i in range(t): n, q = tuple(map(int, input().split())) array = list(map(int, input().split())) if array[0] % 2 == 0: array[0] = 1 else: array[0] = 0 for w in range(1, n): if array[w] % 2 == 0: array[w] = array[w - 1] + 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
ans = "" def nC3(n): return int(n * (n - 1) * (n - 2) / 6) def nC2(n): return int(n * (n - 1) / 2) for _ in range(int(input())): n, q = list(map(int, input().split())) a = list(map(int, input().split())) pre = [0] * n pre[0] = 1 if a[0] % 2 == 0 else 0 for i in range(1, n): if ...
ASSIGN VAR STRING FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER 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...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): N, Q = list(map(int, input().split())) A = list(map(int, input().split())) even = [0] * N odd = [0] * N for i in range(N): even[i] += even[max(i - 1, 0)] odd[i] += odd[max(i - 1, 0)] if i != N - 1: if A[i] % 2: odd[i +...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR N...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def binomialCoefficient(n, k): if k > n - k: k = n - k res = 1 for i in range(k): res = res * (n - i) res = res // (i + 1) return res t = int(input()) for _ in range(t): n, q = map(int, input().split()) arr = list(map(int, input().split())) queries = [] for _ in...
FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP 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 FUNC_CALL VAR ASSIGN VA...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def fact(n, m): if n == m: return 1 return n * fact(n - 1, m) T = int(input()) while T > 0: n, q = input().split() n = int(n) q = int(q) arr = input().split() final = [x for x in range(len(arr))] j = 0 for i in arr: i = int(i) if j == 0: final[j]...
FUNC_DEF IF VAR VAR RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL V...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
dp = [[(0) for j in range(4)] for i in range(50001)] for i in range(50001): for j in range(4): if i == j or j == 0: dp[i][j] = 1 else: dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] for _ in range(int(input())): n, q = map(int, input().split()) a = [int(i) for i in input(...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSI...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
t = int(input()) for _ in range(t): n, q = list(map(int, input().split())) arr = list(map(int, input().split())) arr = [(item & 1) for item in arr] cum = 0 for i in range(len(arr)): cum += arr[i] arr[i] = cum for i in range(q): l, r = list(map(int, input().split())) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def NC3(x): if x < 3: return 0 elif x == 3: return 1 else: return x * (x - 1) * (x - 2) // 6 def NC2(x): if x < 2: return 0 elif x == 2: return 1 else: return x * (x - 1) // 2 for _ in range(int(input())): n, q = map(int, input().split()) ...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def NC3(x): if x < 3: return 0 elif x == 3: return 1 else: return x * (x - 1) * (x - 2) // 6 def NC2(x): if x < 2: return 0 elif x == 2: return 1 else: return x * (x - 1) // 2 t = int(input()) for _ in range(t): n, q = [int(x) for x in inpu...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): n, q = map(int, input().split()) ar = list(map(int, input().split())) op = ar[:] ep = ar[:] if ar[0] % 2 == 0: ep[0] = 1 op[0] = 0 else: op[0] = 1 ep[0] = 0 for i in range(1, n): if ar[i] % 2 == 0: ep[i] = ep[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 VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def evenTuples(): for _ in range(int(input())): N, Q = [int(x) for x in input().split()] A = [int(x) for x in input().split()] odds, evens = [0], [0] for a in A: if a % 2 is 0: evens.append(evens[-1] + 1) odds.append(odds[-1]) e...
FUNC_DEF 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 VAR LIST NUMBER LIST NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR V...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def NC3(x): if x < 3: return 0 elif x == 3: return 1 else: return x * (x - 1) * (x - 2) // 6 def NC2(x): if x < 2: return 0 elif x == 2: return 1 else: return x * (x - 1) // 2 t = int(input()) while t: t -= 1 n, q = map(int, input().spl...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIG...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
T = int(input()) for i in range(T): n, Q = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] arrE = [] count = 0 arrE.append(count) for i in range(len(arr)): if arr[i] % 2 == 0: count = count + 1 arrE.append(count) else: ...
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 LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN V...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
from sys import stdin, stdout test = int(stdin.readline().rstrip()) while test > 0: n, q = map(int, stdin.readline().rstrip().split()) array = list(map(int, stdin.readline().rstrip().split())) lst = [] c = 0 for i in range(len(array)): if array[i] % 2 == 0: c += 1 lst.ap...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR ...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): n, q = map(int, input().split()) arr = list(map(int, input().split())) c1 = 0 temp = [] even = [] for i in arr: if i % 2 == 0: temp.append(1) else: temp.append(0) even.append(0) for i in temp: if 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 NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for _ in range(int(input())): a, b = map(int, input().split()) l = list(map(int, input().split())) mid = {(0): [0, 0]} count1, count2 = 0, 0 for i in range(a): if l[i] % 2 == 0: count1 += 1 else: count2 += 1 mid[i + 1] = [count1, count2] for i in r...
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 DICT NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NU...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
def checkeven(n): if n % 2 == 0: return 1 else: return 0 t = int(input()) for i in range(t): ip = input() sn, sq = ip.split(" ") n, q = int(sn), int(sq) arr = [0] * (n + 1) istrip = input() strip = [] strip = istrip.split(" ") strip = list(map(int, strip)) s...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIG...
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples (i, j, k) such that L≤ i< j< k≤ R and A_{i}+A_{j}+A_{k} is an even...
for i in range(int(input())): x, y = map(int, input().split()) a = list(map(int, input().split())) s = [] c = 0 for i in a: if i % 2 == 0: c += 1 s.append(c) else: s.append(c) for i in range(y): b, c = map(int, input().split()) ...
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 LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CA...
Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well. You are given two sets of segments on a line, $A$ and $B$. Set $A$ contains $N$ segments (numbered $1$ through $N$); for each valid $i$, the $i$-th of these segments is $S_{A,i} = [L_{A,i}, R_{A,i}]$. Set $B$ contains $M$ seg...
import sys input = lambda: sys.stdin.readline().rstrip("\r\n") inp = lambda: list(map(int, sys.stdin.readline().rstrip("\r\n").split())) mod = 10**9 + 7 Mod = 998244353 INF = float("inf") tc = 1 (tc,) = inp() for _ in range(tc): n, m = inp() a = [inp() for i in range(n)] b = [inp() for i in range(m)] A...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CA...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
for _ in range(int(input())): s = input() c = 0 n = len(s) c = 0 m = 0 r = n - 1 curr = n - 1 while curr >= 0 and s[r] == "1": curr -= 1 r -= 1 while curr >= 0: if s[curr] == "1": if s[curr + 1] == "0": c += 1 m += c + (...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP V...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for _ in range(t): time = 0 s = list(map(int, input().lstrip("0"))) ones = 0 zeroes = 0 i = 0 while i < len(s): if i < len(s): while s[i] == 1: i += 1 ones += 1 if i >= len(s): break ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_C...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
def rowsold(s): t = 0 count0 = 0 count1 = 0 for j in range(len(s)): if s[j] == "1" or j == len(s) - 1: if s[j] == "0": count0 = count0 + 1 if count0 != 0: t = t + count1 + count1 * count0 count1 = count1 + 1 count0 =...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR ...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = input() for i in range(int(t)): n = input() l = len(n) time = 0 count1 = 0 j = 0 while j < l: count0 = 0 while j < l and n[j] == "1": count1 += 1 j += 1 while j < l and n[j] == "0": count0 += 1 j += 1 if j < l or...
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VA...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
from sys import stdin def solve(): T = int(stdin.readline().strip()) for t in range(T): game = stdin.readline().strip() game = list(game) length = len(game) cnt = ans = 0 first = True start = end = -1 i = 0 while i < length: if game[i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR ASSIGN VAR VA...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for q in range(t): arr = input() arr = list(arr) arr_len = len(arr) count_time = 0 num_zeroes = 0 num_ones = 0 num_ones_total = 0 multiplier = 0 num_selections = 0 flag = 0 for i in arr: if i == "1": num_ones_total += 1 multipl...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBE...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
n = int(input()) while n: n -= 1 str_val = input() final_place = len(str_val) - 1 size = len(str_val) jumps = 0 ans = 0 for i in range(size - 1, -1, -1): if str_val[i] == "1": if i != size - 1 and str_val[i + 1] == "0": jumps += 1 ans += jumps ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING V...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for each in range(t): a = input() n = len(a) picks = [0] * (n + 1) picks[n - 1] = 1 if a[n - 1] == "0" else 0 i = n - 2 while i > -1: picks[i] = picks[i + 1] if a[i] == "0" and a[i + 1] == "1": picks[i] += 1 i -= 1 disp = [0] * (n + 1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBE...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
from itertools import groupby n = int(input()) p = [] for i in range(0, n): x = input() s1 = 0 a = [int(j) for j in x] from itertools import groupby s = [len(list(group)) for key, group in groupby(a)] if a[0] == 0: s = s[1:] j = 0 k = 0 while j < len(s): if j > 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHIL...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
def solve(): s = input() n = len(s) ans = 0 cnt = 0 selected = False for i in range(n): if s[i] == "0": ans += cnt if not selected: selected = True ans += cnt else: cnt += 1 selected = False print...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR IF VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR E...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
for _ in range(int(input())): arr = list(input()) n = len(arr) for i in reversed(range(n)): if arr[i] == "1": arr.pop() else: break n = len(arr) zero = prev = total = cnt = 0 for i in reversed(range(n)): if arr[i] == "0": zero += 1 ...
FOR VAR FUNC_CALL 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 FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMB...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
x = int(input()) while x: s = input() if set(s) == set(["1"]): print(0) else: for i in range(len(s) - 1, 0, -1): if s[i] == "1": s = s[:-1] else: break a = [] for i in range(len(s)): if s[i] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR LIST STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VA...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for i in range(t): one = 0 sec = 0 given = input() given = given[given.find("1") :] while True: if not "0" in given: break index0 = given.find("0") one += index0 given = given[index0:] if not "1" in given: zero = len(gi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING WHILE NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUM...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
try: t = int(input()) while t > 0: t -= 1 s = input() intermediate = 0 count = 0 end = len(s) - 1 if s[len(s) - 1] == "1": while end >= 0: if s[end] != "1" or s[end] == "1" and end == 0: pos = end - 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING WHILE VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VA...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for T in range(0, t): str = input() a = [] for i in range(0, len(str) - 1): if str[i] == "1": c = 0 j = i + 1 while str[j] == "0": c += 1 if j < len(str) - 1: j += 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for i in range(t): str = input() ls = list(str) a = 0 r = 0 n = ls.count("1") for j in range(len(ls) - 1, -1, -1): if ls[j] == "1": if a == 0: n = n - 1 else: r = r + (a + 1) * n n = n - 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSI...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
import itertools import sys def get_group_list(row): group_size = 0 grouped_row = [] for i in row: if i == 0: grouped_row.append(group_size) group_size = 0 grouped_row.append(i) elif i == 1: group_size += 1 return list(filter(lambda x: x ...
IMPORT IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) while t > 0: t -= 1 count, st = 0, list(input()) m = {} tmpC = 0 for i in range(len(st)): if st[i] == "1": m[len(m)] = tmpC tmpC = 0 else: tmpC += 1 m[len(m)] = tmpC s = 0 for key, value in m.items(): tmp = key ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBE...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
for _ in range(int(input())): animal = input() answer = 0 cer = 0 sqwerty = 0 po = 0 for lk in range(2): po += 1 for lk in range(2): po += 1 for de in range(2): if de != 0: po += 1 for i in range(len(animal)): if animal[i] == "1": ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for e in range(t): s = input() ans = 0 a, lens = [], len(s) for i in range(lens): if s[i] == "1": a.append(i) n = len(a) for i in range(n): if i == n - 1: if a[i] != lens - 1: ans += (lens - a[i]) * (i + 1) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBE...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
def getChar(s, ch): for i in range(len(s)): if s[i] != ch: return s[i:], i return "", len(s) T = int(input()) for t in range(T): ozs = [] tot = 0 count = 0 moving = False s = input().strip() s = s[s.find("1") :] while len(s) > 0: ozs.append([0, 0]) ...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR VAR VAR RETURN STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
repe = int(input()) casos = 0 res = [] while casos < repe: cadena = input() soldados = 0 espacios = 0 tiempo = 0 tt = 0 for c in cadena: if c == "1": if espacios > 0: tiempo = soldados + soldados * espacios tt += tiempo espacios...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMB...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
def calc(st): cnt = 0 ones = 0 enc = False zeros = 0 for i in range(len(st)): if st[i] == "1": if enc: cnt += (zeros + 1) * ones enc = False ones += 1 zeros = 0 elif st[i] == "0": if ones: if ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING IF VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for _ in range(t): s = input() pre = [] n = len(s) j = 0 ss = {} for i in range(n): if s[i] == "1": pre.append(i) ss[i] = j j += 1 pre.append(n) suff = [(0) for i in range(n + 1)] tot = 0 duff = [(0) for i in range(n + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) while t: s = input() n = len(s) if s[n - 1] == "1": n -= 1 ans = 0 count = 0 i = n - 1 while i >= 0: if s[i] == "0": count += 1 else: count += 1 if s[i + 1] == "1": count -= 1 ans += coun...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR VAR V...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for i in range(t): n = input() l = list(n) one = 0 sec = 0 zero = 0 k = 0 f = 0 while l[k] == "0": k = k + 1 if k == len(l): break for j in range(k, len(l)): if l[j] == "1": if f == 1: sec = sec + one + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL ...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
test = int(input()) while test: count = 1 ans = 0 n = input() leng = len(n) while n[leng - 1] == "1": leng -= 1 if leng == 0: break for i in range(leng): if n[leng - i - 1] == "0": count += 1 else: if n[leng - i] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR NUMBER V...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
def find_1seq(S, start): i = start while i < len(S) and S[i] == "0": i += 1 j = i + 1 while j < len(S) and S[j] == "1": j += 1 return j - i, j for _ in range(int(input())): S = input() time = 0 i = 0 prev_nbr_ones = 0 while True: nbr_ones, i = find_1seq(...
FUNC_DEF ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER RETURN BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHIL...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for _ in range(t): st = input() data = [] temp = 1 for i in range(1, len(st)): if st[i] == st[i - 1]: temp += 1 else: data.append((st[i - 1], temp)) temp = 1 data.append((st[len(st) - 1], temp)) ans = 0 ones = 0 for d i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VA...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) while t > 0: a = input() zerocount = 0 onecount = 0 i = 0 sumi = 0 while i < len(a): if int(a[i]) == 1: onecount += 1 if int(a[i]) == 0: j = i while j < len(a) and int(a[j]) != 1: zerocount += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input().strip()) for a0 in range(t): n = input().strip() pos_ones = [(len(n) - (i + 1)) for i in range(len(n)) if n[i] == "1"] len_one = len(pos_ones) pos_ones.reverse() i = 0 total_cnt = 0 while i < len_one: if pos_ones[i] == i: i += 1 else: i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR ...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
import sys for _ in range(int(input())): s = str(input()) arr = [int(i) for i in s] n = len(arr) total = 0 cnt = 0 lstindx, curr = n - 1, n - 1 while arr[curr] == 1 and curr >= 0: curr -= 1 lstindx -= 1 while curr >= 0: if arr[curr] == 1: if arr[curr ...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER ...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
def soln(s): n = len(s) res = ones = i = 0 while i < n and s[i] != "1": i += 1 while i < n: while i < n and s[i] == "1": ones += 1 i += 1 zeros = 0 while i < n and s[i] == "0": zeros += 1 i += 1 if zeros == 0: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FU...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
casos = int(input()) ejecuciones = 0 respuestas = [] soldados = 0 pasos = 0 tiempoIteracion = 0 total = 0 while ejecuciones < casos: entrada = input() for soldado in entrada: if soldado == "0": pasos += 1 else: if pasos > 0: tiempoIteracion = soldados + so...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMB...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
for t in range(int(input())): s = input()[::-1].strip() last = 0 extra_stops = 0 try: for i in range(s.index("01") + 2, len(s)): if s[i] == "1": if s[i - 1] == "0": last += 1 extra_stops += last except ValueError: pass ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR ...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
T = int(input()) ans = [] for _ in range(T): S = input() N = len(S) ones = 0 count = 0 for i in range(N - 1, -1, -1): if S[i] == "1": count += N - i - 1 - ones ones += 1 t = S.split("0") group = 1 for i in range(len(t) - 1, -1, -1): if i != len(t) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL V...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for i in range(0, t): enc = 0 jump = -1 total = flag = 0 sel = 0 string = input() n = len(string) i = n - 1 while (i >= 0) & (string[i] == "1"): i -= 1 enc += 1 while i >= 0: if (string[i] == "1") & (flag == 0): jump += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF BIN_OP V...
Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible ...
t = int(input()) for _ in range(t): s = input() n = len(s) i = n - 1 ones = s.count("1") c = 0 ans = 0 while i >= 0: if s[i] == "0": c += 1 i -= 1 else: if c: ans += ones * (c + 1) c = 0 while i >...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN ...