description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
def lower_bound(arr, left, right, target): if arr[right] < target: return right + 1 while left < right: mid = left + right >> 1 if arr[mid] >= target: right = mid else: left = mid + 1 return left T = int(input()) arr = [0] * T dp = [0] * (T + 1) for ...
FUNC_DEF IF VAR VAR VAR RETURN BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
n = int(input()) dp = [0] t = [0] i, j = 1, 1 for _ in range(n): x = int(input()) t.append(x) while x - t[i] > 89: i += 1 while x - t[j] > 1439: j += 1 try: y = min(dp[-1] + 20, dp[i - 1] + 50, dp[j - 1] + 120) dp.append(y) except: print(i, j) ans = [] for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP ...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
n = int(input()) t = [-(1 << 30)] for i in range(n): t.append(int(input())) dp = [0] paid = 0 for i in range(1, n + 1): cost = 20 + dp[-1] j = i - 1 while j >= 0: if t[i] - t[j] >= 90: cost = min(cost, 50 + dp[j]) break j -= 1 while j >= 0: if t[i] - t...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER I...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
a = b = 1 p, s = [0, 0], [0, 0] for i in range(int(input())): p.append(int(input())) while p[-1] - p[a] > 89: a += 1 while p[-1] - p[b] > 1439: b += 1 s.append(min(s[-1] + 20, s[a - 1] + 50, s[b - 1] + 120)) print(" ".join(str(u - v) for u, v in zip(s[2:], s[1:])))
ASSIGN VAR VAR NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMB...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
n = int(input()) ex1 = 0 ex2 = 0 L = [] f = [0] * (n + 1) for i in range(n): L.append(int(input())) while L[i] - L[ex1] >= 90: ex1 += 1 while L[i] - L[ex2] >= 1440: ex2 += 1 f[i + 1] = min(min(f[ex1] + 50, f[ex2] + 120), f[i] + 20) print(f[i + 1] - f[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
import sys def bs(l, r, val): l1 = l r1 = r while l1 <= r1: mid = (l1 + r1) // 2 if t[mid] >= val: res = mid r1 = mid - 1 elif t[mid] < val: l1 = mid + 1 return res t = [] n = int(sys.stdin.readline()) for i in range(n): temp = int(sys....
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
def go(l, key, plus): while t[l + 1] + plus - 1 < key: l += 1 return l INF = 10**9 n = int(input()) t = [INF] * (n + 1) t[0] = -INF c = [0] * (n + 1) l1 = 0 l2 = 0 for i in range(1, n + 1): t[i] = int(input()) l1 = go(l1, t[i], 90) l2 = go(l2, t[i], 1440) c1 = c[i - 1] + 20 c2 = c[...
FUNC_DEF WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FU...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
n = int(input()) a = [0] for i in range(n): x = int(input()) a.append(x) dp = [0] * (n + 1) dp[0] = 0 p90 = 1 p1440 = 1 for i in range(1, n + 1): dp[i] = dp[i - 1] + 20 while a[p90] + 90 <= a[i]: p90 = p90 + 1 dp[i] = min(dp[i], dp[p90 - 1] + 50) while a[p1440] + 1440 <= a[i]: p1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
n = int(input()) times = [] first_90 = 0 first_1440 = 0 sum_90 = 0 sum_1440 = 0 values = [] for i in range(n): times.append(int(input())) while times[first_90] <= times[-1] - 90: sum_90 -= values[first_90] first_90 += 1 while times[first_1440] <= times[-1] - 1440: sum_1440 -= values[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER NUMBER VAR...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
n = int(input()) trips = [] prix = [0] k = 0 j = 0 for i in range(n): trips.append(int(input())) while trips[i] - trips[j] >= 90: j += 1 while trips[i] - trips[k] >= 1440: k += 1 prix.append(min(min(prix[k] + 120, prix[j] + 50), prix[-1] + 20)) print(prix[-1] - prix[-2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_C...
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: a ticket f...
def main(): N = int(input()) S = [0] T = [0] kh = 0 kd = 0 for n in range(1, N + 1): T.append(int(input())) for i in range(kh + 1, n): if T[n] - T[i] < 90: kh = i - 1 break else: kh = i for i in range...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP V...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K, N): dp = [0, 0] m = 0 while dp[-1] < N: for i in range(len(dp) - 1, 0, -1): dp[i] += dp[i - 1] + 1 if len(dp) < K + 1: dp.append(dp[-1]) m += 1 return m
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: @lru_cache(None) def superEggDrop(self, k: int, n: int) -> int: if n == 0: return 0 elif k == 1: return n lo, hi = 1, n while lo < hi: mid = (lo + hi) // 2 r1, r2 = self.superEggDrop(k - 1, mid - 1), self.superEggDr...
CLASS_DEF FUNC_DEF VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUM...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp, ndp = {}, {} for m in range(1, N + 1): for k in range(1, K + 1): if m == 1: ndp[k] = 1 elif k == 1: ndp[k] = m else: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR RETURN VAR ASSIGN VAR VA...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution(object): def superEggDrop(self, K, N): dp = [([float("inf")] * (N + 1)) for _ in range(K + 1)] for i in range(1, K + 1): dp[i][0] = 0 dp[i][1] = 1 for j in range(1, N + 1): dp[1][j] = j for i in range(2, K + 1): k = 1 ...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: def f(t): a = 0 r = 1 for i in range(1, K + 1): r *= t - i + 1 r //= i a += r if a >= N: break return a ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUM...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: INF = N + 1 cache = {} def eggDropHelper(k, n): if (k, n) in cache: return cache[k, n] if k < 0: return INF if n == 0: return 0 if ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUN...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: def dp(k, n): if k == 1: return n if n == 0: return 0 if (k, n) in memo: return memo[k, n] res = sys.maxsize lo, hi = 1, n ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR V...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: memo = [([-1] * (K + 1)) for _ in range(N + 1)] @lru_cache(None) def drop(egg, floor): if egg == 1 or floor <= 1: return floor if memo[floor][egg] != -1: return memo[floor...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSI...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: memo = {} def dp(k, n): if (k, n) not in memo: if n == 0: ans = 0 elif k == 1: ans = n else: lo, hi = 1, n ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP V...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [([0] * (N + 1)) for _ in range(K + 1)] for i in range(1, N + 1): dp[1][i] = i for i in range(2, K + 1): s = 1 for j in range(1, N + 1): dp[i][j] = j while...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR W...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = range(N + 1) for k in range(2, K + 1): dp2 = [0] x = 1 for n in range(1, N + 1): while x < n and max(dp[x - 1], dp2[n - x]) > max(dp[x], dp2[n - x - 1]): x += ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VA...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: memo = dict() def dp(K, N): if K == 1: return N if N == 0: return 0 if (K, N) in memo: return memo[K, N] low, high = 1, N + 1 w...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_C...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
t = [[(-1) for i in range(10001)] for j in range(101)] class Solution: def superEggDrop(self, K: int, N: int) -> int: if N == 0 or N == 1: return N if K == 1: return N if t[K][N] != -1: return t[K][N] mn, l, h = sys.maxsize, 1, N while l...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: m = [[(0) for i in range(N + 1)] for j in range(K + 1)] def find(k, n): if k == 1: return n if n == 0: return 0 if m[k][n] > 0: return m[k][n] ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CAL...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def binary_search(self, A, k, n): lo = 0 hi = n mid = (lo + hi) // 2 while lo < hi: if A[k - 1][mid - 1] == A[k][n - mid]: return mid if A[k - 1][mid - 1] > A[k][n - mid]: hi = mid else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR RETURN VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VA...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: @lru_cache(None) def dp(k, n): if n == 0: ans = 0 elif k == 1: ans = n else: lo, hi = 1, n while lo < hi: x = (lo +...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBE...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [[(0) for _ in range(K + 1)] for _ in range(N + 1)] attempt = 0 while dp[attempt][K] < N: attempt += 1 for i in range(1, K + 1): dp[attempt][i] = 1 + dp[attempt - 1][i - 1] + dp[attem...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: if N == 1: return 1 eggSolutions = [[None for n in range(N + 1)] for k in range(K + 1)] for n in range(1, N + 1): eggSolutions[1][n] = n for k in range(1, K + 1): eggSolutions[k][1] = ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: cache = {} return self.drop_iter(K, N, cache) def drop_iter(self, K, N, cache): if K == 1: return N if N == 0: return 0 if (K, N) in cache: return cache[K, N] res ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = range(N + 1) for k in range(2, K + 1): dp2 = [0] A = 1 for n in range(1, N + 1): costA = max(dp[A - 1], dp2[n - A]) while A < n: B = A + 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = list(range(1, N + 1)) for _ in range(K - 1): temp = [1] for j in range(1, N): temp.append(temp[-1] + dp[j - 1] + 1) dp = temp return [(i + 1) for i, x in enumerate(dp) if ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER VAR VAR FUNC_CALL VA...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [[sys.maxsize for i in range(N + 1)] for j in range(K + 1)] def DP(k, n): if k < 0 or n < 0: return 0 if k == 0: return 0 if k == 1: return n ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR ...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [i for i in range(N + 1)] for j in range(1, K): prev = dp.copy() m = 1 for i in range(2, N + 1): while m < i and dp[i - m] >= prev[m - 1] and dp[i - m - 1] >= prev[m]: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR V...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [([None] * K) for _ in range(N + 1)] for j in range(K): dp[0][j] = 0 for i in range(1, N + 1): dp[i][0] = i for j in range(1, K): dp[1][j] = 1 m = 1 for i ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: drops = 0 floors = [0] * (K + 1) while floors[K] < N: for eggs in range(K, 0, -1): floors[eggs] += 1 + floors[eggs - 1] drops += 1 return drops def superEggDrop(self, K: int, ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = list(range(N + 1)) for k in range(1, K): newdp = [0] opt = 1 for n in range(1, N + 1): tmp = max(dp[opt - 1], newdp[n - opt]) while opt < n and tmp > max(dp[opt], ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_O...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, eggs: int, floors: int) -> int: dp = [[(-1) for _ in range(floors + 1)] for _ in range(eggs + 1)] def search(eggs, floors): if eggs <= 0: return 0 elif eggs == 1: return floors elif floors <=...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: cachedSolutions = [[(-1) for i in range(N + 1)] for j in range(K + 1)] return self.getMinDrops(K, N, cachedSolutions) def getMinDrops(self, eggs, floors, cachedSolutions): if cachedSolutions[eggs][floors] > 0: r...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR ASS...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: memo = {} def dp(k, n): if (k, n) in memo: return memo[k, n] if k == 1: return n if n == 0: return 0 start = 1 end = n ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR N...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: results = [[None for _ in range(N + 1)] for _ in range(K + 1)] def dp(K, N): if K == 1: return N if N == 0: return 0 if results[K][N]: return results[K...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR ...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: res = [([0] * (N + 1)) for _ in range(K)] for i in range(N + 1): res[0][i] = i if K == 1: return N for k in range(1, K): j = 1 for i in range(1, N + 1): whi...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BI...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
import sys class Solution: def superEggDrop(self, K, N): dp = dict() def recursive(k, n): if k == 1: return n if n == 0: return 0 if (k, n) in dp: return dp[k, n] res = float("INF") l = 1 ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR V...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: mem = [[None for _ in range(N)] for _ in range(K - 1)] def dp(k, n, mem): if n <= 1 or k == 1: return n if mem[k - 2][n - 1] is None: l, r = 1, n while l + 1 < r: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NONE ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMB...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: self.memo = {} return self.cal_eggs(K, N) def find_that_floor(self, K, N): left, right = 1, N while left <= right: mid = (left + right) // 2 r1 = 1 + self.cal_eggs(K - 1, mid - 1) ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR ...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: memo = dict() def dp(K, N): if (K, N) in memo: return memo[K, N] if K == 1: return N if N == 0: return 0 res = sys.maxsize lo, ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VA...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dict_soln = {} return self.dp(K, N, dict_soln) def dp(self, k, n, dict_soln): if n == 0: return 0 if k == 0: return -1 if k == 1: return n if (k, n) in dict_soln: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BI...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: if K == 1: return N Rp = [i for i in range(0, N + 1)] R = [0] * (N + 1) R[1] = 1 k = 2 while k <= K: l1 = 0 for n in range(2, N + 1): if Rp[n - l1 - 1] ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: num_moves = [n for n in range(N + 1)] for k in range(2, K + 1): next_num_moves = [(0) for _ in range(N + 1)] floor = 1 for n in range(1, N + 1): safe_moves = next_num_moves[n - floor] ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BI...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution(object): def superEggDrop(self, K, N): def dfs(i, j): if i == 1: return j if j == 0: return 0 if j == 1: return 1 if (i, j) in d: return d[i, j] lo, hi = 0, j ...
CLASS_DEF VAR FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [([0] * (N + 1)) for _ in range(K + 1)] for n in range(1, N + 1): dp[1][n] = n for k in range(2, K + 1): dp[k][1] = 1 for k in range(2, K + 1): m = 1 for n in range(2,...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NU...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop1(self, K: int, N: int) -> int: memo = [([2**31 - 1] * (N + 1)) for _ in range(K + 1)] def dp(k, n): if k == 0: return 0 if k == 1: return n if n <= 1: return n if memo[k...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR VAR FO...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = {} def helper(K, N): if N <= 2: return N if K == 1: return N if (K, N) not in dp: l = 1 r = N while l + 1 < r: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR V...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop1(self, K: int, N: int) -> int: memo = [([2**31 - 1] * (N + 1)) for _ in range(K + 1)] def dp(k, n): if k == 0: return 0 if k == 1: return n if n <= 1: return n if memo[k...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR VAR FO...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [([0] * (N + 1)) for _ in range(K + 1)] for k in range(1, K + 1): for n in range(1, N + 1): if k == 1: dp[k][n] = n else: dp[k][n] = 1 + dp[k - 1][...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBE...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, e: int, f: int) -> int: self.cache = [([-1] * (f + 1)) for _ in range(e + 1)] return self.drop(e, f) def drop(self, e, f): if f == 0 or f == 1: return f if e == 1: return f if self.cache[e][f] != -1: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR ...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = list(range(N + 1)) for i in range(2, K + 1): k = 1 temp = [0] + [N + 1] * N for j in range(1, N + 1): while k < j + 1 and temp[j - k] > dp[k - 1]: k += 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VA...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = {} def num_moves(n, k): if (n, k) not in dp: if n == 0: ans = 0 elif k == 1: ans = n else: left = 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: def dp(m, k): if m <= 1 or k == 1: return m if (m, k) in memo: return memo[m, k] memo[m, k] = dp(m - 1, k - 1) + 1 + dp(m - 1, k) return memo[m, k] memo =...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL ...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: table = dict() def dp(K: int, N: int) -> int: if K == 1: return N if N <= 0: return 0 if (K, N) in table: return table[K, N] lo = 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL V...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def eggDrop(self, floors, eggs, m): if floors <= 1: return floors if eggs == 1: return floors if (floors, eggs) in m: return m[floors, eggs] l, h = 0, floors while l < h: mid = l + h >> 1 kelge, mele...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIG...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [[i for i in range(N + 1)]] for i in range(K - 1): dp.append([0] * (N + 1)) for i in range(1, K): k = 1 for j in range(1, N + 1): while k < j + 1 and dp[i][j - k] > dp[i -...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR BIN_OP ...
You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is identical in function, and if an egg breaks, you cannot drop it again. You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floo...
class Solution: def superEggDrop(self, K: int, N: int) -> int: @lru_cache(None) def helper(floors, eggs): if floors <= 0: return 0 if eggs == 1: return floors ans = floors low, high = 1, floors while low + ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR...
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble num...
n = int(input()) a = sorted([list(map(int, input().split())) for _ in range(n)]) a.append([a[-1][0] + 1, 0]) res = [10**15] * (n + 1) res[0] = a[0][1] ind = a[0][0] for i in range(n + 1): acc = 0 for j in range(i + 1, n + 1): res[j] = min(res[j], res[i] + acc + a[j][1]) acc = acc + a[j][0] - a[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NU...
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble num...
n = int(input()) arr = [] for i in range(n): p, c = map(int, input().split()) arr += [[p, c]] arr.sort() dp = [[10**100, 10**100] for i in range(n)] dp[0][0] = 10**100 dp[0][1] = arr[0][1] for i in range(1, n): dp[i][1] = min(dp[i - 1]) + arr[i][1] tot = arr[i][0] count = 1 for j in range(i - 1,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMB...
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
n = int(input()) a = [int(a) for a in input().split()] s = sum(a) if s % 3 != 0: print(0) else: s = s // 3 t = 0 ct = 0 res = 0 for i in range(n - 1): t += a[i] if t == 2 * s: res += ct if t == s: ct += 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR...
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
n = int(input()) arr = list(map(int, input().split())) psum = arr[:] for i in range(1, n): psum[i] += psum[i - 1] sums = psum[-1] set1 = set() set2 = set() if sums % 3 != 0: print(0) else: a = sums // 3 for i in range(n): if psum[i] == a: set1.add(i) if psum[i] == 2 * a and i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR...
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
n = int(input()) lis = list(map(int, input().split())) pre = [0] * (n + 1) for i in range(1, n + 1): pre[i] = pre[i - 1] + lis[i - 1] if pre[-1] % 3: print(0) else: s = pre[-1] // 3 ans = t = 0 for i in range(1, n): if pre[i] == 2 * s: ans += t if pre[i] == s: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER...
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
n = int(input()) ar = list(map(int, input().split())) s = sum(ar) if s % 3 != 0: print(0) else: s1, s2, t, v1, v2 = s // 3, s // 3 * 2, 0, 0, 0 for e in ar[:-1]: t += e if t == s2: v2 += v1 if t == s1: v1 += 1 print(v2)
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 IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR NUMBER VAR VAR IF VAR...
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
def solve(): n = int(input()) a = [] total = 0 for i in input().strip().split(): a.append(int(i)) for i in range(0, n): total = total + a[i] if total % 3 != 0 or n < 3: print(0) return part = total // 3 c = [0] * 100005 right = part * 2 right_sum =...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR NU...
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
from itertools import accumulate n = int(input()) a = list(map(int, input().split())) s = sum(a) p = s // 3 k = list(accumulate(a)) r = list(accumulate(x == 2 * p for x in reversed(k))) print( 0 if s % 3 else sum(r[-1 - i] - 2 * (not p) for i, x in enumerate(k[:-1]) if x == p) )
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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR ...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
import sys MOD = 998244353 def solve(): n = int(input()) ans = 0 arr = [] for i in range(n): a = list(input().split()) if len(a) == 2: arr.append(int(a[1])) else: arr.append(0) for cur in range(n): if arr[cur]: dp = [0] * (n + 1)...
IMPORT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASS...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
mod = 998244353 n = int(input()) A = [] ans = 0 for _ in range(n): s = input().split() A.append(0 if s[0] == "-" else int(s[1])) for i in range(n): if not A[i]: continue dp = [0] * (n + 1) dp[0] = 1 greater = 0 for j in range(n): if j == i: continue if j <...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUM...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
import sys N = int(input()) X = [] for i in range(N): a = input() if a[0] == "-": X.append(-1) else: X.append(int(a[2:])) Y = set(X) if -1 in Y: Y.discard(-1) Y = list(Y) DP = [([0] * (N + 1)) for i in range(N + 1)] ANS = 0 mod = 998244353 for i in range(N): if X[i] < 0: con...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP ...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
mod = 998244353 n = int(input()) a = [(0) for i in range(n + 1)] for i in range(1, n + 1): m = input().split() if m[0] == "+": a[i] = int(m[1]) ans = 0 for t in range(1, n + 1): if a[t] == 0: continue f = [[(0) for i in range(n + 2)] for j in range(n + 2)] f[0][0] = 1 for i in ra...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER I...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def L...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_D...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
n = int(input()) a = [] for _ in range(n): t = input() if t[0] == "+": a.append(int(t[2:])) else: a.append(0) ans = 0 for i in range(len(a)): d = [0] * n d[0] = 1 rb = 1 cf = 1 for j in range(i): if a[j]: if a[j] > a[i]: cf = cf * 2 % 9...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
def main(): mod = 998244353 n = int(input()) a = [] for i in range(n): t = input() if t[0] == "-": a.append(-1) else: a.append(int(t.split()[-1])) ans = 0 for i in range(n): if a[i] == -1: continue dp = [0] * (n + 1) ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP LIST N...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
mod = 998244353 N = 504 a = [] def process(): f = [[(0) for i in range(n + 2)] for j in range(n + 2)] res = 0 f[0][0] = 1 for i in range(1, n + 1): for j in range(i + 1): x = a[i - 1] f[i][j] = f[i - 1][j] if i == I: continue if x...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
import sys mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.readline N = int(input()) Q = [] for i in range(N): S = input().rstrip("\n") if S[0] == "+": _, t = S.split() Q.append(int(t) + 1e-05 * i) else: Q.append(-...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER V...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int, sys.stdin.readline().rstrip())) def S(): return sys.stdin.re...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL V...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
import sys input = lambda: sys.stdin.readline().rstrip() P = 998244353 N = int(input()) I = [] C = [0] c = 0 for _ in range(N): Z = input().split() if Z[0] == "-": I.append((-1, -1)) else: x = int(Z[1]) I.append((1, x)) c += 1 C.append(c) cc = C[-1] ans = 0 for i, (t, a)...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CAL...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
import sys tmp_tokens = [] def get_input(): global tmp_tokens while len(tmp_tokens) == 0: if sys.version_info.major == 3: tmp_tokens = input().split(" ") else: tmp_tokens = raw_input().split(" ") return tmp_tokens.pop(0) def parse(s): if "-" in s: ret...
IMPORT ASSIGN VAR LIST FUNC_DEF WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL VAR NUMBER FUNC_DEF IF STRING VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN...
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
n = int(input()) A = [] for i in range(n): s = input() if s[0] == "+": A.append((1, int(s[2:]))) else: A.append((0, 0)) answer = 0 m = 998244353 for k, elem in enumerate(A): if elem[0] == 0: continue D = [1] for j, el in enumerate(A): if k == j: contin...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER...
There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance b_{i} inclusive. The beacon itself is not destroyed however. Saitama ...
n = int(input()) lis = [0] * (1000000 + 2) dp = [0] * (1000000 + 2) for i in range(n): a, b = map(int, input().split()) lis[a] = b if lis[0] > 0: dp[0] = 1 for i in range(1, 1000000 + 1): if lis[i] == 0: dp[i] = dp[i - 1] elif lis[i] >= i: dp[i] = 1 else: dp[i] = dp[i - l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BI...
There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance b_{i} inclusive. The beacon itself is not destroyed however. Saitama ...
mod = 10**6 + 1 b = [0] * mod dp = [0] * mod maxi = 0 n = int(input()) for _ in range(n): a, po = map(int, input().split()) b[a] = po if b[0] > 0: dp[0] = 1 for i in range(1, mod): if b[i] == 0: dp[i] = dp[i - 1] elif b[i] >= i: dp[i] = 1 else: dp[i] = dp[i - b[i] - 1] + ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER F...
There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance b_{i} inclusive. The beacon itself is not destroyed however. Saitama ...
N = int(input()) d = [(0) for i in range(1000001)] Memo = [(0) for i in range(1000001)] max_pos = 0 for i in range(N): subList = input().split() index = int(subList[0]) d[index] = int(subList[1]) max_pos = max(index, max_pos) if d[0] != 0: Memo[0] = 1 result = N result = min(result, N - Memo[0]) for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ...
There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance b_{i} inclusive. The beacon itself is not destroyed however. Saitama ...
read = lambda: list(map(int, input().split())) n = int(input()) p = sorted([tuple(read()) for i in range(n)]) a = [0] * (n + 1) b = [0] * (n + 1) for i in range(1, n + 1): a[i], b[i] = p[i - 1] a[0] = int(-10000000.0) dp = [0] * (n + 1) for i in range(1, n + 1): L = 0 R = n + 1 while R - L > 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM...
There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance b_{i} inclusive. The beacon itself is not destroyed however. Saitama ...
import sys MAX_X = 1000 * 1000 + 10 def main(): n = int(sys.stdin.readline()) arr = [0] * MAX_X cnt = [0] * MAX_X dp = [0] * MAX_X for i in range(n): x, c = list(map(int, sys.stdin.readline().split())) arr[x + 1] = c for i in range(1, MAX_X): cnt[i] += cnt[i - 1] + (ar...
IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VA...
There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance b_{i} inclusive. The beacon itself is not destroyed however. Saitama ...
def main(): n = int(input()) bb = [0] * 1000001 for _ in range(n): a, b = list(map(int, input().split())) bb[a] = b a = 0 for i, b in enumerate(bb): if b: a = bb[i - b - 1] + 1 if i > b else 1 bb[i] = a print(n - max(bb)) def __starting_point(): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBE...
There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance b_{i} inclusive. The beacon itself is not destroyed however. Saitama ...
n = int(input()) bb = [0] * 1000001 for _ in range(n): a, b = map(int, input().split()) bb[a] = b a = 0 for i, b in enumerate(bb): if b: if i > b: a = bb[i - b - 1] + 1 else: a = 1 bb[i] = a print(n - max(bb))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ...
A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk. In the initial mome...
def check(mid, p, f): ptr = 0 for x in p: From = x To = x while ptr < len(f): From = min(From, f[ptr]) To = max(To, f[ptr]) need = To - From + min(To - x, x - From) if need > mid: break ptr += 1 if ptr ==...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMB...
A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk. In the initial mome...
from sys import stdin, stdout n = int(stdin.readline()) s = stdin.readline().strip() mins = [] packs = [] for i in range(len(s)): if s[i] == "*": mins.append(i) elif s[i] == "P": packs.append(i) l, r = -1, 2 * len(s) + 1 while r - l > 1: m = l + r >> 1 test1 = mins[:] test2 = packs[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUM...
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
n = int(input()) s = list(map(str, input().strip())) cnta = 0 cntb = 0 ans = 0 for i, v in enumerate(s): if v == "A": ans += cnta - (cntb and cntb < cnta) cnta = i + 1 else: ans += cntb - (cnta and cnta < cntb) cntb = i + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR...
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
n = int(input()) line = input() left_A = list() left_A.append(-1) left_A.append(-1) left_B = list() left_B.append(-1) left_B.append(-1) counts = list() i = 0 while i < n: counts.append(0) i = i + 1 if line[0] == "A": left_A[1] = 0 i = 1 if line[1] == line[0]: counts[1] = 1 left_A[0] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP V...
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
import sys def I(): return sys.stdin.readline().rstrip() n = int(I()) s = I() l = [] cc = "c" for c in s: if c == cc: l[-1] += 1 else: l.append(1) cc = c ans = n * (n - 1) // 2 for i in range(len(l)): if i > 0: ans -= l[i] - 1 if i < len(l) - 1: ans -= l[i] pr...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
n = int(input()) s = input() gh = 1 cn = s[0] cvb = 0 for i in range(1, n): if s[i] != cn: cvb += gh gh = 1 else: gh += 1 cn = s[i] gh = 1 s = list(reversed(s)) cn = s[0] for i in range(1, n): if s[i] != cn: cvb += gh gh = 1 else: gh += 1 cn = s[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUN...
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
n = int(input()) s = input() def bin_sear_pos(j, arr): initial = 0 final = len(arr) - 1 middle = (initial + final) // 2 if arr[final] <= j: return final + 1 elif arr[initial] > j: return initial while arr[middle] != j and (arr[middle] > j or arr[middle + 1] <= j): if ar...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR WHILE VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VA...
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
import sys input = sys.stdin.readline n = int(input()) s = input() res = n * (n - 1) // 2 for x in range(2): cur = 1 for i in range(1, n): if s[i] == s[i - 1]: cur += 1 else: res -= cur - x cur = 1 s = s[::-1][1:] print(res)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMB...
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
n = int(input()) st = input() + "C" add = 1 sum = [] count = 0 for i in range(n): if st[i] == st[i + 1]: add += 1 else: sum.append(add) add = 1 count += 1 final = [(0) for i in range(count + 1)] i = count - 1 pre = 0 while i >= 0: pre += sum[i] final[i] = pre i -= 1 a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN...