description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def cumsum(it): total = 0 for x in it: total += x yield total t = int(input()) for i in range(0, t): n = int(input()) bricks = list(reversed(list(map(int, input().split(" "))))) if n < 4: print(sum(bricks)) total = list(cumsum(bricks)) p = total[0:3] for i in ra...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
for _ in range(int(input())): n = int(input()) a = map(int, input().split()) a = list(a) a.reverse() if n <= 3: print(sum(a)) else: f = [(0) for i in range(n)] f[0], f[1], f[2] = a[0], a[0] + a[1], a[0] + a[1] + a[2] su = f[2] for i in range(3, n): ...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
sums = {} def summ(i): total = 0 for k in range(i + 1): total = total + int(a[k]) return total def do(n): if n < 4: return summ(len(a) - 1) else: dp = { (0): int(a[0]), (1): int(a[0]) + int(a[1]), (2): int(a[0]) + int(a[1]) + int(a[2]),...
ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VA...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def bricks(a): length = len(a) bsum = [0] * length dp = [0] * length bsum[length - 1] = a[length - 1] bsum[length - 2] = a[length - 2] + bsum[length - 1] bsum[length - 3] = a[length - 3] + bsum[length - 2] dp[length - 1] = bsum[length - 1] dp[length - 2] = bsum[length - 2] dp[length ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASS...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
from itertools import accumulate def solve(): n = int(input()) a = [int(i) for i in input().strip().split()] a.reverse() cumsum = list(accumulate(a)) result = cumsum[:3] for i in range(3, n): result.append(cumsum[i] - min(result[i - 3 : i])) return result[-1] t = int(input()) for...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR NUM...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
t = int(input()) for i in range(t): n = int(input()) ar = input().split() ar = [int(e) for e in ar] for l in range(n // 2): temp = ar[n - 1 - l] ar[n - 1 - l] = ar[l] ar[l] = temp b = [] m = [] b.append(ar[0]) m.append(0) for j in range(1, n): b.append...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR V...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
from itertools import accumulate def main(): ncases = int(input()) for _ in range(ncases): length = int(input()) bricks = [int(f) for f in reversed(input().split())] assert len(bricks) == length cumsum = [0] + list(accumulate(bricks)) score = [0] for i in range(...
FUNC_DEF 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 VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def inv(x): return abs(x - 1) t = int(input()) for _ in range(t): n = int(input()) lis = list(map(int, input().split())) T = [[[0, 0], [0, 0]] for _ in range(n + 3)] for i, x in reversed(list(enumerate(lis))): for j in range(2): for d in range(1, 4): if T[i + d]...
FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR NUMBER 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 ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def best(Bs): if len(Bs) < 4: return sum(Bs) bb, s = [], 0 for i in range(3): s += Bs[i] bb.append(s) for i in range(3, len(Bs)): s += Bs[i] bb.append(s - min(bb[-3:])) return bb[-1] T = int(input()) for t in range(T): N = int(input()) Bs = [int(_) f...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def solution(nums): score = [(0) for i in range(len(nums))] pick = [(0) for i in range(len(nums))] score[-1] = nums[-1] score[-2] = nums[-2] + score[-1] score[-3] = nums[-3] + score[-2] pick[-1] = 1 pick[-2] = 2 pick[-3] = 3 for i in range(len(nums) - 4, -1, -1): if i + pick[...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR V...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
import sys T = int(sys.stdin.readline()) for case in range(T): N = int(sys.stdin.readline()) bs = [int(X) for X in sys.stdin.readline().split()] bs.reverse() scores = [(sum(bs[:i]), 0) for i in [1, 2, 3]] for i in range(3, N): score_take_1 = bs[i] + scores[i - 1][1], scores[i - 1][0] ...
IMPORT 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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
for i in range(int(input())): input() li = list(reversed([int(x) for x in input().split()])) su = [li[0]] for i in range(1, len(li)): su.append(su[i - 1] + li[i]) dp = [(0) for i in range(len(li) + 1)] dp[0] = su[0] dp[1] = su[1] dp[2] = su[2] for k in range(3, len(li)): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
t = int(input()) for times in range(t): n = int(input()) numbers = [int(num) for num in input().split()] numbers.reverse() sumnums = list(numbers) for i in range(1, n): sumnums[i] += sumnums[i - 1] memo = [-1] * (n + 1) memo[0] = numbers[0] memo[1] = numbers[1] + memo[0] memo...
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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
T = int(input().strip()) for t in range(T): n = int(input().strip()) A = list(map(int, input().strip().split(" "))) A.reverse() S = [0] for t in range(1, n + 1): S.append(S[t - 1] + A[t - 1]) F = [(0) for t in range(n)] F[0:3] = S[1:4] for t in range(3, n): temp1 = A[t] +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
t = int(input()) def run(): n = int(input()) nums = [0, 0] + list(reversed(list(map(int, input().strip().split(" "))))) state = [(0, 0)] * (n + 2) for i in range(2, n + 2): one = nums[i] + state[i - 1 - state[i - 1][1]][0] two = nums[i] + nums[i - 1] + state[i - 2 - state[i - 2][1]][0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def max_play(cards): N = len(cards) sum_cards = [0] * N s = 0 for i in range(N): s += cards[i] sum_cards[i] = s dp = [0] * N for i in [0, 1, 2]: dp[i] = sum(cards[0 : i + 1]) for i in range(3, N): dp[i] = max( cards[i] + sum_cards[i - 1] - dp[i - 1...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
class BrickPuzzle: bricks = [] best = {} numberOfBricks = 0 maxToTake = 3 def __init__(self, bricks): assert 0 <= len(bricks) <= 10**5 self.bricks = bricks self.numberOfBricks = len(bricks) self.calculate() def takeBricks(self, index, n): total = 0 ...
CLASS_DEF ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
readinput = lambda x: [int(y) for y in x.split()] def solve(array): array = array[::-1] scores = [(0) for _ in range(len(array))] total = 0 for i in range(3): total += array[i] scores[i] = total for i in range(3, len(array)): total += array[i] min_move = min(scores[...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
t = int(input()) for t in range(0, t): n = int(input()) arr = input().split() arr.reverse() sumarr = [] for i in range(0, n): arr[i] = int(arr[i]) if i >= 1: sumarr.append(sumarr[i - 1] + arr[i]) else: sumarr.append(arr[0]) dp = [] dp.append(su...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) arr.reverse() summary = [0] * n cache = [0] * n summary[0] = arr[0] for i in range(1, n): summary[i] = summary[i - 1] + arr[i] for i in range(3): cache[i] = summary[i] for i in ...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def solve(A, n): A.reverse() if n <= 3: sum = 0 for i in range(n): sum += A[i] return sum dp = list(range(n)) sum = 0 for i in range(3): sum += A[i] dp[i] = sum, 0 for i in range(3, n): first = A[i] second = int() if fir...
FUNC_DEF EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
__author__ = "deepak Singh Mehta(approach_by agutowski :))" tests = int(input()) for _ in range(tests): n = int(input()) suff = best = [0] * (n + 3) arr = list(map(int, input().split())) for i in range(n - 1, -1, -1): suff[i] = suff[i + 1] + arr[i] for i in range(n - 1, -1, -1): best...
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def sol(bricks): if len(bricks) <= 3: return sum(bricks) solutions = [[0] * len(bricks), [0] * len(bricks)] solutions[1][-1] = solutions[0][-1] = sum(bricks[-1:]) solutions[1][-2] = solutions[0][-2] = sum(bricks[-2:]) solutions[1][-3] = solutions[0][-3] = sum(bricks[-3:]) index = len(bri...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUM...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
import sys T = int(sys.stdin.readline().strip()) for t in range(T): sys.stdin.readline() A = list(map(lambda x: int(x.strip()), sys.stdin.readline().split())) A.reverse() B = [0] * len(A) C = [0] * len(A) C[0] = A[0] C[1] = A[0] + A[1] C[2] = A[0] + A[1] + A[2] B[0] = A[0] for i...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NU...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def getMax(bricks, N): if N == 0: return 0 if N <= 3: return sum(bricks) scores = [0] total = 0 for i in range(1, 4): total += bricks[-i] scores.append(total) for i in range(4, N + 1): total += bricks[-i] choice_1 = total - scores[i - 1] ch...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def solve(n, scores): total = [0] * n dp = [0] * n total[-1] = scores[-1] for i in range(n - 2, -1, -1): total[i] = total[i + 1] + scores[i] dp[-3:] = total[-3:] for i in range(n - 4, -1, -1): for j in range(1, 4): dp[i] = max(dp[i], total[i] - dp[i + j]) return d...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUM...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
numinputs = int(input()) for dummy in range(numinputs): n = int(input()) scores = [int(val) for val in input().split()] dp = [0] * n sumdp = [0] * n dp[n - 1] = scores[n - 1] sumdp[n - 1] = scores[n - 1] dp[n - 2] = scores[n - 2] + scores[n - 1] sumdp[n - 2] = scores[n - 2] + scores[n - ...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
__author__ = "Satya" def play_game(): tc = int(input()) for _ in range(tc): n = int(input()) numbers = [int(x) for x in input().split()] if n < 4: return sum(numbers) total = [0] * n total[n - 1] = numbers[n - 1] for i in range(n - 2, -1, -1): ...
ASSIGN VAR STRING FUNC_DEF 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 VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
import sys T = int(sys.stdin.readline()) for _ in range(T): N = int(sys.stdin.readline()) arr = [int(x) for x in sys.stdin.readline().split()] arr.reverse() table = [0] * N table[0] = arr[0], arr[0] table[1] = sum(arr[:2]), sum(arr[:2]) table[2] = sum(arr[:3]), sum(arr[:3]) s = sum(arr[...
IMPORT 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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VA...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
for i in range(int(input())): t = int(input()) a = [int(e) for e in input().split()] d = { (t - 3): a[t - 3] + a[t - 2] + a[t - 1], (t - 2): a[t - 2] + a[t - 1], (t - 1): a[t - 1], t: 0, } def max_score(n): if n in d: return d[n] else: ...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VA...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def play_game(block_nums, size): block_nums.reverse() max_values = [ 0, block_nums[0], block_nums[0] + block_nums[1], block_nums[0] + block_nums[1] + block_nums[2], ] best_picks = [0, 1, 2, 3] index = 3 for i in range(3, size): cur_best = -99999999999 ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMB...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def maxScore(B, n): Mx = [0] * n Mx[-1] = B[-1] Mx[-2] = sum(B[-2:]) Mx[-3] = sum(B[-3:]) BackSum = Mx[:] for i in range(n - 4, -1, -1): x1 = B[i] + BackSum[i + 1] - Mx[i + 1] x2 = B[i] + B[i + 1] + BackSum[i + 2] - Mx[i + 2] x3 = B[i] + B[i + 1] + B[i + 2] + BackSum[i + ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_O...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def iterative(): for T in range(int(input())): n = int(input()) A = [int(x) for x in input().split()] A.reverse() Sum = [A[0]] for i in range(1, n): Sum.append(Sum[i - 1] + A[i]) dp = [A[0], A[0] + A[1], A[0] + A[1] + A[2]] for i in range(3, n): ...
FUNC_DEF 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 FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST VAR NUMBER BIN...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
T = int(input()) for t in range(T): n = int(input()) a = list(reversed(list(map(int, input().split())))) sums = [0] * n sums[0] = a[0] for i in range(1, n): sums[i] = sums[i - 1] + a[i] dp = [0] * n dp[0] = a[0] dp[1] = a[0] + a[1] dp[2] = a[0] + a[1] + a[2] for i in rang...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) l = list(reversed(l)) q = [(0) for i in l] m = [(0) for i in l] for i in range(len(l)): if i <= 2: if i == 0: q[i] = l[i] m[i] = q[i] else: ...
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 FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER A...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def f(A): A = A[::-1] s = [0] * len(A) s[0] = A[0] for i in range(1, len(A)): s[i] = s[i - 1] + A[i] dp = [0] * len(A) dp[0] = A[0] for i in range(1, min(len(A), 3)): dp[i] = dp[i - 1] + A[i] for i in range(3, len(A)): dp[i] = ( max( s[...
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CA...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def maxScore(n, seq): prefixSum = [seq[0], seq[0] + seq[1], seq[0] + seq[1] + seq[2]] table = [seq[0], seq[0] + seq[1], seq[0] + seq[1] + seq[2]] if n < 4: return table[-1] for i in range(3, n): prefixSum.append(prefixSum[-1] + seq[i]) best = 0 for x in (0, 1, 2): ...
FUNC_DEF ASSIGN VAR LIST VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
test_count = int(input()) for test_id in range(0, test_count): dummy = input() values = list(reversed(list(map(int, input().split())))) total = [0] * len(values) target = [-1] * len(values) for i in range(0, len(values)): best_index = -1 max_value = -1 for j in range(1, 4): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUN...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def calculate(bricks): bricks.reverse() numbricks = len(bricks) sumx = [bricks[0]] + (numbricks - 1) * [-1] for x in range(1, numbricks): sumx[x] = bricks[x] + sumx[x - 1] dp = [sumx[0], sumx[1], sumx[2]] + (numbricks - 3) * [-1] for x in range(3, numbricks): dp[x] = max( ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER BIN_OP BIN_OP VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER LIST NUMBER FOR VAR FUNC_C...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
cache = [(-1) for x in range(0, 10001)] count = 0 ar = [] def maxSum(x, i): sum1 = 0 if x == 0: sum1 = ar[i] elif x == 1: sum1 = ar[i] + ar[i + 1] elif x == 2: sum1 = ar[i] + ar[i + 1] + ar[i + 2] elif cache[i] < 0: totSum = 0 for j in range(i, len(ar)): ...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIG...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def score(V): if len(V) <= 3: return sum(V) F = [0] * N F[0] = V[0] for i in range(1, 3): F[i] = F[i - 1] + V[i] for j in range(3, len(V)): m = 0 c = [0] * 3 for k in range(3): m += V[j - k] hi = j - k - 1 if j - k - 1 >= 0 else 0 ...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR V...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
cases = int(input()) for _ in range(cases): size = int(input()) B = [int(x) for x in input().split()] def score(k, memo={}): if k in memo: return memo[k] res = 0 if size - k <= 3: res = sum(B[k:]) else: res = max( B[k] + mi...
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 VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF DICT IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FUN...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
import sys def read_numbers(line=None): if line is None: line = sys.stdin.readline() return [int(x) for x in line.split()] def get(l, i, default=0): try: return l[i] except IndexError: return default def calculate_best_result(stack, best_results, best_moves, i): took_on...
IMPORT FUNC_DEF NONE IF VAR NONE ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF NUMBER RETURN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER LIST...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def main(): t = int(input()) while t: n = int(input()) a = input().split() value = [0] * n for i in range(0, n): value[i] = int(a[n - 1 - i]) oppo = [0] * n plyr = [0] * n plyr[0] = value[0] plyr[1] = value[0] + value[1] plyr[2]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NU...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
T = int(input()) for i in range(T): N = int(input()) bricks = list(map(int, input().split())) bricks.reverse() sums = [bricks[0]] for num in bricks[1:]: sums.append(sums[-1] + num) if N <= 3: print(sums[-1]) else: dp = [sums[0], sums[1], sums[2]] dp = [bricks[...
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 ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
T = int(input()) S = [] def buildArrays(A, B, N): A[0] = S[N - 1] A[1] = S[N - 1] + S[N - 2] A[2] = S[N - 1] + S[N - 2] + S[N - 3] B[0] = 0 B[1] = 0 B[2] = 0 for i in range(3, N): j = 1 A[i] = S[N - 1 - i] + B[i - 1] t = S[N - 1 - i] + S[N - 1 - i + 1] + B[i - 2] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
for _ in range(int(input())): input() arr = list(reversed([int(x) for x in input().split()])) opt = [0, arr[0]] running_total = arr[0] if len(arr) > 1: opt.append(arr[1] + arr[0]) running_total += arr[1] if len(arr) > 2: opt.append(arr[2] + arr[1] + arr[0]) runnin...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VA...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def max_score(bricks): scores = [(0) for _ in range(len(bricks))] scores[0] = bricks[0] scores[1] = scores[0] + bricks[1] scores[2] = scores[1] + bricks[2] psum = [(0) for _ in range(len(bricks))] psum[0] = bricks[0] for i in range(1, len(psum)): psum[i] = psum[i - 1] + bricks[i] ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSI...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def brick_game(B): B.reverse() Sum_B = [B[0]] for x in B[1:]: Sum_B.append(Sum_B[-1] + x) dp = [(0) for _ in range(len(B))] dp[0], dp[1], dp[2] = Sum_B[0], Sum_B[1], Sum_B[2] for i in range(3, len(B)): dp[i] = Sum_B[i] - dp[i - 1] dp[i] = max(dp[i], Sum_B[i] - dp[i - 2]) ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR V...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
import sys sys.setrecursionlimit(1000000) T = int(input()) def max_score1(stack, acc, ptr, dp): if dp[ptr] == -1: if ptr < 3: dp[ptr] = acc[ptr] else: opt1 = max_score(stack, acc, ptr - 1, dp) opt2 = max_score(stack, acc, ptr - 2, dp) opt3 = max_sco...
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
testCases = int(input()) for testCase in range(testCases): n = int(input()) stack = list(map(int, input().split())) s = [(0) for i in range(n + 1)] currSum = 0 for i in range(1, n + 1): currSum += stack[-i] if i <= 3: s[i] = currSum else: c1 = currSum ...
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSI...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def game_bricks(bricks, n): states = [[0] * n, [0] * n] for i in range(n - 1, -1, -1): states[0][i] = max( bricks[i] + (states[1][i + 1] if i < n - 1 else 0), bricks[i] + (bricks[i + 1] if i < n - 1 else 0) + (states[1][i + 2] if i < n - 2 else 0), ...
FUNC_DEF ASSIGN VAR LIST BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VA...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def get_memo(n, memo): if n >= len(memo): return 0 else: return memo[n] def solver(N, bStack): memo = [0] * N for n in range(N - 1, -1, -1): if n == N - 1: memo[n] = bStack[n] elif n == N - 2: memo[n] = sum(bStack[n:]) elif n == N - 3: ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
import sys def max_profit(arr): max_ahead = list(arr) max_move = list(arr) L = len(arr) max_move[L - 1] = 1 max_move[L - 2] = 2 max_move[L - 3] = 3 max_ahead[L - 2] = max_ahead[L - 2] + max_ahead[L - 1] max_ahead[L - 3] = max_ahead[L - 3] + max_ahead[L - 2] max_ahead.insert(L, 0) ...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
test = int(input()) def getOptimalMap(lst, index, dic, sum_array, length): if dic[index] is not None: return dic[index] if length - index <= 3: dic[index] = sum_array[index] else: m = None for i in range(1, 4): x = getOptimalMap(lst, index + i, dic, sum_array, l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR NONE RETURN VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR AS...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
from itertools import accumulate for _ in range(int(input())): n = int(input()) br = [int(x) for x in input().split()] br.reverse() dp = [0] * n sums = list(accumulate(br)) dp[0] = sums[0] dp[1] = sums[1] dp[2] = sums[2] for i in range(3, n): dp[i] = max(sums[i] - dp[i - 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VA...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
def solve(stack): max_score_at = {len(stack): 0} for i, num in reversed(list(enumerate(stack))): possible_scores = [] for n_taken in (1, 2, 3): if i + n_taken - 1 >= len(stack): break score = sum(stack[i : i + n_taken]) - max_score_at[i + n_taken] ...
FUNC_DEF ASSIGN VAR DICT FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
t = eval(input()) def max(a, b, c): result = a if result < b: result = b if result < c: result = c return result while t > 0: t -= 1 n = eval(input()) arr = list(map(int, input().split())) sumRight = [0] * (n + 1) sumRight[n] = 0 for i in reversed(range(n)): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR WHILE VAR NUMBER 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 BIN_OP VAR NUMBER ASSIGN VAR V...
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil...
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) arr = arr[::-1] p1 = [(0) for x in range(n)] p2 = [(0) for x in range(n)] p1[0], p1[1], p1[2], p1[3], p1[4] = ( arr[0], arr[1] + arr[0], arr[0] + arr[1] + arr[2], arr[3] + a...
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 ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUM...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys input = sys.stdin.readline n = int(input()) c = list(map(int, input().split())) t = [[] for _ in range(n)] ab = [] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 ab.append([a, b]) t[a].append(b) t[b].append(a) root = [0] * n root[0] = -1 rank = [0] * n Q = [0] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys def main(): import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) adj = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b = map(int, input().split()) adj[a].append(b) adj[b].append(a) def op(a, b): retur...
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys input = sys.stdin.readline getint = lambda: int(input()) getints = lambda: [int(a) for a in input().split()] n = getint() colors = [(i * 2 - 1) for i in getints()] tree = [[] for i in range(n)] for i in range(n - 1): a, b = getints() tree[a - 1].append(b - 1) tree[b - 1].append(a - 1) parent = [...
IMPORT ASSIGN VAR VAR 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 ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys input = sys.stdin.readline INF = 10**18 N = int(input()) Color = list(map(int, input().split())) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b = map(int, input().split()) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) Score = [{} for _ in range(N)] Max = [-INF] * N for i, c i...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER 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 LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys input = sys.stdin.readline sys.setrecursionlimit(10**5 * 2) n = int(input()) c = [int(item) for item in input().split()] edge = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 edge[a].append(b) edge[b].append(a) memo = [None] * n def dfs(p, ...
IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER 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 FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VA...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys class Tree: def __init__(self, n, decrement=1): self.n = n self.edges = [[] for _ in range(n)] self.root = None self.size = [1] * n self.decrement = decrement def add_edge(self, u, v): u, v = u - self.decrement, v - self.decrement self.edges...
IMPORT CLASS_DEF FUNC_DEF NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NONE ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
class WhiteSubtree: def __init__(self, vertex_is_white, edges, root=1): self.vertex_is_white = vertex_is_white self.root = root self.adj = self.__build_adj_list__(edges) self.subtree_best_polarity = self.__compute_subtree_best_polarity__() self.score_at_nodes = self.__comput...
CLASS_DEF FUNC_DEF NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NONE FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL ...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def LI(): return list(map(int, sys...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ n = int(input()) a = list(map(int, input().split())) G = [[] for i in range(n)] for i in range(n - 1): x, y = map(int, input().split()) x, y = x - 1, y - 1 G[x].append(y) G[y].append(x) cost = [(2 * i - 1) for i in a] def bfs...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VA...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
def main(): n = int(input()) a = list(map(int, input().split())) g = [list() for _ in range(n)] for _ in range(n - 1): u, v = map(int, input().split()) g[u - 1].append(v - 1) g[v - 1].append(u - 1) st = [(x * 2 - 1) for x in a] + [0] p = [-1] * n q = [0] while q: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR F...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys input = sys.stdin.readline n = int(input()) A = list(map(int, input().split())) A = [(-1 if a == 0 else 1) for a in A] g = [[] for i in range(n)] for i in range(n - 1): u, v = map(int, input().split()) u, v = u - 1, v - 1 g[u].append(v) g[v].append(u) s = [] s.append(0) parent = [-1] * n ord...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VA...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ def go(): n = int(input()) a = list(map(int, input().split())) e = {i: set() for i in range(n)} for _ in range(n - 1): u, v = map(int, input().split()) u, v = u - 1, v - 1 e[u].add(v) ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF 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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL ...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
import sys input = sys.stdin.readline n = int(input()) A = [0] + list(map(int, input().split())) for i in range(n + 1): if A[i] == 0: A[i] = -1 E = [[] for i in range(n + 1)] for i in range(n - 1): x, y = map(int, input().split()) E[x].append(y) E[y].append(x) DP_C = [0] * (n + 1) DP_G = [0] * ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER A...
You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black). You have to solve the following problem for each vertex $v$: what is the maximum d...
from sys import setrecursionlimit, stdin n = int(stdin.readline()) ay = [int(x) for x in stdin.readline().split()] graph = [set() for x in range(n)] for e in range(n - 1): a, b = [(int(x) - 1) for x in stdin.readline().split()] graph[a].add(b) graph[b].add(a) dists = {} child = {} bruh = sum(ay) path = [(0...
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 VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN V...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
elem = int(input()) ar = [] for i in input().split(" "): ar.append(int(i)) res = [0] cont = [0] gym = [0] for i in ar: if i == 0: res.append(min(res[-1], cont[-1], gym[-1]) + 1) cont.append(cont[-1] + 1) gym.append(gym[-1] + 1) elif i == 1: temp = min(res[-1], cont[-1], gym[-...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
def min_rest_days(days): cache = {(-1): [0, 0, 0]} for i in range(len(days)): prev_cache = cache[i - 1] if days[i] == 0: cache[i] = [ float("inf"), float("inf"), min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1, ] ...
FUNC_DEF ASSIGN VAR DICT NUMBER LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
t = int(input()) s = list(map(int, input().split())) dp1 = [(0) for i in range(t)] dp2 = [(0) for i in range(t)] dp1[0] = 0 if s[0] & 1 else 1 dp2[0] = 0 if s[0] & 2 else 1 for i in range(1, t): if s[i] == 3: dp1[i], dp2[i] = dp2[i - 1], dp1[i - 1] elif s[i] == 2: dp1[i], dp2[i] = min(dp1[i - 1]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VA...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
import sys input = sys.stdin.readline n = int(input()) l = list(map(int, input().split())) dp = [[float("inf") for i in range(3)] for i in range(n)] dp[0][2] = 1 if l[0] == 3: dp[0][0] = 0 dp[0][1] = 0 elif l[0] == 2: dp[0][0] = 0 elif l[0] == 1: dp[0][1] = 0 for i in range(1, n): cur = l[i] dp...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUM...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) data = list(map(int, input().split())) ans = 0 prev = 0 i = 0 while i < n: if data[i] is 0: ans = ans + 1 prev = 0 elif data[i] is 1: if prev is 1: ans += 1 prev = 0 else: prev = 1 elif data[i] is 2: if prev is 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) A = list(map(int, input().split())) f1 = 0 f2 = 0 t = 0 a = 0 for i in range(n): if A[i] == 0: a += 1 f1 = 0 f2 = 0 elif A[i] == 1: if f1 == 1: a += 1 f1 = 0 else: f1 = 1 f2 = 0 elif A[i] == 2: 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN V...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
def dp(prev, ind): nonlocal dar, n, con, gym if ind >= n: return 0 if (prev, ind) not in dar: m = dp("free", ind + 1) + 1 if prev != "con" and con[ind]: m = min(m, dp("con", ind + 1)) if prev != "gym" and gym[ind]: m = min(m, dp("gym", ind + 1)) ...
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER IF VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR RETU...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
_ = input() days = map(int, input().split()) off = 0 last = 0 for d in days: if d == 0: off += 1 last = 0 elif last == 0 or last == 3: last = d elif d in {3, 3 - last}: last = 3 - last else: off += 1 last = 0 print(off)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VA...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) dias = list(map(int, input().split())) OPT = [([0] * 3) for i in range(2)] for i in range(n): if dias[i] == 0: optimo_anterior = 1 + OPT[0][0] OPT[1][0] = optimo_anterior OPT[1][1] = optimo_anterior OPT[1][2] = optimo_anterior elif dias[i] == 1: optimo_an...
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 NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR ASSIGN ...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) l = list(map(int, input().split())) cur = ans = 0 for a in l: if a == 0: ans += 1 cur = 0 elif a == 1: if cur in (0, 1): cur = 2 else: ans += 1 cur = 0 elif a == 2: if cur in (0, 2): cur = 1 else...
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 FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VA...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
def __starting_point(): MAX = 100 n = int(input()) num = list() for i in range(n + 1): num.append([0, 0, 0]) line = str(input()).split() for i in range(n): if line[i] == "0": num[i + 1][0] = 1 + min(num[i]) num[i + 1][1] = MAX num[i + 1][2] = M...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER F...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) dp = [[(0) for i in range(3)] for j in range(n + 1)] a = list(map(int, input().split())) for i in range(1, n + 1): if a[i - 1] == 1 or a[i - 1] == 3: dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1 if a[i - 1] == 2 or a[i - 1] == 3: dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_O...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
import sys input = lambda: sys.stdin.readline() int_arr = lambda: list(map(int, input().split())) str_arr = lambda: list(map(str, input().split())) get_str = lambda: map(str, input().split()) get_int = lambda: map(int, input().split()) get_flo = lambda: map(float, input().split()) mod = 1000000007 def solve(n, arr):...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) a = list(map(int, input().split())) d = [([10**6] * 3) for i in range(n)] d[0][0] = 1 if a[0] & 1: d[0][1] = 0 if a[0] & 2: d[0][2] = 0 for i in range(1, n): d[i][0] = min(d[i - 1]) + 1 if a[i] & 1: d[i][1] = min(d[i - 1][0], d[i - 1][2]) if a[i] & 2: d[i][2] = min(d...
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 BIN_OP NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUM...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) a = list(map(int, input().split())) cnt = 0 last = a[0] if last == 3: last = 5 if a[0] != 0: cnt += 1 for i in range(1, n): if a[i] != last and a[i] != 0: if a[i] == 3: if last == 0 or last == 5: last = 5 cnt += 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSI...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) a = list(map(int, input().split(" "))) l = [3, 2, 1, 3] rest = 0 last = 0 for i in range(n): if a[i] == 0: rest += 1 last = 0 elif a[i] == 3: last = l[last] elif last == a[i]: rest += 1 last = 0 else: last = a[i] print(rest)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VA...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
def get_ints(string): return list(map(int, string.split())) def get_input(): n = int(input()) xs = get_ints(input()) return n, xs def foo(xs, res, last): if len(xs) is []: return res for i, x in enumerate(xs): if x == 0: res += 1 last = 0 elif ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR LIST RETURN VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER A...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
input() l = list(map(int, input().split())) r = 0 prev = 3 for i in l: if i == prev and prev != 3: i = 0 elif i == 3 and prev != 3: i -= prev if i == 0: r = r + 1 prev = i print(r)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) a = [0] + list(map(int, input().split())) vix = 0 for i in range(1, n + 1): if a[i] == 0: vix += 1 elif a[i] == 3: a[i] = 3 - a[i - 1] elif a[i] == a[i - 1]: vix += 1 a[i] = 0 print(vix)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
user = int(input()) n = list(input().split(" ")) l = len(n) - 1 if int(n[0]) == 3 and int(n[l]) != 3: n.reverse() r = 0 a = 0 c = 0 res = [] for i in n: if int(i) == 0: r = r + 1 a = 0 c = c + 1 if int(i) == 1: if a == 0 or a != 2: a = 2 c = c + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR ...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) k = list(map(int, input().split(" "))) ans = 0 last = "n" for i in k: if i == 0: now = "n" elif i == 1 and last != "p": now = "p" elif i == 1: now = "n" elif i == 2 and last != "s": now = "s" elif i == 2: now = "n" elif last == "s": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR STRING ASSIGN VAR STRING IF VAR NU...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) numbers = list(map(int, input().split(" "))) memo = [[(0) for _ in range(4)] for _ in range(n)] first = numbers[0] if first != 0: if first == 3: memo[0][1] = 1 memo[0][2] = 1 else: memo[0][first] = 1 for i in range(1, n): j = numbers[i] memo[i][0] = max(memo[i - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
R = lambda: map(int, input().split()) n = int(input()) dp = [[0, 0, 0] for i in range(n + 1)] for i, x in enumerate(R()): dp[i][0] = min(dp[i - 1]) + 1 if x == 3: dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) elif x == 2: dp[i][1] = n + 1 ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CA...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) a = list(map(int, input().split())) c = ct = gm = 0 for i in range(n): if a[i] == 0: ct = 0 gm = 0 c += 1 elif a[i] == 1 and ct == 0: ct = 1 gm = 0 elif a[i] == 2 and gm == 0: gm = 1 ct = 0 elif a[i] == 3: if ct == 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 VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASS...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) a = list(map(int, input().split())) mem = {} def solve(i, previous): if i == n: return 0 if a[i] == 0 or a[i] == previous: return solve(i + 1, 0) + 1 elif a[i] == 3: if previous == 0: return solve(i + 1, 0) return solve(i + 1, 2 if previous == 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 DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUM...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) l = list(map(int, input().split())) output = 1 if l[0] == 0 else 0 u = False for i in range(1, n): if l[i] == 0: output += 1 elif l[i] == l[i - 1] and l[i] != 3: output += 1 l[i] = 0 elif l[i] == 3: if l[i - 1] == 1: l[i] = 2 elif l[i - 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 VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
3 n = int(input()) a = list(map(int, input().split())) dp = [([-1791791791] * 4) for i in range(n)] dp[0][0] = 0 if a[0] & 1: dp[0][1] = 1 if a[0] & 2: dp[0][2] = 1 for i in range(1, n): dp[i][0] = max(dp[i - 1]) for j in range(1, 3): if a[i] & j: dp[i][j] = max(dp[i - 1][:j] + dp[i ...
EXPR 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBE...