description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
s, n, q, a = input(), int(input()), {}, "" for i in s: q[i] = [q[i][0] + 1, 1] if i in q else [1, 1] if len(q) > n: print(-1) else: for i in range(n - len(q)): o = 0 for j in q: m = (q[j][0] + q[j][1] - 1) // q[j][1] if m > o: o, w = m, j q[w][...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR DICT STRING FOR VAR VAR ASSIGN VAR VAR VAR VAR LIST BIN_OP VAR VAR NUMBER NUMBER NUMBER LIST NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_O...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
def middle(arr, n, result): f = False result[1] = arr[0] for i in range(1, n): result[i + 1] = result[i] + arr[i] if arr[i - 1] % 2 != 0: result[i + 1] -= 1 if f == True: if arr[i - 2] % 2 != 0: result[i + 1] += 1 else: ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
def get_sums(N, numbers): skip_flag = False final_sum = [] cycle_sum = 0 for i in range(N - 1): if skip_flag: skip_flag = False continue if numbers[i + 1] == 1 and i < N - 2: if numbers[i] % 2: cycle_sum += numbers[i] fi...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
m = 1000000007 T = int(input()) while T: N = int(input()) A = list(map(int, input().split())) onePos = -1 if A[0] == 1: Q = int(input()) while Q: R = int(input()) if R % N == 0: print(int(R / N) % m) elif R % N == 1 and R > N: ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR VAR NU...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
from sys import stdin input = stdin.readline def func1(l, qq, modulus): if l[0] % 2 == 0: for rr in qq: print(((rr - 1) * (l[0] - 1) + l[0]) % modulus) else: for rr in qq: print(rr * l[0] % modulus) return def func2(nn, l, qq, modulus): mm = [None] * nn r...
ASSIGN VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
import sys input = sys.stdin.readline MOD = 10**9 + 7 for _ in range(int(input())): n = int(input()) data = list(map(int, input().split())) n = len(data) ans1 = ans2 = ans3 = ans4 = case = 0 lastone = -1 for i in range(n): if data[i] == 1: lastone = i case = data...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CA...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) u = 10**9 + 7 q = int(input()) if l[0] == 1: for i in range(q): m = int(input()) s = 0 if m % n <= 1: s = m // n % u if 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 BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CA...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
m = 10**9 + 7 t = int(input()) for testcase in range(t): n = int(input()) a = list(map(int, input().split())) pos1 = -1 if n == 1: q = int(input()) for qq in range(q): r = int(input()) if a[0] % 2 == 1: print(r * a[0] % m) else: ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER 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 NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
def case1(): pass def case2(): pass def case3(): pass for _ in range(int(input())): mod = 1000000007 c = -1 n = int(input()) a = list(map(int, input().split())) for i in range(len(a)): if a[i] == 1: if i == 0: c = 0 elif i != n - 1: ...
FUNC_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
def SieveOfEratosthenes(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 l = [] for p in range(2, n + 1): if prime[p]: l += [p] return l...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR LIST VAR RETURN VAR FUNC_D...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
for test in range(int(input())): num = int(input()) arr = [int(x) for x in input().split()] cupid = int(input()) run = list() for i in range(cupid): run.append(int(input())) answer = [] key = False for i in range(num): if i == 0 and arr[i] == 1: answer.append(...
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
def loop6(): i = 3 if i == 3: g = 1 def loop5(): n = int(input()) ar = list(map(int, input().split())) q = int(input()) sol = [0] * n part = ar.copy() p = 10**9 + 7 cnt = 0 loop6() ans = 0 if ar[0] == 1: for i in range(n): sol[i] = 1 ...
FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER 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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER AS...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
t = int(input()) n, a, sum = 0, [], [] def geteven(x): if x & 1: return x - 1 else: return x def getodd(x): if x & 1: return x else: return x - 1 def start1(): if n == 1: return r if r <= n: return 1 if (r - 1) % n == 0: return (r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER LIST LIST FUNC_DEF IF BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF BIN_OP VAR NUMBER RETURN VAR RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR RETURN NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP B...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
mod = 10**9 + 7 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) a.insert(0, 0) last_round = [0] * (n + 1) q = int(input()) isOneInBeetween = False for i in range(1, n + 1): if a[i] == 1: isOneInBeetween = True break if a[...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VA...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
try: t = int(input()) for _ in range(t): queries = [] n = int(input()) arr = list(map(int, input().split())) q = int(input()) for a in range(q): r = int(input()) queries.append(r) value = 0 test = [0] * n err = 10**9 + 7 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
te = int(input()) for tt in range(te): n = int(input()) a = list(map(int, input().split())) aa = [0] * n z = 0 s = 0 t = 0 ss = [0] * n if a[0] == 1: z = 1 ss[0] = 1 s1 = 1 else: p = -1 for i in range(n): if a[i] == 1: ...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER NUMBER ASSIGN...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
try: for t in range(int(input())): n = int(input()) arr = [int(x) for x in input().split()][:n] temp = [] s = 0 if 1 in arr: if arr[0] != 1: for i in range(n): if arr[-1] == 1: s = s + arr[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 VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF NUMBER VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
mod = 1000000007 t = int(input()) for k in range(0, t): n = int(input()) a = [int(i) for i in input().split(" ")] if n == 1: q = int(input()) for h in range(0, q): r = int(input()) if a[0] % 2 == 1: print(a[0] % mod * (r % mod) % mod) else:...
ASSIGN VAR NUMBER 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 VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) a = [0] + a dp = [0] * 100005 s = 0 if a[1] != 1: for i in range(1, n + 1): if a[i] & 1: dp[i] = (s + a[i] - 1) % 1000000007 else: dp[i] = (s +...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
import sys def boolean(n): return [0] * n def update(l): for i in range(len(l) - 1): if l[i] != 1 and l[i] & 1: l[i] -= 1 return l def update2(l): d = boolean(n) d[0] = l[0] for i in range(1, len(l)): d[i] += l[i] + d[i - 1] return d pakka = 10**9 + 7 modu...
IMPORT FUNC_DEF RETURN BIN_OP LIST NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
import sys MOD = pow(10, 9) + 7 def debug(*args): print(*args, file=sys.stderr) def solve(A): N = len(A) solns = [(0) for _ in range(N)] my_turn = True my_score = 0 foe_score = 0 if A[0] == 1: solns[0] = 1 for i in range(N): even = A[i] odd = even - 1 ...
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR A...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
t = int(input()) for i in range(0, t): n = int(input()) a = [] b = [] sum = 0 res = 0 a = list(map(int, input().strip().split()))[:n] for k in range(0, n): if k == 0 and a[k] == 1: res = 1 break elif k == n - 1: if a[k] % 2 == 0: ...
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 LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR NUMBE...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
modu = pow(10, 9) + 7 for i in range(int(input())): n = int(input()) arr = [int(x) for x in input().split()] chef = [0] * n if arr[0] == 1: chef[0] = 1 else: for j in range(n): if j == n - 1: chef[j] = arr[j] - 1 + arr[j] % 2 elif arr[j] == 1: ...
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER 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 BIN_OP LIST NUMBER VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP V...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
t = int(input()) for a in range(t): n = int(input()) A = list(map(int, input().split())) one = -1 for i in range(len(A)): if A[i] == 1: one = i break once = 0 if one == -1 or one == n - 1: tmp = [] for i in range(len(A) - 1): if A[i] % ...
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSI...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
t = input() a = int(t) for __ in range(a): p = 10**9 + 7 cnt = 0 ans = 0 m = input() n = int(m) arrp = [] arr = list(map(int, input().split())) for i in arr: arrp.append(i) sol = [] for i in range(n): sol.append(0) if arr[0] == 1: for i in range(n): ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
def solve(arr, n, q): mod = 10**9 + 7 result = 0 if arr[0] == 1: for r in q: rem = r % n quo = r // n if r <= n: result = 1 else: result = quo if rem != 0 and rem != 1: result += 1 ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
def nearest_lower_even_number(number): return number >> 1 << 1 def nearest_lower_odd_number(number): return (number - (number >> 1) << 1) - 1 def payout_if_one_is_last_or_absent(sequence): payout = [nearest_lower_even_number(sequence[0])] for s in sequence[1:-1]: payout.append(payout[-1] + n...
FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
try: for ii in range(int(input())): n = int(input()) a = list(map(int, input().split())) if a[0] == 1: q = int(input()) for jj in range(q): r = int(input()) if r != 1: d = r // n if d * n + 1 == r...
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 IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) q = int(input()) l1 = [[0, 0]] for j in range(n): if j < n - 1: if l[j + 1] != 1 or j == n - 2: l1.append([l1[len(l1) - 1][0] + (l[j] - l[j] % 2), l[j] % 2]) 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 ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
def inp(): return int(input()) def inl(): return [int(i) for i in input().split()] for _ in range(inp()): n = inp() a = inl() m = pow(10, 9) + 7 flg = False t = -1 for i in range(n): if a[i] == 1 and i == 0: flg = True break if a[i] == 1: ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NU...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
modulo = 1000000007 for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) flag = -1 index = -1 if 1 in arr: index = arr.index(1) if index == -1 or index == n - 1: ans = 0 temp_arr = [] for i in range(n - 1): if arr[i] % 2...
ASSIGN VAR NUMBER 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 NUMBER ASSIGN VAR NUMBER IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
for Z in range(int(input())): N, lst = int(input()), list(map(int, input().split(" "))) dp, mod, temp = [0] * N, int(1000000000.0 + 7), [0] * N if N == 1: dp[0] = lst[0] - int(lst[0] % 2 == 0) temp[0] = temp[0] + int(lst[0] % 2 == 0) elif lst[0] == 1: dp = [1] * N elif 1 not ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER BIN_OP LIST NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
o = 1000000007 def func2(a, n): sm = 0 s = [0] * (n + 1) for i in range(n - 1): if i == ind - 1: if a[i] % 2 == 0: sm = sm + a[i] - 1 s[i] = sm else: sm += a[i] s[i] = sm elif a[i] % 2 == 0: ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
mod = 10**9 + 7 def Retain(A): ln = len(A) re = 0 if A[0] == 1: re = 1 elif A[-1] == 1: for it in A[:-1]: re = re + it if it % 2: re -= 1 re %= mod re += 1 else: for i, it in enumerate(A[:-1]): re = re ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
mod = 1000000007 t = int(input()) for T in range(t): size = int(input()) templ1 = list(map(int, input().split())) qsize = int(input()) if 1 not in templ1: res = [] tes = 0 for j in range(size - 1): if templ1[j] % 2 == 1: tes = (tes + (templ1[j] - 1)) %...
ASSIGN 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 FUNC_CALL VAR FUNC_CALL VAR IF NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF B...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Chefu are at a magical candy store playing a game with the following rules: There are two candy counters; each of them stores an infinite number of candies. At any time, only one of the counters is open and...
mod = 1000000007 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) q = int(input()) one = -1 pref = [0] * n for i in range(n): if a[i] == 1: one = i if i > 0: pref[i] = pref[i - 1] if i < n - 1: pref[i] ...
ASSIGN VAR NUMBER 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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR ...
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left an...
class Solution(object): def isValidBST(self, root): res = [] return self.inorder(root, res) def inorder(self, root, res): if not root: return True if self.inorder(root.left, res) == False: return False if len(res) != 0: last = res.pop...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER RETURN...
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left an...
class Solution: def isValidBST(self, root): if not root: return True return self.dfs(root)[2] def dfs(self, node): if node is None: return [None, None, True] L = self.dfs(node.left) R = self.dfs(node.right) if ( not L[2] ...
CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NONE RETURN LIST NONE NONE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NONE VAR NUMBER VAR VAR NUMBER NONE VAR NUMBER VAR RETURN LIST NONE NONE NUMBER IF VAR NUMBER NONE ASSIG...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
for i in range(int(input())): n, k = [int(x) for x in input().split()] a = [int(y) for y in input().split()] d = [int(u) for u in input().split()] b = [int(l) for l in input().split()] a1 = [0] * 1000000 c = 0 for i in range(len(a)): a1[a[i]] += d[i] c += d[i] sum = 0 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER A...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) d = list(map(int, input().split())) b = list(map(int, input().split())) arr = [] crd = 0 for i in range(len(a)): arr += [[a[i], d[i]]] crd += d[i] arr.sort(key=lambda x: x[0...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR L...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
for i in range(int(input())): n, k = [int(i) for i in input().split()] arr = [[int(i)] for i in input().split()] l = input().split() value = 0 for i in range(n): arr[i].append(int(l[i])) value += int(l[i]) arr.sort() ans = [value] move = list(map(int, 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 LIST FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR V...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
def length(t1, t2): a, b = t1 c, d = t2 return max(0, min(d, b) - max(a, c)) for _ in range(int(input())): N, K = map(int, input().split()) A = list(map(int, input().split())) D = list(map(int, input().split())) C = sum(D) B = list(map(int, input().split())) evs, ods = 0, 0 B =...
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
import sys def main(N, K): A = sys.stdin.readline().split() D = sys.stdin.readline().split() AD = [ [(int(A[y]) if x == 0 else int(D[y])) for x in range(2)] for y in range(len(A)) ] B = sys.stdin.readline().split() B = [int(x) for x in B] AD = sorted(AD, key=lambda l: l[0]) A =...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
T = int(input()) for i in range(0, T): N, K = map(int, input().split()) A = [int(x) for x in input().split()] D = [int(x) for x in input().split()] B = [int(x) for x in input().split()] L = sorted(zip(A, D)) L = L[::-1] for j in range(0, len(L)): L[j] = list(L[j]) if K % 2 != 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
for _ in range(int(input())): [n, k] = [int(i) for i in input().split()] a = [int(i) for i in input().split()] d = [int(i) for i in input().split()] b = [int(i) for i in input().split()] p = {} for i in range(n): try: p[a[i]] += d[i] except: p[a[i]] = d[i]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
t = int(input().strip()) while t > 0: n, k = [int(x) for x in input().strip().split(" ")] a = [int(x) for x in input().strip().split(" ")] d = [int(x) for x in input().strip().split(" ")] b = [int(x) for x in input().strip().split(" ")] p = list(map(list, zip(a, d))) tot = sum(d) p.sort(key=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
t = int(input()) a = [] b = [] for i in range(t): n = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] total = 0 for j in range(n[0]): total += b[j] c.append((a[j], b[j])) c.sort() k = list(map(int, input().spl...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
T = int(input()) for _ in range(T): N, K = map(int, input().split()) (*A,) = map(int, input().split()) (*D,) = map(int, input().split()) (*B,) = map(int, input().split()) P = sorted(zip(A, D)) A = [a for a, d in P] D = [d for a, d in P] left = 0 right = sum(D) - 1 for i in range(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR ...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
outputs = [] T = int(input()) for i in range(0, T): n = input().split() a = input().split() d = input().split() b = input().split() a = list(map(int, a)) d = list(map(int, d)) N, K = int(n[0]), int(n[1]) b = list(map(int, b)) ncards = sum(d) list1 = [] z = 0 z2 = 0 fo...
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VA...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
t = int(input()) while t: t -= 1 n, k = list(map(int, input().split())) a = list(map(int, input().split())) d = list(map(int, input().split())) c = [] for i in range(n): c.append([a[i], d[i]]) c = sorted(c) a = [] d = [] for i in range(n): a.append(c[i][0]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
T = int(input()) for i in range(T): N, K = map(int, input().split()) Alist = list(map(int, input().split())) Dlist = list(map(int, input().split())) Blist = list(map(int, input().split())) Alist, Dlist = (list(t) for t in zip(*sorted(zip(Alist, Dlist)))) C = 0 for j in range(N): C +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL V...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
for _ in range(int(input())): n, k = map(int, input().split()) z = input().split() a = list(map(int, z[:n])) z = input().split() d = list(map(int, z[:n])) z = input().split() b = list(map(int, z[:k])) dis = [(p - c) for c, p in zip(b, [sum(d)] + b)] lo = sum(dis[::2]) hi = sum(di...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
class CardSet(object): def __init__(self, cardValue, cardAmount): self.cardValue = cardValue self.cardAmount = cardAmount T = int(input()) for _ in range(T): N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] D = [int(x) for x in input().split()] B = [i...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VA...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
for _ in range(int(input())): n, k = map(int, input().split()) A = list(map(int, input().split())) D = list(map(int, input().split())) B = list(map(int, input().split())) C = [] f1 = 0 for i in range(n): C.append([A[i], D[i]]) f1 += D[i] C.sort() if f1 != n: j...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 L...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
c = int(input()) for _ in range(c): n, k = input().split() n, k = int(n), int(k) a = list(map(int, input().split())) d = list(map(int, input().split())) b = list(map(int, input().split())) arr = [(a[i], d[i]) for i in range(n)] arr.sort() a = [arr[i][0] for i in range(n)] d = [arr[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_C...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
t = int(input()) for z in range(t): n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] d = [int(x) for x in input().split()] b = [int(x) for x in input().split()] big = [[a[i], d[i]] for i in range(n)] big.sort() left = 0 right = n - 1 num_cards = sum(d) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
T = int(input()) for testCase in range(T): N, K = list(map(int, input().split())) A = list(map(int, input().split())) D = list(map(int, input().split())) C = [] n = 0 for i in range(N): C.append([A[i], D[i]]) n += D[i] C.sort() B = list(map(int, input().split())) righ...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CAL...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
t = int(input()) for j in range(t): n, k = map(int, input().split(" ", 2)[:2]) list1 = list(map(int, input().split(" ", n)[:n])) list2 = list(map(int, input().split(" ", n)[:n])) list3 = list(map(int, input().split(" ", k)[:k])) list4 = [] s = sum(list2) for i in range(n): temp = [li...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR ASSIGN VAR FU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is playing a game with his brother Chefu. Before the game begins, C cards are placed on a table. Each card has a number written on it; since C can be very large, these numbers are described by two sequences A and D. Each of these seque...
for i in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) d = list(map(int, input().split())) b = list(map(int, input().split())) l = list(map(list, zip(a, d))) l = sorted(l, key=lambda x: x[0]) s1 = 0 s2 = 0 s = 0 tot = sum(d) for j i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR F...
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 find(root, c, p, s): if root != None: if p == c: s += root.data s = find(root.left, c, p - 1, s) s = find(root.right, c, p + 1, s) return s de...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NONE IF 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 RETURN VAR FUNC_DEF IF VAR NONE IF VAR VAR RETURN VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR 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): level = 0 is_present = False target_ind = 0 while root: if root.data == target: is_present = True break if root.data > target: root = root.left ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR NONE RETURN IF VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EX...
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 find(root): if root == None: return None if root.data == target: return root elif root.data > target: return find(root.left) else: ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NONE RETURN NONE IF VAR VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBE...
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...
def verticalSumUtil(root, hd, Map): if root == None: return verticalSumUtil(root.left, hd - 1, Map) if hd in Map.keys(): Map[hd] = Map[hd] + root.data else: Map[hd] = root.data verticalSumUtil(root.right, hd + 1, Map) class Solution: def calculate(self, root): ...
FUNC_DEF IF VAR NONE RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR CLASS_DEF FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR NUMBER VAR RETURN VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR IF VAR 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): return self.dfs(root, target, False, 0, 0) - 1 def dfs(self, r, targetValue, hasFound, targetPos, currPos): if r is None: return 0 s = 0 if hasFound and targetPos == currPos: s += r.data ...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RE...
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): stack = [root] ans = None while stack: root_val = stack.pop() if root_val is None: continue if root_val.data == target: ans = root_val break ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR NONE WHILE VAR ASSIGN VAR FUNC_CALL VAR IF VAR NONE IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NONE RETURN NUMBER FUNC_DEF ASSIGN VAR LIST VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NONE...
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 sum_below(node, level): while node and node.data != target: if node.data < target: node = node.right level += 1 else: node = node.left ...
CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR VAR LIST NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR LIST FOR VAR VAR VAR IF VAR VAR VAR VAR IF 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 __init__(self): self.targetNode = None self.nodeSum = 0 def verticallyDownBST(self, root, target): result = self.findNode(root, target) if result == False: return -1 self.downwardTraversal(self.targetNode, 0) return self.nodeSum -...
CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF IF VAR NONE RETURN 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 IF V...
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, tar): def helper(node, data): if not node: return 0 ans = 0 if data == 0: ans += node.data ans += helper(node.left, data - 1) + helper(node.right, data + 1) return ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR NONE EXPR 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: ans = 0 def rootPresent(self, root, target): if root == None: return False if root.data > target: return self.rootPresent(root.left, target) elif root.data < target: return self.rootPresent(root.right, target) else: ...
CLASS_DEF ASSIGN VAR NUMBER 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 ASSIGN VAR VAR RETURN NUMBER FUNC_DEF IF VAR NONE RETURN 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 ...
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 find(root, target): if root == None: return False if root.data > target: return find(root.left, target) elif root.data < target: return find(root.right, target...
CLASS_DEF FUNC_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 ASSIGN VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR NONE RETURN IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR ...
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...
MAIN = {(0): 0} class Solution: def verticallyDownBST(self, root, target): hs = 0 while root != None: if root.data == target: self.get_sum(root, hs, "o") res = MAIN[0] MAIN[0] = 0 if res: return res ...
ASSIGN VAR DICT NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NONE IF VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR RETURN VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN NUMBER FUNC_DEF IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VA...
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 getsum(self, root, pos): if root is None: return 0 return ( self.getsum(root.left, pos - 1) + self.getsum(root.right, pos + 1) + (root.data if pos == 0 else 0) ) def verticallyDownBST(self, root, target): if ro...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN 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 verticallyDownBST(self, root, target): self.foundTarget = False self.target = target self.ans = 0 self.find(root) if not self.foundTarget: return -1 return self.ans - target def verticalTraversal(self, r, val): if r is not...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR RETURN NUMBER RETURN BIN_OP VAR VAR FUNC_DEF IF VAR NONE IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NONE IF VAR VAR VAR ASSIGN VAR NUMBER ASSI...
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 __init__(self): self.levelFind = None self.colFind = None self.find = False self.summ = 0 self.startNode = None def traverse(self, node, target, level, col): if not node: return -1 if node.data < target: self.t...
CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VA...
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): l = [] def findColumn(root, target, l, v, level): if root == None: return if root.data == target: l.append(v) l.append(level) l.append(root) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NONE RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBE...
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...
import sys sys.setrecursionlimit(1000000) class Solution: def __init__(self): self.answer = -1 self.target_position = 0 self.start_node = None self.total = 0 def findTarget(self, root, target, target_position): if root is None: return if root.data...
IMPORT EXPR FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE RETURN IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NONE ...
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 findVerticalSum(self, root, pos, sum): if root is None: return 0 sum += self.findVerticalSum(root.left, pos - 1, sum) + self.findVerticalSum( root.right, pos + 1, sum ) if pos == 0: sum += root.data return sum def ...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC...
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 findnode(self, root): if not root: return if root.data == self.target: return root return self.findnode(root.left) or self.findnode(root.right) def verticalsum(self, root, parity): if not root: return if parity == ...
CLASS_DEF FUNC_DEF IF VAR RETURN IF VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR RETURN 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 VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER EXP...
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 __init__(self): self.flag = False self.ans = 0 self.g = 0 self.start = None def dfs(self, root, trt, gg): if root is None: return if root.data == trt and not self.flag: self.g = gg self.start = root ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FUNC_DEF IF VAR NONE RETURN IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR IF VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR 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 searchTarget(self, root, target): if root == None: return -1 if root.data == target: return root if root.data > target: return self.searchTarget(root.left, target) else: return self.searchTarget(root.right, target) ...
CLASS_DEF 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 FUNC_DEF IF VAR NONE IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NONE IF BIN_OP VAR NUMBER NUMBER ASSIGN 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): arr = [0, 0] node = [0] found = self.find(root, target, 0, 0, arr, node) if not found: return -1 return self.getsum(node[0], target, arr[0], arr[1], arr) def find(self, root, target, h, v, arr, node)...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR IF VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VA...
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 not root: return def t_node(root, target): if not root: return if target < root.data: return t_node(root.left, target) elif target > root.data: ...
CLASS_DEF FUNC_DEF IF VAR RETURN FUNC_DEF IF VAR RETURN IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VA...
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...
def findRecurse(root, target, depth, column): foundNode = None if root: if root.data == target: return root if root: foundNode = findRecurse(root.left, target, depth + 1, column - 1) if foundNode is None: foundNode = findRecurse(root.right, target, depth + 1, ...
FUNC_DEF ASSIGN VAR NONE IF VAR IF VAR VAR RETURN VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VA...
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 dfs(self, root, targetValue, hasFound=False, targetPos=0, currPos=0): if root is None: return 0 ans = 0 if hasFound and targetPos == currPos: ans += root.data if not hasFound and root.data == targetValue: hasFound = True ...
CLASS_DEF FUNC_DEF NUMBER NUMBER NUMBER IF VAR NONE RETURN NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VA...
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): target_node = self.find_target(root, target) if target_node is None: return -1 return self.vertical_sum(target_node, 0) - target_node.data def vertical_sum(self, node, column): _sum = 0 if node is no...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NONE IF VAR NUMBER 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 IF VAR VAR RETURN VAR IF V...
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 __init__(self): self.res = -1 self.s = 0 def check(self, a, r, k): if a == None: return 0 o = self.check(a.left, r - 1, k) p = self.check(a.right, r + 1, k) if a.data == k: self.res = a return o + p + a.data ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF IF VAR NONE RETURN IF VAR VAR VAR NUMBER VAR VAR EXPR 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 verticallyDownBST(self, root, target): tmp = root found = False y = 0 while tmp: if target == tmp.data: found = True break elif target < tmp.data: y -= 1 tmp = tmp.left ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF IF VAR NONE RETURN IF VAR VAR VAR VAR EXPR FUNC...
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): sol = False res = 0 targetCol = 0 def dfs(node, solved, col): nonlocal sol, targetCol, res if not node: return if solved and targetCol == col: res += node....
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL V...
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): rt = root while True: if rt.data == target: break elif rt.data > target: if rt.left: rt = rt.left else: return -1 el...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR WHILE NUMBER IF VAR VAR IF VAR VAR IF VAR ASSIGN VAR VAR RETURN NUMBER IF VAR ASSIGN VAR VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VA...
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 __init__(self): self.s = 0 def verticallyDownBST(self, root, target): return self.findsum(root, target, 0, None, False) def findsum(self, root, target, s, pos, takeNode): root = self.getNode(root, target, s, pos) if root == None: return -1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER NONE NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NONE RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF IF VAR NONE RETURN IF VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR A...
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, node, target): if self.found: return if node.data == target: self.found = node return if node.left: self.search(node.left, target) if node.right: self.search(node.right, target) def tra...
CLASS_DEF FUNC_DEF IF VAR RETURN IF VAR VAR ASSIGN VAR VAR RETURN IF VAR EXPR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR VAR IF 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): if not root: return def t_node(root, target): if not root: return if target < root.data: return t_node(root.left, target) elif target > root.data: ...
CLASS_DEF FUNC_DEF IF VAR RETURN FUNC_DEF IF VAR RETURN IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WH...
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 down(node, direction): nonlocal res if node: if direction == 0: res += node.data down(node.left, direction - 1) down(node.right, direction + 1) ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR 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 IF VAR NONE IF VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NONE E...
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): if root is None: return 0 count = 0 if x == 0: count += root.data count += helper(root.left, x - 1) count += helper(root.right, x + 1)...
CLASS_DEF FUNC_DEF 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 NUMBER RETURN VAR IF VAR NONE RETURN NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR 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): dummy = None while root: if root.data == target: dummy = root break if root.data > target: root = root.left else: root = root.right ...
CLASS_DEF FUNC_DEF ASSIGN VAR NONE WHILE VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR RETURN NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL...
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...
def lo1(root, target): if root is not None: lo1(root.left, target) if root.data == target: m[0] = root m[1] = 1 lo1(root.right, target) def lo2(root, p): if root is not None: lo2(root.left, p - 1) if p == 0: l.append(root.data) ...
FUNC_DEF IF VAR NONE EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NONE EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR L...
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): searchNode = self.findNode(root, target) if searchNode == None: return -1 add = [0] self.verticalSum(searchNode, searchNode, 0, add) return add[0] def findNode(self, root, target): if root !=...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR RETURN VAR NUMBER FUNC_DEF IF VAR NONE IF VAR VAR RETURN VAR ASSIGN VAR VAR NONE NONE ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF 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...
def find(root, target): if root == None: return -1 if root.data == target: return root if root.data > target: return find(root.left, target) return find(root.right, target) class Solution: def verticallyDownBST(self, root, target): node = find(root, target) ...
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 CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL ...
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): temp = root while temp: if temp.data == target: break elif temp.data < target: temp = temp.right else: temp = temp.left if temp is None: return...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR WHILE VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NONE RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR BI...
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...
ping = None class Solution: def fun(self, root, level, ans): if root: if level == 0: ans += root.data ans = self.fun(root.left, level - 1, ans) ans = self.fun(root.right, level + 1, ans) return ans def check(self, root, target): glo...
ASSIGN VAR NONE CLASS_DEF FUNC_DEF IF VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF IF VAR RETURN IF VAR VAR ASSIGN VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR NUMBER...