description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given $n$ lengths of segments that need to be placed on an infinite axis with coordinates. The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate $0$. Let's call this endpoint the "start" of the first segment and let's call its "end" as that endpoint that is not ...
import sys input = sys.stdin.readline inf = float("inf") def solve(A, n): mx = max(A) * 2 + 1 dp = [([inf] * mx) for _ in range(2)] dp[0][0] = 0 for i, a in enumerate(A): b = i % 2 dp[b ^ 1] = [inf] * mx for L in range(mx): nx = dp[b][L] + max(0, a - L) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP LIST VAR VAR FOR ...
You are given $n$ lengths of segments that need to be placed on an infinite axis with coordinates. The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate $0$. Let's call this endpoint the "start" of the first segment and let's call its "end" as that endpoint that is not ...
import sys readline = sys.stdin.readline def Bisect_Int(ok, ng, is_ok): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok T = int(readline()) for t in range(T): N = int(readline()) A = list(map(int, readline...
IMPORT ASSIGN VAR VAR FUNC_DEF WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VA...
You are given $n$ lengths of segments that need to be placed on an infinite axis with coordinates. The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate $0$. Let's call this endpoint the "start" of the first segment and let's call its "end" as that endpoint that is not ...
from sys import stdin def solve_dp(N, nums): MAX = max(nums) * 2 + 1 cur = [0] * MAX for d in nums: nxt = [MAX] * MAX for l, r in enumerate(cur): if l + d < MAX: nxt[l + d] = min(nxt[l + d], max(r - d, 0)) if r + d < MAX: nxt[r + d] =...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN V...
You are given $n$ lengths of segments that need to be placed on an infinite axis with coordinates. The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate $0$. Let's call this endpoint the "start" of the first segment and let's call its "end" as that endpoint that is not ...
from sys import stdin def solve_linh(N, nums): MAX = max(nums) * 2 + 1 cur = [MAX] * MAX cur[0] = 0 for d in nums: nxt = [MAX] * MAX for l, r in enumerate(cur): if r >= MAX: continue for ll, rr in [(l, r), (r, l)]: nl = ll + d ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR VAR LIST VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR V...
You are given $n$ lengths of segments that need to be placed on an infinite axis with coordinates. The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate $0$. Let's call this endpoint the "start" of the first segment and let's call its "end" as that endpoint that is not ...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) dp = [([2100] * 2100) for _ in range(n)] dp[0][a[0]] = a[0] for i in range(1, n): for j in range(2100): nj = max(j - a[i], 0) dp[i][nj] = min(dp[i...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FU...
Given an array A of N elements, find the number of distinct possible sums that can be obtained by taking any number of elements from the array and adding them. Note that 0 can always be obtained by taking none. First line of the input contains number of test cases T. Each test case has two lines. First line has N, t...
def possibleSums(n, elems): sums = sum(elems) dp = [([False] * (sums + 1)) for _ in range(n)] dp[0][0] = True dp[0][elems[0]] = True for i in range(1, n): for j in range(sums + 1): dp[i][j] = dp[i - 1][j] or ( dp[i - 1][j - elems[i]] if j - elems[i] >= 0 else Fals...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ...
Given an array A of N elements, find the number of distinct possible sums that can be obtained by taking any number of elements from the array and adding them. Note that 0 can always be obtained by taking none. First line of the input contains number of test cases T. Each test case has two lines. First line has N, t...
import sys N = int(eval(input())) res = [] def check(nums): nums1 = set() nums1.add(0) for i in nums: nums2 = nums1.copy() for j in nums1: nums2.add(i + j) nums1 = nums2.copy() return len(nums1) for i in range(N): tot = int(input()) nums = [int(i) for i i...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ...
Given an array A of N elements, find the number of distinct possible sums that can be obtained by taking any number of elements from the array and adding them. Note that 0 can always be obtained by taking none. First line of the input contains number of test cases T. Each test case has two lines. First line has N, t...
tc = int(input()) while tc > 0: n = int(input()) num = [] xx = input().split(" ") sum = 0 for i in range(0, n): num.append(int(xx[i])) sum = sum + num[i] m = [] for i in range(0, sum + 1): m.append(0) m[0] = 1 for i in range(0, n): for j in range(sum, ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ...
Given an array A of N elements, find the number of distinct possible sums that can be obtained by taking any number of elements from the array and adding them. Note that 0 can always be obtained by taking none. First line of the input contains number of test cases T. Each test case has two lines. First line has N, t...
num_tests = eval(input()) for tests in range(num_tests): sums = set([0]) num_vars = eval(input()) numbers_lst = [int(i) for i in input().split()] for num in numbers_lst: sums_lst = list(sums) new_sums = [(num + i) for i in sums_lst] sums.update(new_sums) print(len(sums))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
try: for test in range(int(input())): man, axe = map(int, input().split()) ls = [0] * (axe + 1) ls[1] = 1 for i in range(2, axe + 1): t = man % i if t == 0: t = i ls[i] = ls[i - 1] if ls[i] >= t: ls[i] +=...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER I...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) for _ in range(t): m, x = map(int, input().split()) lst = [k for k in range(x + 1)] lst[1] = 1 ans = [] for i in range(2, x + 1): calc = m % i if calc == 0: calc = i lst[i] = lst[i - 1] if lst[i] >= calc: lst[i] += 1 lst.po...
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 FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSI...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, x = map(int, input().split()) win = [1] * x for n in range(1, x): if m % (n + 1) == 0: f = n + 1 else: f = m % (n + 1) if f > win[n - 1]: win[n] = win[n - 1] else: win[n] = win[n - 1] + 1 pri...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VA...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) for _ in range(t): m, x = map(int, input().split()) arr = [1] * x m = m - 1 for i in range(1, x): a = m % (i + 1) + 1 if arr[i - 1] < a: arr[i] = arr[i - 1] else: arr[i] = arr[i - 1] + 1 for i in arr: print(i, end=" ") prin...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
try: for _ in range(int(input())): m, x = map(int, input().split()) l = [(0) for _ in range(x)] l[0] = 1 for i in range(1, x): temp = (m - 1) % (i + 1) + 1 if l[i - 1] < temp: l[i] = l[i - 1] else: l[i] = l[i - 1] + ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, x = map(int, input().split()) lst = [] lst.append(1) for i in range(1, x): x = (m - 1) % (i + 1) + 1 if lst[i - 1] < x: lst.append(lst[i - 1]) else: lst.append(lst[i - 1] + 1) print(*lst, sep=" ")
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 LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): mm, xx = map(int, input().split()) aa = [0, 1] + [(0) for ii in range(xx - 1)] for ii in range(2, xx + 1): aa[ii] = aa[ii - 1] + (aa[ii - 1] >= (mm % ii if mm % ii else ii)) print(*[aa[ii + 1] for ii in range(xx)])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR 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 BIN_OP VAR VAR BIN_O...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, k = map(int, input().split()) last = [] for i in range(k): if i == 0: last.append(0) continue last.append((m % (i + 1) - 1) % (i + 1)) out = [0] for i in last[1:]: if len(out) >= m - 1: out.append(out[-1]) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR NUMBER IF...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
import sys sys.setrecursionlimit(10**6) def jos_m1(n: int, m: int) -> int: if n == 1: print(1, end=" ") return 1 if (m - 1) % n == 0: z = (jos_m1(n - 1, m) + 1) % (n + 1) print(z, end=" ") return z else: x = jos_m1(n - 1, m) if x <= (m - 1) % n: ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING RETURN NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) for i in range(t): m, x = map(int, input().split()) ans = [0, 1] + [0] * (x - 1) for j in range(2, x + 1): c = m % j if m % j else j ans[j] = ans[j - 1] + (ans[j - 1] >= c) print(*[ans[j] for j in range(1, x + 1)])
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 BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
import sys sys.setrecursionlimit(10000000) def jos(n, k): if n == 1: print(1, end=" ") return 1 a = jos(n - 1, k) if (k - 1) % n == 0: print(a + 1, end=" ") return a + 1 if a <= (k - 1) % n: print(a, end=" ") return a else: print(a + 1, end=...
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING RETURN BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STR...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
def sol(m, n): arr = [1] + [0] * (n - 1) for i in range(1, n): pos = m % (i + 1) + 1 if arr[i - 1] < pos: arr[i] = arr[i - 1] else: arr[i] = arr[i - 1] + 1 return arr t = int(input()) for tc in range(0, t): m, n = map(int, input().split()) m -= 1 ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) def solve(m, x): dp = [0, 1] for i in range(2, x + 1): md = (m - 1) % i + 1 if md > dp[i - 1]: dp.append(dp[i - 1]) else: dp.append(dp[i - 1] + 1) return dp[1:] for _ in range(t): m, x = list(map(int, input().split())) ans = solve(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR NUMBE...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, x = [int(i) for i in input().split()] m = m - 1 a = [i for i in range(0, x)] if m == 0: for i in range(1, x + 1): print(i, end=" ") print("") if m == 1: for i in range(1, x + 1): print(1, end=" ") print("") ...
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 BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR V...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for t in range(int(input())): m, n = map(int, input().split()) print(1) l = 0 for i in range(1, n): a = (m - 1) % (i + 1) if l >= a: l = l + 1 print(l + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
import sys input = sys.stdin.readline output = sys.stdout.write for _ in range(int(input())): m, x = map(int, input().split()) arr = [0] * x arr[0] = 1 a1 = 0 m = m - 1 for i in range(1, x): a1 = m % (i + 1) + 1 if arr[i - 1] < a1: arr[i] = arr[i - 1] else: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP V...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for t in range(int(input())): L = [1] M, X = list(map(int, input().split())) for i in range(2, X + 1): k = M % i if k == 0: k = i if k > L[-1]: L.append(L[-1]) else: L.append(L[-1] + 1) L = list(map(str, L)) print(" ".join(L))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP ...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) while t > 0: m, x = map(int, input().split()) m -= 1 a = [0] * x a[0] = 1 for i in range(1, x): temp = m % (i + 1) + 1 if a[i - 1] < temp: a[i] = a[i - 1] else: a[i] = a[i - 1] + 1 for i in range(x): print(a[i], end=" ") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BI...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, x = map(int, input().split()) arr = [(0) for _ in range(x + 1)] arr[1] = 1 if x > 1: for i in range(2, x + 1): if m % i != 0: temp = m % i else: temp = x if temp > arr[i - 1]: arr...
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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR ...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) while t > 0: t -= 1 m, x = map(int, input().split()) m -= 1 a = [0] * x a[0] = 1 ps = 0 for i in range(1, x): ps = m % (i + 1) + 1 a[i] = a[i - 1] * 1 if a[i - 1] >= ps: a[i] += 1 print(*a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
def get(num, m): if m % num == 0: return num return m % num for _ in range(int(input())): m, x = map(int, input().split()) ans = [1] * x for i in range(1, x): ans[i] = ans[i - 1] if get(i + 1, m) > ans[i - 1] else ans[i - 1] + 1 print(*ans)
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BI...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) for i in range(t): w = list(map(int, input().split())) m, x = w[0], w[1] a = [(0) for r in range(x + 1)] a[1] = 1 if w[1] > 1: for k in range(2, x + 1, 1): q = 0 if m % k == 0: q = x else: q = m % k ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMB...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, n = map(int, input().split()) m = m - 1 arr = [] for i in range(1, n + 1): if not arr: arr.append(1) elif i >= m + 1: arr.append(arr[-1]) else: idx = arr[-1] l = m % i + 1 if l <= idx: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR ...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) for _ in range(t): m, n = map(int, input().split()) a = [0] * (n + 1) a[1] = 1 for i in range(2, n + 1): if m % i != 0: idx = m % i else: idx = m if a[i - 1] < idx: a[i] = a[i - 1] else: a[i] = a[i - 1] + 1 ...
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR BIN_O...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for i in range(int(input())): m, x = map(int, input().split()) l = ["1"] a = 1 for j in range(2, x + 1): if j > m - 1: l.append(str(a)) else: r = (m - 1) % j if r < a: a += 1 l.append(str(a)) print(" ".join(l))
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 LIST STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER E...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) for _ in range(t): m, x = map(int, input().split()) arr = [] for i in range(1, x + 1): arr.append(i) dp = [0] * (x + 1) dp[1] = 0 print(arr[dp[1]], end=" ") for i in range(2, x + 1): rem = (m - 1) % i if rem <= dp[i - 1]: print(arr[dp[i - ...
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 LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER STRIN...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
x = int(input()) for i in range(x): m, x = list(map(int, input().split())) print(1, end=" ") y = 1 for k in range(2, x + 1): z = m % k if z == 0: print(y, end=" ") elif z <= y and z != 0: print(y + 1, end=" ") y += 1 else: p...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR VAR VAR N...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, x = [int(i) for i in input().split()] m -= 1 i, p = 1, 1 print(p, end=" ") while i < x: val = m % (i + 1) + 1 if val > p: print(p, end=" ") else: p = p + 1 print(p, end=" ") i += 1 print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER E...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, n = map(int, input().split()) d = [0] * (n + 1) d[1] = 0 for i in range(2, n + 1): z = (m - 1) % i if z <= d[i - 1]: d[i] = d[i - 1] + 1 else: d[i] = d[i - 1] x = "" for a in range(1, n + 1): x += str(d[a] +...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VA...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): m, x = map(int, input().split()) win = [1] print(1, end=" ") for i in range(1, x): if win[i - 1] >= m % (i + 1) and m % (i + 1) != 0: print(win[i - 1] + 1, end=" ") win.append(win[i - 1] + 1) else: print(win[i - 1], end=" ...
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 LIST NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
for _ in range(int(input())): [m, x] = [int(j) for j in input().split()] ps = 0 l = [] m = m - 1 for i in range(x): l.append("0") l[0] = 1 for i in range(1, x): ps = m % (i + 1) + 1 if l[i - 1] < ps: l[i] = l[i - 1] else: l[i] = l[i - 1...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BI...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
x = int(input("")) li = [] for i in range(x): y = input("") y = list(map(int, y.split())) li.append(y) for l in li: m = l[0] - 1 x = l[1] counter = 1 while counter != x + 1: if counter == 1: print(1, end=" ") counter = counter + 1 elif counter == 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF V...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
def gl(): return [int(x) for x in input().split()] for _ in range(int(input())): m, x = gl() m -= 1 l = [1] * x for i in range(1, x): l[i] = l[i - 1] if l[i - 1] < m % (i + 1) + 1 else l[i - 1] + 1 print(*l)
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
t = int(input()) for i in range(t): m, x = map(int, input().split()) l = [1] * (x + 1) print(l[1], end=" ") for i in range(2, x + 1): if m % i == 0: x = i else: x = m % i l[i] = l[i - 1] if l[i] >= x: l[i] += 1 print(l[i], end="...
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ...
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N-1 times. The person with the lowest index holds a coin. Then, the coin then moves to the next person clockwise M-1 times. Then, the p...
from sys import stdin input = stdin.readline def solve(M, X): winner = [0] * (X + 1) for N in range(2, X + 1): if winner[N - 1] <= (M - 1) % N - 1: winner[N] = winner[N - 1] else: winner[N] = winner[N - 1] + 1 for i in range(X + 1): winner[i] += 1 retur...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR V...
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
import sys mod = 1000000007 eps = 10**-9 inf = 1000000000.0 def main(): import sys input = sys.stdin.readline N = int(input()) A = [] B = [] for _ in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) vmax = sum(A) dp = [[-inf] * (vmax + 1)] ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUN...
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
n = int(input()) p = sorted( [tuple(map(int, input().split())) for _ in range(n)], key=lambda x: (x[0], -x[1]) ) dic = [([-1] * 10001) for _ in range(n + 1)] dic[0][0] = 0 l, r, s = [0], [0], 0 for i in range(n): dc, dv = p[i] s += dv for k in range(i, -1, -1): m = -1 for c in range(r[k]...
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 VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER LIST NUMBER NUMBER F...
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
n = int(input()) dp = [([-(10**8)] * 10002) for _ in range(n + 1)] dp[0][0] = 0 total = 0 for i in range(n): a, b = map(int, input().split()) total += b for k in range(n - 1, -1, -1): for c in range(10001 - a, -1, -1): dp[k + 1][c + a] = max(dp[k + 1][c + a], dp[k][c] + b) ans = [(0) for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER...
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
from sys import stdin, stdout def glass_half_spilled(n, ab_a, a_a, sa, sb): dp = [[(-1) for _ in range(sa + 1)] for _ in range(n + 1)] dp[0][0] = 0 for i in range(1, n + 1): for k in range(i, 0, -1): for A in range(a_a[i], -1, -1): if dp[k - 1][A - ab_a[i - 1][0]] == -1...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ...
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
n = int(input()) inf = 10**8 dp = [] for k in range(n + 1): dp.append([-inf] * 10005) dp[0][0] = 0 w = 0 for _ in range(k): a, b = map(int, input().split()) w += b for k in range(n - 1, -1, -1): for i in range(10005 - a): dp[k + 1][i + a] = max(dp[k + 1][i + a], dp[k][i] + b) out = [...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR FOR VAR FU...
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
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 MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
n = int(input()) k = [] dics = [] for _ in range(n): a, b = map(int, input().split()) k.append([a, b]) dics.append({}) sums = 0 for i in range(n): sums += k[i][1] for i in range(n): r1 = k[i][0] r2 = k[i][1] for j in range(n - 1, -1, -1): for t in dics[j]: if t + r1 in di...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NU...
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
import sys def oneLineArrayPrint(arr): print(" ".join([str(x) for x in arr])) input = sys.stdin.buffer.readline n = int(input()) a = [] b = [] for _ in range(n): aa, bb = [int(x) for x in input().split()] a.append(aa) b.append(bb) total = sum(b) MAXCAP = sum(a) dp = [[(-float("inf")) for _ in range(...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VA...
You are given an r rows and c cols matrix grid representing a field of chocolates where grid[i][j] represents the number of chocolates that you can collect from the (i, j) cell. You have two robots that can collect chocolates for you: Robot #1 is located at the top-left corner (0, 0), and Robot #2 is located at the top...
class Solution: def solve(self, n, m, grid): dictio = {(1, -1), (1, 0), (1, 1)} m = len(grid) n = len(grid[0]) dp = {} def f(i, j, r, c): if (i, j, r, c) in dp: return dp[i, j, r, c] if i == m - 1: if j == c: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR VAR VAR RETURN VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR NUMBER VAR RETURN BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF VAR...
You are given an r rows and c cols matrix grid representing a field of chocolates where grid[i][j] represents the number of chocolates that you can collect from the (i, j) cell. You have two robots that can collect chocolates for you: Robot #1 is located at the top-left corner (0, 0), and Robot #2 is located at the top...
class Solution: def solve(self, n, m, grid): dp = [[[(-1) for _ in range(m)] for _ in range(m)] for _ in range(n)] def helper(i, j1, j2): if j1 < 0 or j1 >= m or j2 < 0 or j2 >= m: return -1000000000.0 if i == n - 1: if j1 == j2: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR VAR VAR RETURN BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR ...
You are given an r rows and c cols matrix grid representing a field of chocolates where grid[i][j] represents the number of chocolates that you can collect from the (i, j) cell. You have two robots that can collect chocolates for you: Robot #1 is located at the top-left corner (0, 0), and Robot #2 is located at the top...
class Solution: def solve(self, n, m, grid): dp = {} def recursion(row, c1, c2): if c1 < 0 or c1 >= m or c2 < 0 or c2 >= m: return -(10**9) if row == n - 1: if c1 == c2: return grid[row][c1] return grid[row...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN BIN_OP NUMBER NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR VAR VAR RETURN BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSI...
You are given an r rows and c cols matrix grid representing a field of chocolates where grid[i][j] represents the number of chocolates that you can collect from the (i, j) cell. You have two robots that can collect chocolates for you: Robot #1 is located at the top-left corner (0, 0), and Robot #2 is located at the top...
class Solution: def solve(self, n, m, grid): memo = {} def dp(i, j1, j2): if j1 >= m or j1 < 0 or j2 >= m or j2 < 0: return 0 k = i, j1, j2 if k in memo: return memo[k] ans = grid[i][j1] if j2 != j1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUM...
You are given an r rows and c cols matrix grid representing a field of chocolates where grid[i][j] represents the number of chocolates that you can collect from the (i, j) cell. You have two robots that can collect chocolates for you: Robot #1 is located at the top-left corner (0, 0), and Robot #2 is located at the top...
class Solution: def solve(self, n, m, grid): dp = [[[(-1) for j in range(m)] for i in range(m)] for k in range(n)] n = len(grid) m = len(grid[0]) return self.func(0, 0, m - 1, n, m, grid, dp) def func(self, i, j1, j2, n, m, grid, dp): if j1 < 0 or j1 >= m or j2 < 0 or j...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR STRING IF VA...
You are given an r rows and c cols matrix grid representing a field of chocolates where grid[i][j] represents the number of chocolates that you can collect from the (i, j) cell. You have two robots that can collect chocolates for you: Robot #1 is located at the top-left corner (0, 0), and Robot #2 is located at the top...
class Solution: def dfs(self, ind, j1, j2, grid, N, M, dp): if ind >= N: return 0 if dp[ind][j1][j2] != -1: return dp[ind][j1][j2] ans = 0 for i in [j1 - 1, j1, j1 + 1]: for j in [j2 - 1, j2, j2 + 1]: if i < M and i >= 0 and j < M ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUN...
You are given an r rows and c cols matrix grid representing a field of chocolates where grid[i][j] represents the number of chocolates that you can collect from the (i, j) cell. You have two robots that can collect chocolates for you: Robot #1 is located at the top-left corner (0, 0), and Robot #2 is located at the top...
class Solution: def helper(self, n, m, grid, dp, i, j1, j2): if i < 0 or j1 < 0 or j2 < 0 or i >= n or j1 >= m or j2 >= m: return float("-inf") if i == n - 1: if j1 == j2: return grid[i][j1] else: return grid[i][j1] + grid[i][j2] ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR VAR VAR RETURN BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR...
You are given an r rows and c cols matrix grid representing a field of chocolates where grid[i][j] represents the number of chocolates that you can collect from the (i, j) cell. You have two robots that can collect chocolates for you: Robot #1 is located at the top-left corner (0, 0), and Robot #2 is located at the top...
class Solution: def solve(self, n, m, A): dp = [([0] * m) for _ in range(m)] dp[0][m - 1] = A[0][0] + A[0][-1] for i in range(1, n): dpn = [([0] * m) for _ in range(m)] for j in range(m): for k in range(m): if j > i or m - k - 1 > ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP ...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): dp = {} n = len(s) def helper(ind, sum): if ind == n: return 1 if (ind, sum) in dp: return dp[ind, sum] curr_sum = 0 ans = 0 for i in range(ind, n): ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VA...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): n = len(s) maxl = 100 dp = [[(-1) for i in range(9 * maxl + 1)] for i in range(maxl)] def helper(p, psum): if p == n: return 1 if dp[p][psum] != -1: return dp[p][psum] ans =...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR V...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def dfs(self, s, index, prevSum): if index >= len(s): return 1 if (index, prevSum) in self.memo: return self.memo[index, prevSum] currentSum = ans = 0 for i in range(index, len(s)): currentSum += int(s[i]) if currentSum...
CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT RETURN FUNC_CALL VAR V...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
def f(idx, summ, dp, S): N = len(S) if idx == N: return 1 if dp[idx][summ] != -1: return dp[idx][summ] dp[idx][summ] = 0 ans = 0 tempsumm = 0 for i in range(idx, N): tempsumm += int(S[i]) if tempsumm >= summ: ans += f(i + 1, tempsumm, dp, S) dp...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR CLASS...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): def task(n, i, ism, s, dp): if i == n: return 1 if dp[i][ism] != -1: return dp[i][ism] cm = 0 ans = 0 for j in range(i, n): cm += int(s[j]) i...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): def is_possible(i, prev, dp): if i == n: return 1 if dp[i][prev] != -1: return dp[i][prev] res = 0 for j in range(i, n): summ = pre_sum[j + 1] - pre_sum[i] ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR L...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): sum2 = 0 n = len(s) for i in s: sum2 += int(i) dp = [[(-1) for i in range(sum2 + 1)] for i in range(n + 1)] return self.group(n, 0, 0, s, dp) def group(self, n, index, sum1, s, dp): if index == n: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL 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 NUMBER NUMBER VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN V...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): n = len(s) y = 0 for i in range(n): y += int(s[i]) dp = [] for i in range(n + 1): x = [] for j in range(y + 1): x.append(-1) dp.append(x) def solve(i, sm): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN ...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, num): dp = {} def count_parts(pre_sum, num_lis): if not num_lis: return 1 if (num_lis, pre_sum) in dp: return dp[num_lis, pre_sum] cur_sum = 0 count = 0 for i in range(l...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL V...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def solve(self, s, i, prev, dp): n = len(s) if i == n: return 1 elif dp[i][prev] != -1: return dp[i][prev] cur = res = 0 for j in range(i, n): cur += int(s[j]) if cur >= prev: res += self.solve(s...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CA...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): dp = [[(-1) for _ in range(9 * len(s) + 1)] for _ in range(len(s))] def rec(i, sm): if i == len(s): return 1 if dp[i][sm] != -1: return dp[i][sm] dp[i][sm] = 0 sum_ = 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FU...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): n = len(s) dp = [[(-1) for i in range(9 * n)] for j in range(n)] return self.solve(s, 0, 0, dp) def solve(self, S, index, sum_, dp): if index == len(S): return 1 if dp[index][sum_] != -1: return dp[index][...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FU...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def solve(self, dp, s, n, Sum, idx): if idx >= n: return 1 if dp[idx][Sum] != -1: return dp[idx][Sum] currSum = 0 res = 0 for i in range(idx, n): currSum += int(s[i]) if currSum >= Sum: res += se...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL V...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def sumi(self, s): i = 0 if s != "": for c in s: i += int(c) return i def solve(self, i, j, s, c): if i >= j: return 0 for k in range(i, j): left = self.solve(i, k, s, c) sl = self.sumi(left...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
def rec(s, i, presum, dp): if i == len(s): return 1 elif dp[i][presum] != -1: return dp[i][presum] cursum = 0 res = 0 for j in range(i, len(s)): cursum += int(s[j]) if cursum >= presum: res += rec(s, j + 1, cursum, dp) dp[i][presum] = res return dp...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR CLASS_DEF FUNC_DEF ASSIG...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): arr = [int(ch) for ch in s] n, tot = len(s), sum(arr) dp = [([-1] * (tot + 1)) for _ in range(n)] return self.find_count(arr, 0, len(s), 0, dp) def find_count(self, arr, i, n, prev, dp): if i == n: return 1 el...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN ...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): def helper(i, s): if dp[i][s] == -1: cs = 0 res = 0 for j in range(i, n): cs += l[j] if cs >= s: res += helper(j + 1, cs) dp[...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSI...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def countSubgroups(self, n, position, num, previous_sum, dp): if position == n: return 1 if dp[position][previous_sum] != -1: return dp[position][previous_sum] dp[position][previous_sum] = 0 s = 0 res = 0 for i in range(positio...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR ...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): dp = {} def countGroup(position, pre_sum, length, s): if position == length: return 1 if (position, pre_sum) in dp: return dp[position, pre_sum] res = 0 sum = 0 for ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR RETURN...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): dp = [([-1] * len(s)) for _ in range(1000)] def rec(i, su): if i >= len(s): return 1 if dp[su][i] != -1: return dp[su][i] sum = 0 c = 0 for j in range(i, len(s)): ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
[7, -1, -1, -1] [-1, 4, -1, -1] [-1, 2, 1, -1] [-1, 1, 1, 1] class Solution: def TotalCount(self, s): def haha(ind, sumi, s, dp, n): if ind == n: return 1 if dp[ind][sumi] != -1: return dp[ind][sumi] c, ans = 0, 0 for i in r...
EXPR LIST NUMBER NUMBER NUMBER NUMBER EXPR LIST NUMBER NUMBER NUMBER NUMBER EXPR LIST NUMBER NUMBER NUMBER NUMBER EXPR LIST NUMBER NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL V...
Given a string str consisting of digits, one may group these digits into sub-groups while maintaining their original order. The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on ...
class Solution: def TotalCount(self, s): n = len(s) sums = 0 for i in s: sums += int(i) dp = [[(-1) for _ in range(sums + 1)] for _ in range(n)] def fun(i, pre): nonlocal n if i == n: return 1 if dp[i][pre] != ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = map(int, input().split()) dp = [[([1, 0] if i and not j else [0, 0]) for j in range(b + 2)] for i in range(w + 2)] for i in range(1, w + 1): for j in range(1, b + 1): dp[i][j][0] = (i + j * dp[i][j - 1][1]) / (i + j) dp[i][j][1] = ( j * ((j - 1) * dp[i][j - 2][0] + i *...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER LIST NUMBER NUMBER 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP BIN_OP ...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
def f(W, B): n = B - W + 1 d, p, t, r = [0] * B, [0] * B, [0] * B, [0] * B p[0], r[0], p[1] = 1, 1, 0.5 for b in range(2, n + 1): d[b] = (t[b - 1] + p[b - 2] * (b - 1)) / (1 + b) p[b] = (1 + d[b - 1] * b) / (1 + b) r[0], t[0] = 1, 1 t, r, p = p, t, r for w in range(2, W): ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMB...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = [int(i) for i in input().split()] a = [[(0) for i in range(w + 1)] for j in range(b + 1)] def cnt(w, b): if w <= 0: return 0 if b <= 0: return 1 if a[b][w] != 0: return a[b][w] c = w / (w + b) if w + b > 2: wjump = cnt(w - 1, b - 2) bjump = cnt(w, b -...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL 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 NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER A...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
import sys sys.setrecursionlimit(10**6) w, b = map(int, input().split()) w += 1 b += 1 pr_win = [[None for k in range(b)] for k in range(w)] dr_win = [[None for k in range(b)] for k in range(w)] def f(w0, b0, princess): if w0 < 0 or b0 < 0: return 0 if w0 == 0 and b0 == 0: return 0 if b0 ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER R...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
dp = {} def prob(w, b): if (w, b) in dp: return dp[w, b] if w == 0 and b == 0: return 0 if b == 0: return 1 if w == 0: return 0 if b == 1: ans = w / (w + b) dp[w, b] = ans return ans if b == 2: ans = w / (w + 2) + 2 / (w + 2) * 1 ...
ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = map(float, input().split()) dic = {} def fun(w, b): if dic.get((w, b)): return dic[w, b] if w > 0 and b > 1: temp = b / (b + w) * (b - 1) / (w + b - 1) res = w / (w + b) + temp * ( w / (w + b - 2) * fun(w - 1, b - 2) + (b - 2) / (w + b - 2) * fun(w, b - 3) ) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP BI...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = map(int, input().split(" ")) if w == 0: print(0) elif b == 0: print(1) else: solved = [([-1] * b) for i in range(w)] def solve(w, b): if solved[w - 1][b - 1] != -1: return solved[w - 1][b - 1] if w == 0: ans = 0 solved[w - 1][b - 1] = ans ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
MAX = 1002 w, b = map(int, input().split()) ans = 0 dp = [[(0) for _ in range(MAX)] for _ in range(MAX)] end = [[(0) for _ in range(MAX)] for _ in range(MAX)] dp[w][b] = 1 for i in range(w, -1, -1): end[i][b + 1] = 1 if w > 0: ans += w / (w + b) * dp[w][b] end[w - 1][b] = 1 if b > 0: for j in range(b - ...
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMB...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = list(map(int, input().split())) p = [] for i in range(w + 1): p.append([0] * (b + 1)) for i in range(1, w + 1): p[i][0] = 1 for i in range(1, w + 1): for j in range(1, b + 1): p[i][j] = i / (i + j) if j >= 3: p[i][j] += ( j / (i + j) ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST 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 BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_C...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
import sys input = sys.stdin.readline memo = {} def prob(w, b): if w == 0 or b < 0: return 0 if b == 0: return 1 if (w, b) in memo: return memo[w, b] ans1 = w / (w + b) if b == 1: ans2 = 0 else: ans2 = ( b / (w + b) *...
IMPORT ASSIGN VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBE...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = map(int, input().split()) dp = [([0] * (b + 1)) for _ in range(w + 1)] for i in range(1, w + 1): dp[i][0] = 1 for i in range(1, w + 1): for j in range(1, b + 1): dp[i][j] += i / (i + j) if j >= 3: dp[i][j] += ( dp[i][j - 3] * j /...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR V...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = [int(i) for i in input().split()] dp = [[(-1) for i in range(b + 1)] for j in range(w + 1)] def f(w, b): if w == 0 and b == 0: return 0 if b <= 0: return 1 if w == 0: return 0 if dp[w][b] != -1: return dp[w][b] ans = w / (w + b) if w >= 1 and b >= 2: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL 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 VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP VAR BI...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = map(int, input().split()) k, p, q, s = 0, 0, 1, w + b while q != 0 and k < s: d = q * w / s p += d q -= d s -= 1 d = q * w / s q -= d s -= 1 k += 1 print(p)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = map(int, input().split()) if w == 0: print(0) elif b == 0: print(1) else: ans = 0 dp = [[(0.0) for i in range(b + 1)] for j in range(w + 1)] dp[w][b - 1] = b / (w + b) ans += w / (w + b) i = w while i >= 0: j = b - 1 while j >= 0: if j + 3 <= b: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR B...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
save = {} def fun(w, b): global save key = str(w) + " " + str(b) if save.get(key) != None: return save[key] prob = 0 if w >= 0 and b >= 0 and w + b != 0: prob = w / (w + b) if w + b > 2: prob += ( fun(w - 1, b - 2) * (b / (w + b))...
ASSIGN VAR DICT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE RETURN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BI...
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
w, b = map(int, input().split()) cached = [([None] * (b + 1)) for i in range(w + 1)] def cal(w, b): if cached[w][b] is not None: return cached[w][b] if w == 0: return 0 if b == 0: return 1 total = w + b p = w / total bp = 1 - p dbp = (b - 1) / (total - 1) if b =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR NONE RETURN VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER ...
Knight is at (start_x,start_y) in Geekland which is represented by an NxM 2D matrix. Each cell in the matrix contains some points. In the ith step, the knight can collect all the points from all the cells that can be visited in exactly i steps without revisiting any cell. Also, the knight has some magical powers that e...
class Solution: def knightInGeekland(self, arr, start): x = [-2, -2, 2, 2, -1, 1, -1, 1] y = [-1, 1, -1, 1, -2, -2, 2, 2] n = len(arr) m = len(arr[0]) visit = [[(False) for _ in range(m)] for _ in range(n)] data = [] start = [start] visit[start[0][0]]...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIS...
Knight is at (start_x,start_y) in Geekland which is represented by an NxM 2D matrix. Each cell in the matrix contains some points. In the ith step, the knight can collect all the points from all the cells that can be visited in exactly i steps without revisiting any cell. Also, the knight has some magical powers that e...
class Solution: def knightInGeekland(self, arr, start): m, n = len(arr), len(arr[0]) q = [(start[0], start[1])] coins = [] visited = {(start[0], start[1])} ds = [(r, c) for r in (-2, 2) for c in (-1, 1)] + [ (r, c) for r in (-1, 1) for c in (-2, 2) ] ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VA...