description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
def main(): n, t = map(int, input().split()) a = [int(i) for i in input().split()] x = min(a) ans = 0 while t >= x: cnt = 0 s = 0 tau = t for i in range(n): if tau >= a[i]: tau -= a[i] s += a[i] cnt += 1 ...
FUNC_DEF 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 ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_O...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) a = list(map(int, input().split())) ans, nn = 0, n while t >= min(a) and nn > 0: tot = sum(a) ans += t // tot * nn t %= tot for i in range(n): if t < a[i]: nn -= 1 a[i] = 0 elif a[i] > 0: t -= a[i] ans += 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR V...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, k = map(int, input().split()) l = [int(i) for i in input().split()] cnt = 0 n = len(l) k1 = k % sum(l) mini = min(l) def calc(k1): cnt = 0 sm = 0 for i in l: if k1 >= i: k1 -= i cnt += 1 sm += i return cnt, sm ans = k // sum(l) * n k1 = k % sum(l) while...
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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 while k >= min(a): s = 0 count = 0 for i in a: if i <= k: k -= i s += i count += 1 ans += k // s * count + count k -= k // s * s print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_O...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
import sys def least_significant_bit(i): return i & -i class FenwickTree: def __init__(self, values): self.n = len(values) + 1 self.data = [0] * self.n for i, v in enumerate(values): self.add(i, v) def add(self, index, value): i = index + 1 while i <...
IMPORT FUNC_DEF RETURN BIN_OP VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIG...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, T = input().split() n = int(n) T = int(T) tendas = list(map(int, input().split())) doces = 0 minimo = min(tendas) while T >= minimo: soma = 0 cont = 0 for i in range(n): if soma + tendas[i] <= T: soma += tendas[i] cont += 1 doces += cont * (T // soma) T = T % soma ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, T = map(int, input().split()) a = list(map(int, input().split())) cur = 0 ased = a[:] ased.sort(key=lambda x: -x) ased += [0] s = sum(a) r = 0 while cur != n: while ased[cur] > T: s -= ased[cur] cur += 1 if s <= T and s > 0: d, T = divmod(T, s) r += d * (n - cur) conti...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
from sys import stdin input = stdin.readline n, t = map(int, input().split()) lst = list(map(int, input().split())) s = sum(lst) x = min(lst) candy = n * (t // s) t -= s * (t // s) while t >= x: s, c = 0, 0 for i in lst: if i <= t - s: c += 1 s += i candy += c * (t // s) ...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR I...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) a = list(map(int, input().split())) b = [] for i in a: if i <= t: b.append(i) c = 0 n = len(b) s = sum(b) while len(b) > 0 and t >= min(b): if s <= t: k = t // s t -= s * k c += n * k else: for i in b: if i <= t: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF VA...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
def splitInput(): return list(map(int, input().split())) nT = splitInput() money = nT[1] kioski = list(filter(lambda x: x <= money, splitInput())) konfet = 0 if len(kioski) > 0: minKioskiPrice = min(kioski) while money >= minKioskiPrice: sumKioski = sum(kioski) countCycles = money // sumKi...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR ...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = input().strip().split(" ") n, t = int(n), int(t) arr = list(map(int, input().strip().split(" "))) a = 0 flag = 1 while flag and t: cnt = 0 x = t y = 0 flag = 0 for i in arr: if x >= i: cnt += 1 x -= i y += i flag = 1 if flag == 0: ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VA...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
import sys def main(args): n, t = list(map(int, input().split())) prices = list(map(int, input().split())) loop_prices = sum(prices) loop_n = n tot = 0 while loop_n > 0: c = t // loop_prices tot += c * loop_n t -= c * loop_prices loop_prices = 0 for i, v...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR V...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) arr = list(map(int, input().split())) ans = 0 while True: tmp = list() paid = 0 for v in arr: if v <= t: tmp.append(v) t -= v paid += v if paid != 0: ans += len(tmp) * (1 + t // paid) t %= paid else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) a = list(map(int, input().split())) sum1 = sum(a) b = a.copy() b.sort() cnt = n * (t // sum1) t %= sum1 i = 0 N = n while n != 0 and t != 0: while len(b) and b[-1] > t: sum1 -= b[-1] b.pop() n -= 1 if not len(b): break while a[i] > t: ...
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 VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER WHILE FUNC_CALL V...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) a = list(map(int, input().split())) x = min(a) cands = 0 while t >= x: y = sum(a) if t >= y: f = len(a) cands += t // y * f t = t - t // y * y else: for item in a: if t >= item: t = t - item cands +=...
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 VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP ...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) n, t = I() l = I() s = sum(l) an = t // s * n t = t % s i = 0 mi = min(l) while t >= mi: c = k = i = 0 while i < n: if c + l[i] <= t: k += 1 c += l[i] i += 1 if c == 0: break ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR NUMBE...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, T = list(map(int, input().split())) a = list(map(int, input().split())) summ = [] cur = 0 mmin = a[0] for item in a: cur += item summ.append(cur) mmin = min(item, mmin) def helper(x, l, r=n - 1): z = l while l < r: mid = (l + r) // 2 cur = summ[mid] - summ[z] + a[z] if c...
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 LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VA...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
w = input().split(" ") n = int(w[0]) t = int(w[1]) w = input().split(" ") a = [] for i in w: a.append(int(i)) sm = 0 while True: c_candies = 0 c_sum = 0 for i in range(n): if t >= a[i]: c_candies += 1 sm += 1 c_sum += a[i] t -= a[i] if c_candie...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) l = list(map(int, input().split())) p = sum(l) s = 0 s += n * (t // p) t -= p * (t // p) x = min(l) i = 0 while t >= x: countinround = 0 costround = 0 p = t for i in l: if p >= i: countinround += 1 costround += i p -= i if ...
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 VAR ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = list(map(int, input().split())) a = list(map(int, input().split())) _ = min(a) r = 0 s = sum(a) n_ = n while t >= _: v = int(t / s) r += v * n_ t -= v * s for i in range(n): if a[i] == 0: continue if t >= a[i]: r += 1 t -= a[i] else: ...
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 VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
line1 = input().split() line2 = input().split() Booths, Money = map(int, line1) Price = list(map(int, line2)) Count = 0 cur = 0 mini = min(Price) Skip = set() pre = Money pre_count = 0 while Money >= mini: if cur not in Skip: if Price[cur] <= Money: Money -= Price[cur] Count += 1 ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR VAR VAR...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
def buy(n, t, c, s): if len(c) == 0: return 0 ans = 0 if t >= s: ans += n * (t // s) t %= s nc = [] for i in range(n): if t >= c[i]: nc.append(c[i]) t -= c[i] ans += 1 else: s -= c[i] ans += buy(len(nc), t, n...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) a = list(map(int, input().split())) ans = 0 while True: b = False k = 0 s = 0 for i in range(n): if t >= a[i]: s += a[i] k += 1 b = True if not b: break if t < s: for i in range(n): if t >= a...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR VAR FOR VAR FUN...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) u = list(map(int, input().split())) ans = 0 s = sum(u) while 1 == 1: ans += t // s * n t = t % s t1 = t u1 = [] for i in range(n): if u[i] <= t: t -= u[i] u1.append(u[i]) ans += 1 else: s -= u[i] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR V...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
def inint(): return int(input()) def inlist(): return list(map(int, input().split())) def main(): n, t = inlist() a = inlist() sol = 0 while True: ss = 0 amt = 0 for i in a: if i <= t: sol += 1 ss += i t -= i...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, m = map(int, input().split()) t = list(map(int, input().split())) wyn = 0 t_del = [] t2 = [] t_pom = [] t_min = 999999999999999999 tmp_sum = sum(t) while True: tmp_sum = 0 for y in range(0, len(t), +1): if m < t[y]: continue m -= t[y] wyn += 1 t_pom.append(t[y]) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBE...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
I = lambda: list(map(int, input().split())) n, have = I() l = I() ans = 0 while have: got = 0 temp = 0 i = 0 while i < n: if have - (temp + l[i]) >= 0: temp += l[i] got += 1 i += 1 if not got: break ans += have // temp * got have %= temp print(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR ...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n = [int(i) for i in input().split()] l = [int(i) for i in input().split()] m = 0 while len(l) > 0: m += n[1] // sum(l) * len(l) n[1] %= sum(l) l = [i for i in l if i <= n[1]] for i in l: if n[1] - i >= 0: m += 1 n[1] -= i else: l = [i for i in l if i <= n[1]]...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, k = map(int, input().split()) a = list(map(int, input().split())) x = min(a) ans = 0 sum1 = 0 cnt = 0 while k >= x: sum1 = 0 cnt = 0 for i in range(n): if a[i] <= k: sum1 = sum1 + a[i] cnt = cnt + 1 t = cnt * (k // sum1) ans = ans + t k = k % sum1 for i in ...
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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR ...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) inrr = input().split() a = [] for i in inrr: ii = int(i) if ii <= t: a.append(ii) n = len(a) if n == 0: print(0) else: minier = min(a) ans = 0 row = [] for x in range(n): if a[x] <= t: row.append(a[x]) while t >= minier: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR V...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
def main(): n, T = map(int, input().split()) ls = map(int, input().split()) a = list(ls) ans = 0 while 1: if T < min(a): break s = 0 cnt = 0 for x in a: if s + x <= T: s += x cnt += 1 ans += T // s * cnt ...
FUNC_DEF 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 ASSIGN VAR NUMBER WHILE NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR V...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, k = [*map(int, input().split())] numbers = [*map(int, input().split())] count = 0 suma = sum(numbers) sorted_numbers = sorted(numbers) count_numbers = len(numbers) while count_numbers != 0: ile = k // suma if ile >= 1: count += count_numbers * ile k -= suma * ile else: copy = [] ...
ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, T = map(int, input().split()) costs = input().split() costs = map(int, costs) costs = list(costs) min_cost = min(costs) confets = 0 while T >= min_cost: c = T curr = 0 spent = 0 for x in costs: if x <= c: curr += 1 spent += x c -= x confets += T // spen...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR ...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = [int(x) for x in input().split()] a = [int(x) for x in input().split()] ans = 0 while t > 0 and len(a) > 0: s = sum(a) ans += t // s * len(a) t = t % s b = [] for i in range(len(a)): if a[i] <= t: ans += 1 t -= a[i] if a[i] <= t: b.a...
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 NUMBER WHILE VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
import sys n, T = map(int, sys.stdin.readline().split()) booths = list(map(int, sys.stdin.readline().split())) total_cost = 0 result = 0 cheapest_item = float("inf") candle_count = 0 while T >= cheapest_item or cheapest_item == float("inf"): running_T = T total_cost = 0 candle_count = 0 for booth in bo...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR I...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, T = map(int, input().split()) a = list(map(int, input().split())) s = sum(a) t = n * (T // s) left = T % s b = {} j = 0 temp = [] for i in range(n): b[i] = a[i] while n > 0 and left > 0: for j in b: if left >= b[j]: t = t + 1 left = left - b[j] else: n = n ...
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 VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR WHILE...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
R = lambda: map(int, input().split()) n, T = R() a = list(R()) res = 0 while 1: acc, cnt = 0, 0 for x in a: if acc + x <= T: acc += x cnt += 1 if not acc: break res += T // acc * cnt T %= acc print(res)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
import sys N, T = list(map(int, sys.stdin.readline().strip().split())) nums = list(map(int, sys.stdin.readline().strip().split())) ret = 0 while True: t = 0 count = 0 for item in nums: if T >= t + item: t += item count += 1 if not count: break ret += T // t *...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR VA...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
from sys import stdin input = stdin.readline n, t = map(int, input().split()) l = list(map(int, input().split())) s = sum(l) cnt, d = 0, [1] * n tot = 0 while cnt < n: if t >= s and s > 0: tot += t // s * (n - cnt) t %= s if t < s: curr = 0 for i in range(n): if d[i]...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF V...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
import sys n, T = [int(i) for i in sys.stdin.readline().strip().split()] A = [int(i) for i in sys.stdin.readline().strip().split()] r = T // sum(A) * n T = T % sum(A) S = list(range(n)) s = 0 k = 0 while S: U = [] for i in S: if A[i] <= T: T = T - A[i] r = r + 1 if A...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, t = map(int, input().split()) A = list(map(int, input().split())) ans = 0 while t > 0: k = 0 suma = 0 t1 = t f = 0 for i in range(n): if A[i] <= t1: suma += A[i] t1 -= A[i] k += 1 f = 1 if f == 1: ans = ans + k * (t // suma) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBE...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
n, T = map(int, input().split(" ")) a = list(map(int, input().split(" "))) candies = 0 remaining = len(a) min_a = min(a) while remaining > 0: for i, ai in enumerate(a): if ai > T: a[i] = 0 remaining -= 1 if remaining == 0: break round_cost = sum(a) max_full_rounds...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER A...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
N, T = map(int, input().split()) A = [int(x) for x in input().split()] ans = 0 while A and T > 0: sa = sum(A) if T >= sa: ans += T // sa * len(A) T %= sa else: for i, a in enumerate(A): if T <= 0: break if T >= a: T -= a ...
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 NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER A...
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. P...
def sum(a): s = 0 for i in a: s += i return s n, T = map(int, input().split()) a = list(map(int, input().split())) sum = sum(a) k = 0 k += n * (T // sum) T %= sum new_a = [] new_sum = 0 ch = True while ch: for i in range(n): if a[i] <= T: new_a.append(a[i]) new_...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN 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 VAR ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER W...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: temp = [] def leafNodes(self, arr, N): temp = [] def fleaf(pre): n = len(pre) if n == 1: temp.append(pre[0]) return if n < 1: return left = pre[0] for i in range(1, n): ...
CLASS_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN IF VAR NUMBER RETURN ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBE...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, n): st = [] ans = [] st.append(arr[0]) for i in range(1, n): if arr[i] < st[-1]: st.append(arr[i]) else: temp = st[-1] st.pop() if st and arr[i] > st[-1]:...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): if N < 1: return [] stack = [arr[0]] ans = [] for i in range(1, N): if arr[i] > stack[-1]: iniSize = len(stack) while len(stack) > 0 and stack[-1] < arr[i]: stack...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): stk = [] res = [] for i in range(N): if len(stk) > 0 and stk[-1] < arr[i]: leaf = stk[-1] count = 0 while len(stk) > 0 and stk[-1] < arr[i]: stk.pop() ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VA...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): st = [] ans = [] for i in arr: if st and st[-1] < i: prev = st.pop() if st and st[-1] < i: ans.append(prev) while st and st[-1] < i: st.po...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, n): stack = [arr[0]] l = [] for i in range(1, n): if arr[i] < stack[-1]: stack.append(arr[i]) else: presize = len(stack) temp = stack[-1] while stack and arr[i] >...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EX...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): mx = [] leaf = [] prev = arr[0] flag = 0 for i in range(1, N): if arr[i] < prev: mx.append(prev) prev = arr[i] else: flag = 0 while mx: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL V...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, n): ans = [] s = [] j = 0 for i in range(1, n): if arr[j] > arr[i]: s.append(arr[j]) else: valid = False while s: if arr[i] > s[-1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): s = [] i = 0 ans = [] for j in range(1, N): found = False if arr[i] > arr[j]: s.append(arr[i]) else: while len(s) != 0: if arr[j] > s[-1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CA...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ans = [] def dfs(index, mmin, mmax): nonlocal ans if index[0] == N - 1: ans.append(arr[index[0]]) return node = arr[index[0]] lindex = index[0] + 1 left, right =...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NONE NONE IF VAR VAR VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ans = [] s = [] i, j = 0, 1 while j < N: flag = False if arr[i] > arr[j]: s.append(arr[i]) else: while s and s[-1] < arr[j]: s.pop() ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ans, stack = [], [] stack.append(arr[0]) for i in range(1, N): if arr[i] < stack[-1]: stack.append(arr[i]) else: temp = stack[-1] rem = 0 while stack != [] an...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR LIST VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ret = [] def collect(xs): nonlocal ret if len(xs) <= 1: if xs: ret.append(xs[0]) return collect([x for x in xs if x < xs[0]]) collect([x for x in xs if x...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): stack = [] res = [] for i in range(N - 1): if arr[i] > arr[i + 1]: stack.append(arr[i]) elif stack and arr[i + 1] > stack[-1]: res.append(arr[i]) while stack and stack[-1] < ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Tree: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def leafNodes(self, arr, N): stack = [] ans = [] for x in arr: if stack and stack[-1] < x: prev = stack...
CLASS_DEF FUNC_DEF NUMBER NONE NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VA...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ans = [] stack = [arr[0]] for i in range(1, N): if arr[i] < stack[-1]: stack.append(arr[i]) else: a = stack.pop() b = 0 while len(stack) > 0 and stack[-1] < a...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ans = [] st = [arr[0]] for i in range(1, N): if arr[i] < st[-1]: st.append(arr[i]) else: top = st[-1] co = 0 while st and st[-1] < arr[i]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): n, stack, leaf_nodes = N, [arr[0]], [] for i in range(1, n): if arr[i] < stack[-1]: stack.append(arr[i]) else: temp, removed_counter = stack[-1], 0 while stack and stack[-1] < arr[i]...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR LIST VAR NUMBER LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, n): ans = list() j = 0 s = list() for i in range(1, n): f = 1 if arr[j] > arr[i]: s.append(arr[j]) else: while len(s) != 0: if arr[i] > s[-1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VA...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): stack, ans = [arr[0]], [] for i in range(1, len(arr)): if arr[i] > stack[-1]: pop_count, top_elem = 0, stack[-1] while stack and stack[-1] < arr[i]: stack.pop() pop_count...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR LIST VAR NUMBER LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ind = -1 res = [] def recur(low, high): nonlocal res, ind ind += 1 if ind >= N or arr[ind] < low or arr[ind] > high: ind -= 1 return -1 else: val = a...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
def leafNodeHelper(preorder, inorder, pl, pu, il, ih, ans): if pl == pu: ans.append(preorder[pl]) return if pl > pu: return rIndex = il while True: if preorder[pl] == inorder[rIndex]: break rIndex += 1 Index = rIndex - il leafNodeHelper(preorde...
FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN IF VAR VAR RETURN ASSIGN VAR VAR WHILE NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes1(self, arr, N): global ans if N == 0: return if N == 1: ans.append(arr[0]) return root = arr[0] index = 1 for i in range(1, N): if arr[0] < arr[i]: index = i ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DE...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ans = list() self.solve(arr, ans) return ans def solve(self, arr, ans): if len(arr) < 1: return if len(arr) == 1: ans.append(arr[0]) return root = arr[0] i = 1 while...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR V...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): i, j = 0, 1 stack = [] result = [] while j < N: if arr[i] > arr[j]: stack.append(arr[i]) else: flag = False while stack and stack[-1] < arr[j]: fl...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): ans = [] def solve(a): if 0 <= len(a) < 2: ans.extend(a) return root = a[0] i = 1 while i < len(a) and root > a[i]: i += 1 solve(a[1:i]) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): st = [] leaf = [] st.append(arr[0]) t = 0 for i in range(1, N): if arr[i] > st[t]: if t > 0 and arr[i] > st[t - 1]: leaf.append(st.pop()) t -= 1 w...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): sol = [] stk = [] i = 0 for j in range(1, N): flag = False if arr[i] > arr[j]: stk.append(arr[i]) else: while len(stk) > 0: if arr[j] > stk[-1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): if len(arr) == 1: return arr stack = [] leafNode = [] stack.append(arr[0]) i = 1 while i < len(arr): if arr[i] <= stack[-1]: stack.append(arr[i]) else: te...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR F...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): if len(arr) == 0: return [] if len(arr) == 1: return [arr[0]] for i in range(1, len(arr)): if arr[i] > arr[0]: idx = i break else: idx = i + 1 left = ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST IF FUNC_CALL VAR VAR NUMBER RETURN LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): if N == 1: return [arr[0]] if N == 2: return [arr[-1]] stack = [arr[0]] res = [] for i in range(1, N): if arr[i] < stack[-1]: stack.append(arr[i]) else: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST VAR NUMBER IF VAR NUMBER RETURN LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE F...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): st = [] lis = [] st.append(arr[0]) for i in range(1, N): if arr[i] < st[-1]: st.append(arr[i]) else: temp = st[-1] count = 0 while len(st) != 0 and st...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUM...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): stack = [] output = [] for num in arr: possibleLeafNode = None totalRemoved = 0 while stack and stack[-1] < num: if not possibleLeafNode: possibleLeafNode = stack[-1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR IF VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodesHelper(self, l, r, arr, leaves): if l > r: return if l == r: leaves.append(arr[l]) return mid = l + 1 while mid <= r and arr[mid] < arr[l]: mid += 1 self.leafNodesHelper(l + 1, mid - 1, arr, leaves)...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER V...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
st = "" out = [] def check(arr): global st global out if len(arr) == 0: return if len(arr) == 1: st = st[1:] out.append(arr[0]) return else: j = arr.index(st[0]) st = st[1:] check(arr[0:j]) check(arr[j + 1 :]) return class S...
ASSIGN VAR STRING ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN CLASS_DEF FUNC_...
Given a preorder traversal of a BST, find the leaf nodes of the tree without building the tree. Example 1: Input: N = 2 arr = {2,1} Output: {1} Explaination: 1 is the only leaf node. Example 2: Input: N = 3 Arr = {3, 2, 4} Output: {2, 4} Explaination: 2, 4 are the leaf nodes. Your Task: You don't need to read input or ...
class Solution: def leafNodes(self, arr, N): st = [] l = [] for i in range(N - 1): f = 0 if arr[i] > arr[i + 1]: st.append(arr[i]) else: while len(st) > 0: if arr[i + 1] > st[-1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR...
Chef has binary string A of length N. He constructs a new binary string B by concatenating M copies of A together. For example, if A = \texttt{"10010"}, M = 3, then B = \texttt{"100101001010010"}. Chef calls an index i (1 ≤ i ≤ N \cdot M) *good* if: pref_{i} = suf_{i + 1}. Here, pref_{j} = B_{1} + B_{2} + \ldots + B_...
for i in range(int(input())): n, m = map(int, input().split()) s = input() c_1 = s.count("1") c = 0 if c_1 == 0: print(n * m) elif c_1 * m % 2 == 1: print(0) elif m % 2 == 0: for i in range(n): if s[i] == "0": c = c + 1 else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMB...
Chef has binary string A of length N. He constructs a new binary string B by concatenating M copies of A together. For example, if A = \texttt{"10010"}, M = 3, then B = \texttt{"100101001010010"}. Chef calls an index i (1 ≤ i ≤ N \cdot M) *good* if: pref_{i} = suf_{i + 1}. Here, pref_{j} = B_{1} + B_{2} + \ldots + B_...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) a = input() p = [] k = 0 for i in a: k += int(i) p.append(k) s = [(0) for i in range(n)] k = 0 for i in range(n - 1, -1, -1): k += int(a[i]) s[i] = k s.append(0) if int(a) == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BI...
Chef has binary string A of length N. He constructs a new binary string B by concatenating M copies of A together. For example, if A = \texttt{"10010"}, M = 3, then B = \texttt{"100101001010010"}. Chef calls an index i (1 ≤ i ≤ N \cdot M) *good* if: pref_{i} = suf_{i + 1}. Here, pref_{j} = B_{1} + B_{2} + \ldots + B_...
t = int(input()) def main(s): l = list(s) k = l.count("1") if k % 2 != 0: return 0 else: c = [] for i in range(len(s)): if s[i] == "1": c.append(i) p = c[len(c) // 2] - c[len(c) // 2 - 1] return p for i in range(t): l = list(map...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP ...
Chef has binary string A of length N. He constructs a new binary string B by concatenating M copies of A together. For example, if A = \texttt{"10010"}, M = 3, then B = \texttt{"100101001010010"}. Chef calls an index i (1 ≤ i ≤ N \cdot M) *good* if: pref_{i} = suf_{i + 1}. Here, pref_{j} = B_{1} + B_{2} + \ldots + B_...
for _ in range(int(input())): n, m = (int(i) for i in input().split()) a = input() if a.count("0") == n: print(n * m) continue if m % 2 == 0: a = a + a s = list(map(int, list(a))) pre = [0] * len(s) pre[0] = s[0] for i in range(1, len(s)): pre[i] = pre[i -...
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 IF FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN ...
Chef has binary string A of length N. He constructs a new binary string B by concatenating M copies of A together. For example, if A = \texttt{"10010"}, M = 3, then B = \texttt{"100101001010010"}. Chef calls an index i (1 ≤ i ≤ N \cdot M) *good* if: pref_{i} = suf_{i + 1}. Here, pref_{j} = B_{1} + B_{2} + \ldots + B_...
n = int(input()) for i in range(n): a, b = map(int, input().split()) c = input() ones, d, e = c.count("1"), 0, 0 if ones == 0: print(a * b) elif ones * b % 2 == 1: print(0) elif b % 2 == 0: i = 0 while i < a: if c[i] == "1": break ...
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 ASSIGN VAR VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN...
Chef has binary string A of length N. He constructs a new binary string B by concatenating M copies of A together. For example, if A = \texttt{"10010"}, M = 3, then B = \texttt{"100101001010010"}. Chef calls an index i (1 ≤ i ≤ N \cdot M) *good* if: pref_{i} = suf_{i + 1}. Here, pref_{j} = B_{1} + B_{2} + \ldots + B_...
t = int(input()) while t > 0: t -= 1 N, M = [int(x) for x in input().split()] A = input() target = A.count("1") * M res = 0 cc = 0 start = N * (int(M / 2) - 1) cc = target / M * (int(M / 2) - 1) end = int(N * M / 2) + N if target == 0: res = M * N elif target % 2 == 0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BI...
Chef has binary string A of length N. He constructs a new binary string B by concatenating M copies of A together. For example, if A = \texttt{"10010"}, M = 3, then B = \texttt{"100101001010010"}. Chef calls an index i (1 ≤ i ≤ N \cdot M) *good* if: pref_{i} = suf_{i + 1}. Here, pref_{j} = B_{1} + B_{2} + \ldots + B_...
for _ in range(int(input())): n, m = map(int, input().split(" ")) a = input() s = [] t = 0 for i in range(n): t += int(a[i]) s.append(t) res = 0 if t == 0: print(n * m) elif m * t % 2 == 1: print(0) else: for j in range(m): pref = j...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): dict = {} l = [] A1.sort() for i in A1: if i in dict: dict[i] += 1 else: dict[i] = 1 for i in A2: if i in dict: while dict[i] > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): d = {} for i in A1: d[i] = d.get(i, 0) + 1 ans = [] flg = 0 for i in A2: if i in d: ans.extend([i] * d[i]) d[i] = 0 flg = 1 tmp = len(ans) ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR B...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): freq = {} for i in range(N): if A1[i] in freq: freq[A1[i]] += 1 else: freq[A1[i]] = 1 result = [] for i in range(M): if A2[i] in freq: for j in r...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CAL...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): dic = {} li = [] oli = [] for i in range(M): dic[A2[i]] = 0 for i in range(N): if A1[i] in dic: dic[A1[i]] += 1 else: oli.append(A1[i]) oli.sort(...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): z = [] g = {} for i in A1: g.setdefault(i, 0) g[i] += 1 for i in A2: try: z.extend([i] * g[i]) del g[i] except: continue for ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR RETURN VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): a1_counts = {} for x in A1: if x in a1_counts: a1_counts[x] += 1 else: a1_counts[x] = 1 relative_sort = [] list_a1_only = [] for y in A2: if y in a1_coun...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR BIN_OP LIST VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): freq = {} for i in A1: freq[i] = freq.get(i, 0) + 1 ans = [] for i in A2: if i in freq: ans.extend([i] * freq[i]) del freq[i] l = len(ans) for i in freq: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN V...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): dictin = {} l = [] gq = [] for i in A1: if i not in dictin: dictin[i] = 1 else: dictin[i] += 1 for i in range(M): if A2[i] in dictin: l +...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP LIST VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR BIN_OP LIST VAR VAR VAR RETURN...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): counts = {} for element in A1: if element in counts: counts[element] += 1 else: counts[element] = 1 sorted_A1 = [] for element in A2: if element in counts: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR RETURN VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): A1_dict = {} for i in A1: if i not in A1_dict: A1_dict[i] = 1 else: A1_dict[i] += 1 k = 0 for i in A2: if i in A1_dict: while A1_dict[i] > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBE...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): def bs(a, l, r, x): if r >= l: mid = l + (r - l) // 2 if x == a[mid]: while mid - 1 >= 0 and a[mid - 1] == x: mid -= 1 return mid ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER EXPR ...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): freq = {} for i in range(N): if A1[i] not in freq: freq[A1[i]] = 1 else: freq[A1[i]] += 1 result = [] for j in range(M): if A2[j] in freq: result...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR ...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def partition(self, arr, l, h): pivot = arr[h] j = l for i in range(l, h): if arr[i] < pivot: arr[i], arr[j] = arr[j], arr[i] j += 1 arr[j], arr[h] = arr[h], arr[j] return j def quicksort(self, arr, l, h): ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR V...