description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
MOD = 1000000007 A = [([0, 1, 2, 4, 8] + [0] * 996) for _ in range(1001)] A[0] = [0] * 1001 for m in range(5, 1001): A[1][m] = (A[1][m - 1] + A[1][m - 2] + A[1][m - 3] + A[1][m - 4]) % MOD for n in range(2, 1001): for m in range(1001): A[n][m] = A[n - 1][m] * A[1][m] % MOD def solve(N, M): SN = [0...
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER NUMBER NUMBER NUMBER BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR N...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
A = 1000000007 inp = [] for _ in range(int(input())): [n, m] = [int(x) for x in input().split()] inp.append((n, m)) m_max = max([a[1] for a in inp]) r = [1, 2, 4, 8] for i in range(4, m_max): r.append(sum(r[i - 4 : i]) % A) for a, b in inp: t = [1] s = [pow(x, a, A) for x in r[:b]] for j in rang...
ASSIGN VAR NUMBER ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
mod = 1000000007 lim = 1000 A = [0] * (lim + 1) for i in range(1, 5): A[i] = sum(A[:i]) + 1 for i in range(5, lim + 1): A[i] = sum(A[i - 4 : i]) % mod for _ in range(int(input())): n, m = map(int, input().strip().split()) H = [0] * (m + 1) for i in range(1, m + 1): H[i] = pow(A[i], n, mod) ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
mod = 1000000007 T = int(input()) for case in range(T): N, M = map(int, input().rstrip().split()) def solve(): if N == 1: return 1 if M < 5 else 0 row_comb = [0] * (M + 1) row_comb[0] = 1 for i in range(len(row_comb)): for coin in [1, 2, 3, 4]: ...
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 FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FO...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
tc = int(input()) mod = 1000000007 while tc: tc -= 1 N, M = input().split() N, M = int(N), int(M) d = {(-3): 0, (-2): 0, (-1): 0, (0): 1, (1): 1} for i in range(2, M + 1): d[i] = (d[i - 1] + d[i - 2] + d[i - 3] + d[i - 4]) % mod D = {(1): 1} for i in range(2, M + 1): d[i] = p...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
modc = 1000000007 maxn = 1000 + 5 a = {} a[1, 1] = 1 a[1, 2] = 2 a[1, 3] = 4 a[1, 4] = 8 for i in range(5, maxn): a[1, i] = (a[1, i - 1] + a[1, i - 2] + a[1, i - 3] + a[1, i - 4]) % modc for h in range(2, maxn): for w in range(1, maxn): p, d = a[h // 2, w], a[1, w] if h % 2 == 1 else 1 a[h, w] =...
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
def lego_blocks(N, M): S = [(0) for _ in range(M)] P = [(0) for _ in range(M)] Q = [(0) for _ in range(M)] for i in range(M): Q[i] += pow(2, i) if i < 4 else Q[i - 1] + Q[i - 2] + Q[i - 3] + Q[i - 4] Q[i] %= 1000000007 for i in range(M): P[i] = pow(Q[i], N, 1000000007) fo...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMB...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
def get_walls(n, m): first = [1, 1, 2, 4] for i in range(4, m + 1): first.append(sum(first[-4:]) % 1000000007) table = [[1] * (m + 1)] for i in range(n): table.append([(x * y % 1000000007) for x, y in zip(table[-1], first)]) return table walls = get_walls(1000, 1000) def get_unbr...
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VA...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
t = input() mod = 1000000007 def fastPow(base, power, MOD): result = 1 while power > 0: if power % 2 == 1: result = result * base % MOD power = power // 2 base = base * base % MOD return result for _ in range(int(t)): n, m = map(int, input().split()) floorComb...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
t = int(input()) inps = [] max_n, max_m = 0, 0 M = int(1000000000.0 + 7) rows = [] cols = [] for test in range(t): n, m = [int(x) for x in input().split()] max_n, max_m = max(max_n, n), max(max_m, m) inps.append((n, m)) if not n in rows: rows.append(n) cols.append(m) z = rows.index(n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER 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 ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CA...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
__author__ = "camilo ariza" __email__ = "camilo.ariza@protomail.com" __created__ = "Sat 04 Apr 2020 11:36:43 -0300" __modified__ = "Wed 08 Apr 2020 14:31:52 -0300" def get_solid_walls(n, m, rows=[1, 1, 2, 4, 8]): mod = pow(10, 9) + 7 n, m = n % mod, m % mod all_walls = [0] * (m + 1) solid_walls = [0] ...
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIG...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
MOD = 10**9 + 7 def main(MOD=MOD, rowtbl=[1]): ncases = int(input()) for case in range(ncases): rows, cols = map(int, input().split()) while len(rowtbl) <= cols: rowtbl.append(sum(rowtbl[-4:]) % MOD) walltbl = [pow(possrows, rows, MOD) for possrows in rowtbl] solidt...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF VAR LIST 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 WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
modulo = 1000000007 g = [(0) for x in range(1000)] g[0:4] = [1, 2, 4, 8] for i in range(4, 1000): g[i] = (g[i - 1] + g[i - 2] + g[i - 3] + g[i - 4]) % modulo T = int(input()) for i in range(T): [N, M] = [int(x) for x in input().split()] unconst = [(0) for x in range(M)] const = [(0) for x in range(M)] ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
T = int(input()) for _ in range(T): n, m = map(int, input().split()) ntes = [(0) for i in range(max(m + 1, 4))] ntes[0], ntes[1], ntes[2], ntes[3] = 1, 1, 2, 4 for i in range(4, m + 1): ntes[i] = (ntes[i - 1] + ntes[i - 2] + ntes[i - 3] + ntes[i - 4]) % 1000000007 total = [pow(ntes[i], n, 10...
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 NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMB...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
m = 1000000007 raw = [0] * 1001 raw[1] = 1 raw[2] = 2 raw[3] = 4 raw[4] = 8 for i in range(5, 1001): raw[i] = (raw[i - 1] + raw[i - 2] + raw[i - 3] + raw[i - 4]) % m def modexp(b, e): rv = 1 bb = b ee = e while ee > 0: if ee & 1 == 1: rv = rv * bb % m bb = bb * bb % m ...
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBE...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
M = 1000000007 def powMod(num, power): c, e = 1, 0 while e < power: e += 1 c = num * c % M return c def solve(h, w): memo = [0, 1, 2, 4, 8] A = [0, 1, powMod(2, h), powMod(4, h), powMod(8, h)] for i in range(5, w + 1): memo.append((memo[i - 1] + memo[i - 2] + memo[i -...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMB...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
def go(n, m): M = 1000000007 f = [1, 1, 2, 4] for i in range(4, m + 1): f.append(sum(f[-4:])) F = [0, 1] for i in range(2, m + 1): v = f[i] = pow(f[i], n, M) for j in range(1, i): v -= F[j] * f[i - j] F.append(v % M) return F[-1] for t in range(int(i...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
m = 1000000007 dp1 = [1, 1, 2, 4] for i in range(4, 1001): dp1.append((dp1[-1] + dp1[-2] + dp1[-3] + dp1[-4]) % m) def f(h, w): dp2 = [] dp3 = [pow(dp1[i], h, m) for i in range(w + 1)] for i in range(w + 1): tmp = dp3[i] for j in range(1, i): tmp = (tmp - dp2[j] * dp3[i - j...
ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
mod = 1000000007 max_w = 1000 def pow(a, b): a %= mod result = 1 while b > 0: if b & 1: result = result * a % mod a = a * a % mod b = b >> 1 return result n_rows = [0] * (max_w + 1) n_rows[0] = 1 n_rows[1] = 1 n_rows[2] = 2 n_rows[3] = 4 n_rows[4] = 8 for i in ran...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
MOD = int(1000000000.0 + 7) for _ in range(int(input())): N, M = map(int, input().split()) ways = [0] * (M + 4) ways[0] = 1 for i in range(M): for j in range(1, 5): ways[i + j] = (ways[i + j] + ways[i]) % MOD res = [0] * (M + 1) resbad = [0] * (M + 1) resgood = [0] * (M +...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER 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 VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
def modPower(value, toPower, toMod): powered = value for i in range(1, toPower): powered *= value if powered > 1000000007: powered %= toMod return powered % toMod def LegoSum(H, W): A = [0] * (W + 1) L = [0] * (W + 1) A[0] = 1 for i in range(1, W + 1): f...
FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBE...
You have an infinite number of 4 types of lego blocks of sizes given as (depth x height x width): d h w 1 1 1 1 1 2 1 1 3 1 1 4 Using these blocks, you want to make a wall of height $n$ and width $m$. Features of the wall are: - The wall should not have any holes in it. - The wall you build should be one solid st...
ll = [0] * 1001 ll[0] = 1 ll[1] = 1 ll[2] = 2 ll[3] = 4 for g in range(4, 1001): ll[g] = (ll[g - 1] + ll[g - 2] + ll[g - 3] + ll[g - 4]) % 1000000007 a = int(input().strip()) l = [] for t in range(a): l.append(tuple(map(int, input().strip().split(" ")))) for i in l: S = [] for tt in range(0, i[1] + 1): ...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VA...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): a = [] for i in range(1, N + 1): a.append(i) n = N k = K dp = [] for i in range(N + 1): c = [] for j in range(N + 1): d = [] for k in range(k + 1): ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VA...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): dp = [[(0) for _ in range(N + 1)] for _ in range(K + 1)] for i in range(1, K + 1): for j in range(i, N + 1): if i == 1: dp[i][j] = 1 elif j == i: dp[i][j] = 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR 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 VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NU...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): if N == K or K == 1: return 1 elif N < K: return 0 else: return self.countWaystoDivide(N - 1, K - 1) + self.countWaystoDivide( N - K, K )
CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): memo = [[[(-1) for _ in range(N + 1)] for _ in range(N + 1)] for _ in range(K)] def dfs(index: int = 0, last_used: int = 1, left: int = N): if index == K - 1: return 1 if left >= last_used else 0 if left <= ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF VAR VAR VAR NUMBER NUMBER VAR IF VAR BIN_OP VAR NUMBER RETURN VAR VAR NUMBER NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR LIST FOR...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): if K > N: return 0 def func(dp, ind, tar, K, N): if ind > N: return 0 if ind == N and tar == 0 and K == 0: return 1 if tar < 0 or K < 0: return 0 ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN V...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, n, k): memo = {} def helper(i, n, k): if (i, n, k) in memo: return memo[i, n, k] if n == 0 and k != 0 or n != 0 and k == 0: return 0 if n == 0 and k == 0: return 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): if N < K: return 0 if K == 1: return 1 return self.countWaystoDivide(N - K, K) + self.countWaystoDivide(N - 1, K - 1)
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
import sys sys.setrecursionlimit(10**6) class Solution: def countWaystoDivide(self, n, s): def csum(ind, t, co): if ind > n: return 0 if ind == n and t == 0 and co == 0: return 1 if t < 0 or co < 0: return 0 ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR N...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): if N < K: return 0 def solve(P, N, K): if N < K * P: return 0 if K == 1 and N > 0 or P * K == N: return 1 i = P s = 0 while i * K <= N: ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER FUNC_DEF IF VAR BIN_OP VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR NUMBER VAR VAR
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): if N < K: return 0 T = [([0] * (K + 1)) for i in range(N + 1)] for i in range(1, N + 1): T[i][1] = 1 T[0][0] = 1 for i in range(1, N + 1): for j in range(2, K + 1): if i >=...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER 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 ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP V...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): memo = {} def dp(i, remain, total, memo): if total > N: return 0 if remain == 0: if total == N: return 1 return 0 if i > N: ret...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RE...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): def solve(sum_left, count, prev): if count == 0: if sum_left == 0: return 1 else: return 0 if sum_left == 0 and count != 0: return 0 ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR RETU...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): max_val = N - (K - 1) mat = [ [[(0) for _ in range(max_val + 1)] for _ in range(N + 1)] for _ in range(K + 1) ] return self.ways_to_divide(N, K, max_val, mat) def ways_to_divide(self, N, K, max_val, mat)...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP 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 VAR RETURN VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER A...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, n, k): dp = [[[(0) for _ in range(K + 1)] for _ in range(N + 1)] for _ in range(N + 1)] for i in range(1, N + 1): dp[i][0][0] = 1 for max_value in range(1, N + 1): for remaining_sum in range(1, N + 1): for r...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR 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 ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBE...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, n, k): dp = [] for i in range(n + 1): l1 = [] for j in range(n + 1): l2 = [] for z in range(k + 1): l2.append(-1) l1.append(l2) dp.append(l1) r...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_DEF IF VAR NUMBE...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): a = [i for i in range(1, N + 1)] dp = [[([-1] * (K + 1)) for i in range(N + 1)] for j in range(N + 1)] def coin(i, su, a1): if su == N: if a1 == K: return 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR NUMB...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
import sys sys.setrecursionlimit(1500) class Solution: def countWaystoDivide(self, N, K): cache = [[([None] * (N + 1)) for i in range(N + 1)] for k in range(K + 1)] def helper(k, _sum, i): if _sum > N: return 0 if k == 0: if _sum == N: ...
IMPORT EXPR FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER IF ...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def __init__(self): self.cache = {} def dp(self, nxt, summ, n): if summ == 0 and n == 0: return 1 if summ <= 0 or n == 0: return 0 if (nxt, summ, n) in self.cache: return self.cache[nxt, summ, n] ans = 0 for i ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VA...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): dp = [ [[(-1) for i in range(K + 1)] for j in range(N + 1)] for j in range(N + 1) ] def recursive(N, K, Sum=N): nonlocal dp if Sum == 0: if K == 0: return 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF VAR IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def countWaystoDivide(self, N, K): dp = [[(0) for j in range(K + 1)] for i in range(N + 1)] dp[0][0] = 1 for i in range(1, N + 1): dp[i][0] = 0 dp[i][1] = 1 for j in range(2, K + 1): for i in range(j, N + 1): dp[i][...
CLASS_DEF 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 ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR B...
Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing order (i.e. group[i] <= group[i+1]). Find the number of such groups Example ...
class Solution: def s(self, n, k, p, dp): if k == 0: if n == 0: return 1 return 0 if n <= 0: return 0 if dp[n][k][p] != -1: return dp[n][k][p] w = 0 for i in range(p, n + 1): w = w + self.s(n - i, k ...
CLASS_DEF FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR RE...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
n = int(input()) (*a,) = map(int, input().split()) a.append(-1) b = [a[i] for i in range(n) if a[i] != a[i - 1]] dp = [[(0) for j in range(n + 2)] for i in range(n + 2)] for l in range(len(b)): for i in range(len(b) - l): j = i + l dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]) if b[i] == b[j]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR F...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
def lps(str): n = len(str) L = [[(0) for x in range(n)] for x in range(n)] for i in range(n): L[i][i] = 1 for cl in range(2, n + 1): for i in range(n - cl + 1): j = i + cl - 1 if str[i] == str[j] and cl == 2: L[i][j] = 2 elif str[i] == ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
def inpl(): return list(map(int, input().split())) N = int(input()) A = inpl() B = [0] for a in A: if B[-1] != a: B.append(a) B = B[1:] k = len(B) dp = [0] * ((k * k + k) // 2) for d in range(1, k): for i in range(k - d): if B[i] == B[i + d]: dp[d * (2 * k - d + 1) // 2 + i] = ...
FUNC_DEF RETURN 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 ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP VAR VA...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
n = int(input()) lsr = list(map(int, input().split())) ls = [lsr[0]] for le in lsr[1:]: if le != ls[-1]: ls.append(le) n = len(ls) dpa = [] dpb = [(0) for i in range(n + 1)] for sz in range(2, n + 1): dp = [] for start in range(n - sz + 1): if ls[start] == ls[start + sz - 1]: dp....
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
def main(): for i in range(n): for j in range(n): dp[0][i][j] = dp[1][i][j] = 0 if i == j else n for r in range(n): for l in range(r, -1, -1): for k in [0, 1]: color = c[l] if k == 0 else c[r] if l != 0: dp[0][l - 1][r] ...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL ...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
n = int(input()) c = list(map(int, input().split())) c.append(-5) arr = [0] for i in range(n): if c[i] != c[i + 1]: arr.append(c[i]) arr_r = [0] + arr[::-1] l = len(arr) store = [0] * l up = [0] * l for i in range(1, l): for j in range(1, l): if arr[i] == arr_r[j]: store[j] = up[j - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
def lcs(a, b): c = [[(0) for i in range(len(a) + 1)] for i in range(len(b) + 1)] for i in range(len(b) + 1): for j in range(len(b) + 1): if i == 0 or j == 0: c[i][j] = 0 elif a[i - 1] == b[j - 1]: c[i][j] = c[i - 1][j - 1] + 1 else: ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_O...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
def fill(): nonlocal dp dp = [0] * (n + 2) for i in range(n + 2): dp[i] = [0] * (n + 2) def compress(v): nonlocal n nonlocal c c = [v[0]] for i in range(1, n): if v[i] != v[i - 1]: c.append(v[i]) n = len(c) n = int(input()) v = [int(i) for i in input().spl...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FU...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
n = int(input()) C = [0] + list(map(int, input().split())) A = [] for i in range(1, n + 1): if C[i] != C[i - 1]: A.append(C[i]) L = len(A) DP = [[([0] * L) for i in range(L)] for j in range(2)] def color(r, i, j): if r == 1: if A[i] == A[j]: DP[r][i][j] = min(DP[0][i][j - 1], DP[1]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
import sys input = sys.stdin.readline n = int(input()) c = list(map(int, input().split())) + [-1] b = [c[i] for i in range(n) if c[i] != c[i + 1]] m = len(b) INF = 10**9 dp = [[([INF] * (m + 1)) for i in range(m + 1)] for j in range(2)] for i in range(m): dp[0][i][i] = dp[1][i][i] = 0 for l in range(1, m): for...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUM...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
def run_length_compress(string): string = string + ["."] n = len(string) begin = 0 end = 1 cnt = 1 ans = [] while True: if end >= n: break if string[begin] == string[end]: end += 1 cnt += 1 else: ans.append(string[begin]...
FUNC_DEF ASSIGN VAR BIN_OP VAR LIST STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSI...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
n = int(input()) C = [int(i) for i in input().split()] INF = 5000 DP = [[([0] * 2) for i in range(n)] for j in range(2)] for i in range(n - 1): for j in range(n - i - 1): DP[(i + 1) % 2][j][0] = INF DP[(i + 1) % 2][j][1] = INF for k in range(2): c = C[j] if k == 0 else C[j + i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NU...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
n = int(input()) a = list(map(int, input().split())) b = [] p = -1 for e in a: if e == p: continue else: b.append(e) p = e def lcs(a, b): lengths = [[(0) for j in range(len(b) + 1)] for i in range(len(a) + 1)] for i, x in enumerate(a): for j, y in enumerate(b): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
def solve(a): n = len(a) best = [([0] * n) for _ in range(n)] for i in range(n - 1, -1, -1): for j in range(i + 1, n): if a[i] == a[j]: best[i][j] = best[i + 1][j - 1] + 1 else: best[i][j] = min(best[i + 1][j], best[i][j - 1]) + 1 return be...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL ...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
n = int(input()) C = [int(i) for i in input().split()] D = [] for c in C: if not D or D[-1] != c: D.append(c) n = len(D) C = D[::-1] DP = [([0] * (n + 1)) for i in range(2)] for i in range(n): for j in range(n): if C[i] == D[j]: DP[i + 1 & 1][j + 1] = DP[i & 1][j] + 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR F...
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju. Input: First line contains N and K, denoting number of angles Raju knows how to draw and K the number...
n, k = list(map(int, input().split())) knows = list(map(int, input().split())) draw = list(map(int, input().split())) for i in draw: if i in knows: print("YES") else: for j in knows: f = False angle = j * 2 while angle % 360 != j: if angle % 36...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE B...
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju. Input: First line contains N and K, denoting number of angles Raju knows how to draw and K the number...
N, K = [int(i) for i in input().split()] KnownAngle = [int(x) for x in input().split()] Todraw = [int(x) for x in input().split()] def Tell(toknow): for j in KnownAngle: for i in range(1, 360): if j * i % 360 == toknow: return True def Telll(toknow): for i in KnownAngle: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER FUNC_DEF FOR VAR VAR FOR VAR VAR IF BI...
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju. Input: First line contains N and K, denoting number of angles Raju knows how to draw and K the number...
N, K = input().strip().split() N = int(N) K = int(K) if N < 1 or N > 10 or K < 1 or K > 10: exit() raju_angles = input().strip().split() raju_angles = list(map(int, raju_angles)) rani_angles = input().strip().split() rani_angles = list(map(int, rani_angles)) for i in raju_angles: if i < 0 or i > 360: ex...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR...
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju. Input: First line contains N and K, denoting number of angles Raju knows how to draw and K the number...
def formatter(a): if a == "360": return 0 return int(a) super_array = [] for i in range(360): super_array.append([]) num = i j = 1 while num not in super_array[i]: super_array[i].append(num) j += 1 num = i * j while num >= 360: num -= 360 n, ...
FUNC_DEF IF VAR STRING RETURN NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju. Input: First line contains N and K, denoting number of angles Raju knows how to draw and K the number...
def fin(n, k): for i in range(1, 51): if (360 * i + n) % k == 0: return 1 if (360 * i - n) % k == 0: return 1 return 0 def main(): t = input().split() N = int(t[0]) K = int(t[1]) raj = [int(i) for i in input().split()] ran = [int(i) for i in input()....
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER RETURN NUMBER IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_C...
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju. Input: First line contains N and K, denoting number of angles Raju knows how to draw and K the number...
N, K = list(map(int, input().split(" "))) angles_raju = list(map(int, input().split(" "))) angles_rani = list(map(int, input().split(" "))) all_angles = {} for angle in angles_raju: temp = angle all_angles[temp] = 1 while temp % 360 != 0: temp = temp + angle all_angles[temp % 360] = 1 for an...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBE...
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju. Input: First line contains N and K, denoting number of angles Raju knows how to draw and K the number...
import sys def main(): N, K = list(map(int, sys.stdin.readline().split())) raju_knows = list(map(int, sys.stdin.readline().split())) rani_wants = list(map(int, sys.stdin.readline().split())) raju_can_make = [] for i in raju_knows: raju_can_make.extend(angel(i)) for e in rani_wants: ...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_C...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
for i in range(int(input())): a = int(input()) l = list(map(int, input().split(" "))) l1 = [(-1) for i in range(a)] l1[-1] = 1 for i in range(a - 2, -1, -1): if l[i] >= 0 and l[i + 1] <= 0 or l[i] <= 0 and l[i + 1] >= 0: l1[i] = l1[i + 1] + 1 else: l1[i] = 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBE...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) nl = [] j, c = 0, 1 for i in range(n): if j < i: j = i while j < n - 1 and (l[j] < 0 and l[j + 1] >= 0 or l[j] >= 0 and l[j + 1] < 0): j += 1 print(j - i + 1, end=" ") ...
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 LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NU...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) arr.append(0) j = 0 while j < n: l = 1 for x in range(j, n): if arr[x + 1] / arr[x] < 0: l += 1 else: break for k in range(l): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUM...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) dp = [1] * n for i in range(n - 1, 0, -1): if arr[i] < 0 and arr[i - 1] < 0 or arr[i] > 0 and arr[i - 1] > 0: continue else: dp[i - 1] = 1 + dp[i] print(*dp)
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 VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split()))[::-1] s = [1] for i in range(1, n): if arr[i] * arr[i - 1] < 0: s.append(s[-1] + 1) else: s.append(1) print(*s[::-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NU...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] + [0] cur = 1 for i in range(1, n + 1): if a[i] * a[i - 1] >= 0: while cur: print(cur, end=" ") cur -= 1 cur = 1 else: cur += 1 pri...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR STRING VAR...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
for _ in range(int(input())): n = int(input()) a = [(0 if int(x) < 0 else 1) for x in input().split()] i, j, k = 0, 0, 0 while i <= n - 1: s = 0 j = i while j <= n - 1: if j < n - 1: k = j + 1 if j == n - 1: k = j ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
for i in range(int(input())): n = int(input()) y = list(map(int, input().split())) a = [0] * n a[-1] = 1 j = 0 while j < n - 1: c = 1 for i in range(j, n - 1): if y[i] < 0: if y[i + 1] > 0: c += 1 else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMB...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There's an array A consisting of N non-zero integers A_{1..N}. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x...
def f(arr, n): ans = [-1] * n ans[n - 1] = 1 for i in range(n - 2, -1, -1): if arr[i] < 0: if arr[i + 1] > 0: ans[i] = ans[i + 1] + 1 else: ans[i] = 1 elif arr[i + 1] < 0: ans[i] = ans[i + 1] + 1 else: an...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): ms = -1000000 cs = 0 ans = "" t = "" d = {} for i in range(n): d[x[i]] = b[i] for j in range(len(w)): ans += w[j] if w[j] not in d: cs += ord(w[j]) e...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUM...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): chr_arr = [] hashmap = dict(zip(x, b)) for i in w: if i in hashmap: chr_arr.append(hashmap[i]) continue chr_arr.append(ord(i)) localmax = globalmax = chr_arr[0] t_begin = t_...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN ...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
from sys import maxsize class Solution: def maxSum(self, w, x, b, n): weight = [] for i in range(len(w)): value = ord(w[i]) if w[i] in x: index = x.index(w[i]) value = b[index] weight.append(value) max_so_far = -maxsize -...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): d = {} m = "" min = -1001 for i in range(0, n): d[x[i]] = b[i] if b[i] > min: min = b[i] m = "" + x[i] else: continue for i in range(0, len(w)): ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP STRING VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): def solve(a, size): max_so_far = float("-inf") - 1 max_ending_here = 0 start = 0 end = 0 s = 0 for i in range(0, size): max_ending_here += a[i] if max_so_fa...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR V...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): d = {} str = "" sum = 0 max = -999999 for i, j in zip(x, b): d[i] = j for i in w: str = str + i if i in d: sum = sum + d[i] else: sum = sum +...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSI...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): csum = 0 msf = 0 dic = {} for ch in w: dic[ch] = ord(ch) for i in range(0, len(x)): dic[x[i]] = b[i] i = 0 start = 0 end = 0 s = 0 while i < len(w): if c...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR ...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): char_dict = {} for ch, val in zip(x, b): char_dict[ch] = val total, max_total = 0, float("-inf") l = 0 res = "" for i in range(len(w)): if w[i] in char_dict: total += char_dict[w[i]...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR ...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): c = {i: j for i, j in zip(x, b)} t = 0 m = -(10**9) s = "" ts = "" for i in w: ts += i if i in c: t += c[i] else: t += ord(i) if m < t: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING RETURN VAR
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): max_s = 0 maxsum = -10000 d = {} s, start, stop = 0, 0, 0 for i in range(n): d[x[i]] = b[i] for i in range(len(w)): if w[i] in d: max_s += d[w[i]] else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF ...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
from sys import maxsize class Solution: def maxSum(self, w, x, b, n): asci = [(b[x.index(i)] if i in x else ord(i)) for i in w] maxf = -maxsize - 1 maxe = start = end = s = 0 for i in range(len(asci)): maxe += asci[i] if maxf < maxe: maxf = ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): d = dict() for i in range(len(x)): d[x[i]] = b[i] s = 0 l = 0 m = -99999 for i in range(len(w)): if w[i] not in d: s += ord(w[i]) else: s += d[w[i]] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
import sys class Solution: def maxSum(self, w, x, b, n): max_so_far = -sys.maxsize max_current = 0 i = 0 j = 0 s = 0 if n == 0: return w for cur in range(len(w)): new_asc = ord(w[cur]) if w[cur] in x: new_...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN V...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): cur_max = 0 overall_max = -100000000 cur_string = "" overall_string = "" for c in w: n = ord(c) if c not in x else b[x.index(c)] cur_max += n cur_string += c if cur_max > overall_ma...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING RETURN VAR
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
import sys class Solution: def maxSum(self, w, x, b, n): def getASCII(c): if w[i] in x: return b[x.index(w[i])] else: return ord(w[i]) sum = 0 max_sum = ord(w[0]) start = 0 cur = 0 end = 0 for i in r...
IMPORT CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR RETURN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN V...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): re = {} for i in range(n): re[x[i]] = b[i] arr = [] for i in range(len(w)): if w[i] in re: arr.append(re[w[i]]) else: arr.append(ord(w[i])) pos = 0 maxi ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASS...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): d = {} s = float("-inf") ans = float("-inf") for i in range(n): d[x[i]] = b[i] x = 0 res = [-1, -1] for i in range(len(w)): if w[i] in d: val = d[w[i]] else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): map = {} char = "a" while char <= "z": map[char] = ord(char) char = chr(ord(char) + 1) char = "A" while char <= "Z": map[char] = ord(char) char = chr(ord(char) + 1) for i in...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR STRING WHILE VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING WHILE VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VA...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
from sys import maxsize class Solution: def maxSum(self, w, x, b, n): arr = [] for i in w: if i in x: ind = x.index(i) arr.append(b[ind]) else: arr.append(ord(i)) current_sum = max_sum = arr[0] if len(arr) == ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): char_weight = {ch: wt for ch, wt in zip(x, b)} res, temp = "", "" res_sum, curr_sum = float("-inf"), 0 for ch in w: val = ord(ch) if ch not in char_weight else char_weight[ch] if val <= curr_sum + val: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): eval_char = lambda a: b[x.index(a)] if a in x else ord(a) len_w = len(w) i = 0 j = 0 max_str = w[j] max_sum = summ = eval_char(w[j]) while j < len_w - 1: if i < j and i < 0: summ -= eva...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VA...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): d = {} for i in range(n): d[x[i]] = b[i] arr = [] for i in w: if i in d: arr.append(d[i]) else: arr.append(ord(i)) if len(arr) == 1: return w ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL ...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): max = -9999 sum = 0 asc = 0 z = "" ans = "" v = {} for i, j in zip(x, b): v[i] = j for i in range(len(w)): if w[i] in v: asc = v[w[i]] else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIG...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): def helper(char): if char in x: return b[x.index(char)] return ord(char) total = 0 ml, mr, l, r = 0, 0, 0, 0 Max = float("-inf") for i in range(len(w)): curval = helper(w[i]) ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR A...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): mp = {} for i in range(n): mp[x[i]] = b[i] asciiList = [] for i in w: if i in mp.keys(): asciiList.append(mp[i]) else: asciiList.append(ord(i)) ans = "" ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL V...
Given a string w, integer array b, character array x and an integer n. n is the size of array b and array x. Find a substring which has the sum of the ASCII values of its every character, as maximum. ASCII values of some characters are redefined. Note: Uppercase & lowercase both will be present in the string w. Array ...
class Solution: def maxSum(self, w, x, b, n): s = 0 cs = -float("inf") ss = "" css = "" for c in w: if c in x: i = x.index(c) s += b[i] ss = ss + x[i] else: s += ord(c) ss...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ...