description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, str): if str[0] == 0 or str.__contains__("00"): return 0 str_len = len(str) if str_len == 0 or str_len == 1: return 1 dp = [-1] * (str_len + 1) return self.validate_message(str, str_len, dp) % 1000000007 def va...
CLASS_DEF FUNC_DEF IF VAR NUMBER NUMBER FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR A...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, str): n = len(str) if n == 0: return 1 if str[0] == "0": return 0 dp = [0] * (n + 1) dp[0] = 1 dp[1] = 1 for i in range(2, n + 1): oneDigit = int(str[i - 1]) twoDigit = int(st...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER STRING RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_C...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def helper(self, str, dp): if str in dp: return dp[str] if len(str) <= 1: return 1 mod = 1000000007 dp[str] = 0 if ( str[0] == "1" or str[0] == "2" and len(str) > 1 and str[1] >= "0" ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR BIN_OP FUNC_CALL VAR ...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, str): if not str: return 0 dp = [(0) for i in range(len(str) + 1)] dp[0] = 1 if str[0] == "0": dp[1] = 0 else: dp[1] = 1 for i in range(2, len(str) + 1): if 0 < int(str[i - 1 : i]) <=...
CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBE...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def solve(self, data, n, dp): if n == 0: return 1 if n == 1: return 1 if dp[n] != -1: return dp[n] a = 0 if n >= 2: if data[n - 2] == "1" or data[n - 2] == "2" and data[n - 1] <= "6": a += self.s...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUM...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, s): d = [0] * len(s) if s[0] != "0": d[0] = 1 else: return 0 for i in range(1, len(s)): if s[i] != "0": d[i] += d[i - 1] g = s[i - 1] + s[i] h = int(g) if s[i ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUM...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, strx): n = len(strx) if n == 0: return 1 if strx.find("00") >= 0 or strx[0] == "0": return 0 for i in range(3, 10): if strx.find(i.__str__() + "0") >= 0: return 0 strx = strx.replace("10"...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING A...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
mod = 1000000000.0 + 7 class Solution: def CountWays(self, digits): n = len(digits) count = [0] * (n + 1) count[0] = 1 count[1] = 1 for i in range(2, n + 1): count[i] = 0 if digits[i - 1] > "0": count[i] = count[i - 1] if...
ASSIGN VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF V...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, s): def isValid(n): if n == "" or n[0] == "0": return False n = int(n) if n == 0 or n > 26: return False return True n = len(s) def f(i): if i == n: ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR STRING VAR NUMBER STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, stg): dp = [(-1) for i in range(len(stg) + 1)] n = len(stg) def recursive(dp, stg, n): if n == 0: return 1 if dp[n] != -1: return dp[n] char = stg[n - 1] if char == "0" and (...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMB...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, st): di = {x: (1) for x in range(1, 27)} m = 1000000007 li = [1] if st[0] == "0": return 0 li.append(1) for i in range(1, len(st)): if st[i] == "0": if st[i - 1] == "1" or st[i - 1] == "2": ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER IF VAR NUMBER STRING RETURN NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP V...
A top secret message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 You are an FBI agent. You have to determine the total number of ways that message can be decoded, as the answer can be large return the answer modulo 10^{9} + 7. Note: An empty digit...
class Solution: def CountWays(self, str): memo = {} def dfs(s): if s in memo: return memo[s] if not s: return 1 if int(s[0]) == 0: return 0 l = dfs(s[1:]) r = 0 if len(s) >= 2 an...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
import sys class Combination: def __init__(self, n, MOD): self.f = [1] for i in range(1, n + 1): self.f.append(self.f[-1] * i % MOD) self.inv_f = [0] * (n + 1) self.inv_f[n] = pow(self.f[n], MOD - 2, MOD) for i in reversed(range(n)): self.inv_f[i] =...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
fac = [1] * 500 finv = [1] * 500 p2 = [1] * 500 n, MOD = map(int, input().split()) for i in range(len(fac) - 1): fac[i + 1] = fac[i] * (i + 1) % MOD finv[i + 1] = pow(fac[i + 1], MOD - 2, MOD) p2[i + 1] = p2[i] * 2 % MOD ans = 0 dp = [([0] * (n // 2 + 2)) for _ in range(n + 2)] dp[0][0] = 1 for i in range(n...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUM...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
inp = input().split() totNums, mod = int(inp[0]), int(inp[1]) def Exp(b, exp): if exp == 0: return 1 temp = Exp(b, exp >> 1) ** 2 if exp % 2 == 1: temp *= b return temp % mod n = 410 fact, inv = [(0) for i in range(n)], [(0) for i in range(n)] fact[0] = inv[0] = 1 for i in range(1, t...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR NU...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
N, MOD = map(int, input().split()) dp = [([0] * (N + 2)) for i in range(N + 2)] dp[0][0] = 1 limit = 1000 frac = [1] * limit for i in range(2, limit): frac[i] = i * frac[i - 1] % MOD fraci = [None] * limit fraci[-1] = pow(frac[-1], MOD - 2, MOD) for i in range(-2, -limit - 1, -1): fraci[i] = fraci[i + 1] * (lim...
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 ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASS...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
N, M = map(int, input().split()) fac = [1] + [0] * N for i in range(1, N + 1): fac[i] = fac[i - 1] * i % M fac_inv = [0] * N + [pow(fac[N], M - 2, M)] for i in range(N, 0, -1): fac_inv[i - 1] = fac_inv[i] * i % M pow2 = [1] + [0] * N for i in range(N): pow2[i + 1] = pow2[i] * 2 % M DP = [([0] * N) for _ in ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_C...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) MOD = m MAX_N = 10**3 fac = [1] + [0] * MAX_N for i in range(1, MAX_N + 1): fac[i] = fac[i - 1] * i % MOD fac_inv = [1] + [0] * MAX_N fac_inv[MAX_N] = pow(fac[MAX_N], MOD - 2, MOD) for i in range(MAX_N, 1, -1): fac_inv[i - 1] = fac_inv[i] *...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_O...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
n, M = map(int, input().split()) combdic = {} def fastfrac(a, b, M): numb = pow(b, M - 2, M) return a % M * (numb % M) % M def comb(p, q): if p == 1: return q if (p, q) in combdic: return combdic[p, q] output = comb(p - 1, q - 1) * q % M output = fastfrac(output, p, M) co...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP ...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
N, MOD = map(int, input().split()) dp = [] comps = [0] * (N + 1) ncr = [[1]] for i in range(420): tmp = [1] for j in range(i): tmp.append((ncr[i][j] + ncr[i][j + 1]) % MOD) tmp.append(1) ncr.append(tmp) for i in range(N): curr = list(comps) curr[1] = pow(2, i, MOD) for j in range(i -...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
import sys f = sys.stdin def line(): return f.readline().strip().split() def powers(limit): size = limit + 1 p = [1] * size for n in range(1, size): p[n] = 2 * p[n - 1] % M return p def binomials(limit): size = limit + 1 bc = [[(0) for k in range(size)] for n in range(size)] ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL ...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL ...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
import sys def input(): return sys.stdin.readline().strip() n, mod = map(int, input().split()) le = 405 def pow(x, y): ans = 1 while y > 0: if y % 2 == 1: ans = ans * x % mod x = x**2 % mod y //= 2 return ans def inv(x): return pow(x, mod - 2) M = [1] mu...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL V...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
N, mod = map(int, input().split()) two = [1] * (N + 1) fact = [1] * (N + 1) inv = [1] * (N + 1) for i in range(1, N + 1): two[i] = two[i - 1] * 2 % mod for i in range(2, N + 1): fact[i] = fact[i - 1] * i % mod inv[N] = pow(fact[N], mod - 2, mod) for i in range(N, 0, -1): inv[i - 1] = inv[i] * i % mod dp = [...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FU...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
def getc(): f = [([0] * 500) for i in range(500)] for i in range(500): f[i][0] = 1 f[1][0] = 1 f[1][1] = 1 for i in range(2, 411): for j in range(1, i + 1): f[i][j] = (f[i - 1][j - 1] + f[i - 1][j]) % mod return f n, mod = map(int, input().split()) f = [([0] * 500) ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP ...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
N = 405 n, m = map(int, input().split()) dp = [([0] * N) for _ in range(N)] c = [([1] * N) for _ in range(N)] p = [0] * N p[0] = 1 for i in range(1, N): p[i] = p[i - 1] * 2 % m for i in range(1, N): for j in range(1, i): c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % m dp[0][0] = 1 for i in range(2, n + 2)...
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP V...
There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn on automatically if it is not already on. Note that Phoenix cannot ...
n, mod = map(int, input().split()) le = 500 def pow(x, y): ans = 1 while y > 0: if y % 2 == 1: ans = ans * x % mod x = x**2 % mod y //= 2 return ans def inv(x): return pow(x, mod - 2) M = [1] mul = 1 for i in range(1, le): mul = mul * i % mod M.append(mu...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER...
# Problem Description Let's imagine a function `F(n)`, which is defined over the integers in the range of `1 <= n <= max_n`, and `0 <= F(n) <= max_fn` for every `n`. There are `(1 + max_fn) ** max_n` possible definitions of `F` in total. Out of those definitions, how many `F`s satisfy the following equations? Since ...
def generate_table(max_n, max_fn): a = [] a.append([[(0) for __ in range(_ + 1)] for _ in range(max_fn + 1)]) for j in range(max_fn + 1): for k in range(j + 1): if j + k <= max_fn: a[0][j][k] = 1 i = 1 while 2**i + 1 <= max_n: a.append([[(0) for __ in rang...
FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER VAR NUMBER VAR EX...
# Problem Description Let's imagine a function `F(n)`, which is defined over the integers in the range of `1 <= n <= max_n`, and `0 <= F(n) <= max_fn` for every `n`. There are `(1 + max_fn) ** max_n` possible definitions of `F` in total. Out of those definitions, how many `F`s satisfy the following equations? Since ...
def circular_limited_sums(max_n, max_fn): p = 12345787 m = max_fn + 1 v = [[int(f1 == fn) for fn in range(m)] for f1 in range(m)] for n in range(max_n - 1): v = [[(sum(w[: m - fn]) % p) for fn in range(m)] for w in v] return sum(sum(w[: m - f1]) % p for f1, w in enumerate(v)) % p
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VA...
# Problem Description Let's imagine a function `F(n)`, which is defined over the integers in the range of `1 <= n <= max_n`, and `0 <= F(n) <= max_fn` for every `n`. There are `(1 + max_fn) ** max_n` possible definitions of `F` in total. Out of those definitions, how many `F`s satisfy the following equations? Since ...
def circular_limited_sums(max_n, max_fn): FL = [([0] * (max_fn + 1)) for i in range(max_fn + 1)] for i in range(max_fn + 1): for j in range(max_fn + 1): if i == j: FL[i][j] = 1 for x in range(max_n - 1): nextFL = [([0] * (max_fn + 1)) for i in range(max_fn + 1)] ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_...
# Problem Description Let's imagine a function `F(n)`, which is defined over the integers in the range of `1 <= n <= max_n`, and `0 <= F(n) <= max_fn` for every `n`. There are `(1 + max_fn) ** max_n` possible definitions of `F` in total. Out of those definitions, how many `F`s satisfy the following equations? Since ...
MODULUS = 12345787 def circular_limited_sums(max_n, max_fn): total = 0 for initial in range(max_fn + 1): counts = {v: (0) for v in range(max_fn + 1)} counts[initial] = 1 for n in range(1, max_n): new_counts = {} for v in range(max_fn + 1): new_co...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_...
# Problem Description Let's imagine a function `F(n)`, which is defined over the integers in the range of `1 <= n <= max_n`, and `0 <= F(n) <= max_fn` for every `n`. There are `(1 + max_fn) ** max_n` possible definitions of `F` in total. Out of those definitions, how many `F`s satisfy the following equations? Since ...
class Memoize: def __init__(self, fn): self.fn = fn self.memo = {} def __call__(self, *args): if args not in self.memo: self.memo[args] = self.fn(*args) return self.memo[args] @Memoize def linear_limited_sums(X, Y, head, tail): if X == 1: return 1 if h...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP VAR VAR VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP...
# Problem Description Let's imagine a function `F(n)`, which is defined over the integers in the range of `1 <= n <= max_n`, and `0 <= F(n) <= max_fn` for every `n`. There are `(1 + max_fn) ** max_n` possible definitions of `F` in total. Out of those definitions, how many `F`s satisfy the following equations? Since ...
mod = 12345787 mat = [ ([1, 1], [0, 1, 3]), ([2, 1, -1], [0, 2, 6, 11]), ([2, 3, -1, -1], [0, 2, 10, 23, 70]), ([3, 3, -4, -1, 1], [0, 3, 15, 42, 155, 533]), ([3, 6, -4, -5, 1, 1], [0, 3, 21, 69, 301, 1223, 5103]), ] for i in range(100): [m.append(sum(k * m[-1 - i] for i, k in enumerate(c)) % mo...
ASSIGN VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUM...
# Problem Description Let's imagine a function `F(n)`, which is defined over the integers in the range of `1 <= n <= max_n`, and `0 <= F(n) <= max_fn` for every `n`. There are `(1 + max_fn) ** max_n` possible definitions of `F` in total. Out of those definitions, how many `F`s satisfy the following equations? Since ...
dp = {} def circular_limited_sums(max_n, max_fn): if max_n == 1: return max_fn // 2 + 1 else: s = 0 for i in range(max_fn + 1): s += solve(max_n - 1, max_fn, i, i) s %= 12345787 return s def solve(n, m, first, last): if (n, m, first, last) in dp: ...
ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR VAR VAR VAR RETURN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP ...
# Problem Description Let's imagine a function `F(n)`, which is defined over the integers in the range of `1 <= n <= max_n`, and `0 <= F(n) <= max_fn` for every `n`. There are `(1 + max_fn) ** max_n` possible definitions of `F` in total. Out of those definitions, how many `F`s satisfy the following equations? Since ...
def circular_limited_sums(max_n, max_fn): if max_n == 1: return sum([(1) for i in range(max_fn + 1) if i + i <= max_fn]) % 12345787 nexts = [ list(filter(lambda x: i + x <= max_fn, range(max_fn + 1))) for i in range(max_fn + 1) ] result = 0 for ii in range(max_fn + 1): ...
FUNC_DEF IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): N = int(input()) arr = list(map(int, input().split())) (HardLeftMin, HardLeftMax, SoftLeftMax, SoftLeftMin, HardRightMax, HardRightMin) = ( [0] * N, [0] * N, [0] * N, [0] * N, [0] * N, [0] * N, ) for i in range(N): ...
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 VAR VAR VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
t = int(input()) for rep in range(t): n = int(input()) d = list(map(int, input().split())) lmax = [0] * n lmax[0] = d[0] rmax = [0] * n rmax[n - 1] = d[n - 1] lmin = [0] * n lmin[0] = d[0] rmin = [0] * n rmin[n - 1] = d[n - 1] for i in range(1, n): lmin[i] = min(lmin[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER A...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) i = [0] * n i[0] = a[0] j = [0] * n j[0] = a[0] k = [0] * n k[-1] = a[-1] l = [0] * n l[-1] = a[-1] for x in range(1, n): i[x] = min(i[x - 1] + a[x], a[x]) j[x] = max(j[x - 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSI...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
from sys import stdin def fix_one(max1_e, min1_e, max1_s, min1_s): next_best = -(10**9) - 1 for x in range(0, len(max1_e) - 1): next_best = max( abs(max1_e[x] - min1_s[x + 1]), abs(max1_s[x + 1] - min1_e[x]), next_best ) return next_best tc = int(stdin.readline()) for i in ra...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR V...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
T = int(input()) for tc in range(T): N = int(input()) D = list(map(int, input().split())) Omaxlist = [] Ominlist = [] Rmaxlist = [] Rminlist = [] Omax = D[0] Omin = D[0] Rmax = D[-1] Rmin = D[-1] Olocalmax = 0 Olocalmin = 0 Rlocalmax = 0 Rlocalmin = 0 for i in...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMB...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): num_ingredients = int(input()) delish_values = list(map(int, input().split())) prefix_max = [0] * num_ingredients prefix_max[0] = delish_values[0] prefix_min = [0] * num_ingredients prefix_min[0] = delish_values[0] suffix_max = [0] * num_ingredients suffix_m...
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 VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSI...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def cal(): def max_delish2(idx): nonlocal maxdp2 if idx == n - 1: maxdp2[idx] = d[idx] return maxdp2[idx] temp = max_delish2(idx + 1) if temp + d[idx] > d[idx]: maxdp2[idx] = temp + d[idx] else: maxdp2[idx] = d[idx] ret...
FUNC_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP V...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def mp(): return map(int, input().split(" ")) def lst(): return list(mp()) def subsm(el, e): ms = el[0] me = el[0] nw = [el[0] * e] for i in range(1, len(el)): ms = max(el[i], ms + el[i]) me = max(me, ms) nw.append(me * e) return nw for _ in range(int(input())):...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL ...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) lmax, lmin, rmax, rmin = [0] * n, [0] * n, [0] * n, [0] * n lmax[0] = l[0] lmin[0] = l[0] rmax[-1] = l[-1] rmin[-1] = l[-1] for i in range(1, len(l)): lmax[i] = max(lmax[i - 1] + l[i], l[i]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 ASSIG...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def solve(arr, n): ans = -(10**20) dp = [0] * n dp[0] = arr[0] dp2 = [10**20] * n dp2[n - 1] = arr[n - 1] for i in range(1, n): dp[i] = max(arr[i], dp[i - 1] + arr[i]) for i in range(n - 2, -1, -1): dp2[i] = min(arr[i], dp2[i + 1] + arr[i]) maxpref = [0] * n minsuff =...
FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FU...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
import sys for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) lmax = [(0) for i in range(n)] lmin = [(0) for i in range(n)] rmax = [(0) for i in range(n)] rmin = [(0) for i in range(n)] c1, c2 = l[0], l[0] m1, m2 = l[0], l[0] lmax[0], lmin[0] = l[0], ...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR V...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def findMax(x): c = x[0] for i in range(1, len(x)): if c < 0: c = 0 c += x[i] if c < x[i - 1]: x[i] = x[i - 1] else: x[i] = c for _ in range(int(input())): N = int(input()) d = list(map(int, input().split())) min1 = d.copy() m...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR 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...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
t = int(input()) for i in range(t): n = int(input()) ar = [int(x) for x in input().split()] pos = [0] * n neg = [0] * n rpos = [0] * n rneg = [0] * n sm = 0 ng = 0 rsm = 0 rng = 0 pos[0] = ar[0] neg[n - 1] = ar[n - 1] rpos[n - 1] = ar[n - 1] rneg[0] = ar[0] fo...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIG...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
n = int(input()) for _ in range(n): total = int(input()) arr = list(map(int, input().split())) rightmax = [0] * total leftmax = [0] * total rightmin = [0] * total leftmin = [0] * total rightmax[0] = arr[0] leftmax[-1] = arr[-1] rightmin[0] = arr[0] leftmin[-1] = arr[-1] for i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NU...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def kadane(a): b = [a[0]] b1 = [a[0]] cs = a[0] cs1 = a[0] for i in range(1, len(a)): cs = max(a[i], cs + a[i]) cs1 = min(a[i], cs1 + a[i]) b.append(max(cs, b[-1])) b1.append(min(cs1, b1[-1])) return b, b1 def kadane1(a): b, b1 = [0] * len(a), [0] * len(a) ...
FUNC_DEF ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) delish = list(map(int, input().split())) r_max, r_min = [0] * n, [0] * n l_max, l_min = [0] * n, [0] * n all_max, all_min, cur_max, cur_min = (-10000000000, 10000000000, 0, 10000000000) all_maxb, all_minb, cur_maxb, cur_minb = (-10000000000, 1000000...
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 VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBE...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def solve(): n = int(input()) arr = list(map(int, input().split())) hardLeftMin = [] for i in range(n): if i == 0: hardLeftMin.append(arr[i]) else: hardLeftMin.append(min(hardLeftMin[-1] + arr[i], arr[i])) hardLeftMax = [] for i in range(n): if i =...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def solve(a, n): prefix_max = [0] * n prefix_min = [0] * n suffix_max = [0] * n suffix_min = [0] * n for i in range(n): if i == 0: prefix_max[i] = a[i] prefix_min[i] = a[i] suffix_max[n - i - 1] = a[n - i - 1] suffix_min[n - i - 1] = a[n - i - ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_O...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) min_left = [0] * n max_left = [0] * n min_right = [0] * n max_right = [0] * n min_left[0] = max_left[0] = l[0] min_right[n - 1] = max_right[n - 1] = l[n - 1] for i in range(1, n): min_left[i] =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) dp1 = [0] * n dp2 = [0] * n dp3 = [0] * n dp4 = [0] * n cs = a[0] gs = a[0] dp1[0] = cs for i in range(1, n): cs = max(a[i], cs + a[i]) gs = max(cs, gs) dp1[i] = gs cs =...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def cal(): maxdp1, maxdp1[0] = [0] * n, d[0] maxdp2, maxdp2[-1] = [0] * n, d[-1] mindp1, mindp1[0] = [0] * n, d[0] mindp2, mindp2[-1] = [0] * n, d[-1] for i in range(n - 2, -1, -1): if maxdp2[i + 1] + d[i] > d[i]: maxdp2[i] = maxdp2[i + 1] + d[i] else: maxdp2[...
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER V...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) Ar = A[::-1] dpmax = [A[i] for i in range(n)] dpmin = [Ar[i] for i in range(n)] for i in range(1, n): dpmax[i] = max(A[i], dpmax[i - 1] + A[i]) for i in range(1, n): dpmin[i] = min(Ar[i], dpmin...
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 VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VA...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def maxSubArray(nums): n = len(nums) dp = [float("-inf")] * n for i in range(n): dp[i] = max((dp[i - 1] if i > 0 else 0) + nums[i], nums[i]) return dp def minSubArray(nums): n = len(nums) dp = [float("inf")] * n for i in range(n): dp[i] = min((dp[i - 1] if i > 0 else 0) + n...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL V...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
t = int(input()) while t != 0: n = int(input()) a = list(map(int, input().split())) max_left = a[:] min_left = a[:] min_right = a[:] max_right = a[:] max_diff = 0 for i in range(1, n): max_left[i] = max(max_left[i - 1] + a[i], a[i]) min_left[i] = min(min_left[i - 1] + a[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP ...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for tests in range(int(input())): N = int(input()) D = list(map(int, input().split())) minL = [] minR = [] maxL = [] maxR = [] currentMax = currentMin = 0 for i in range(N - 1): if i == 0: if D[i] < 0: currentMin = D[i] 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 LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) startmax = [0] * n startmin = [0] * n endmax = [0] * n endmin = [0] * n startmax[n - 1], startmin[n - 1] = A[n - 1], A[n - 1] endmax[0], endmin[0] = A[0], A[0] for i in range(n - 2, -1, -1): st...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
T = int(input()) ans = [] for _ in range(T): N = int(input()) D = [int(i) for i in input().split()] lmax = [D[0]] * N lmin = [D[0]] * N rmax = [D[-1]] * N rmin = [D[-1]] * N for i in range(1, N): lmin[i] = min(lmin[i - 1] + D[i], D[i]) lmax[i] = max(lmax[i - 1] + D[i], D[i]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR ASSIGN VAR BIN_OP LIST VAR NU...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
t = int(input().strip()) for _ in range(t): n = int(input().strip()) a = list(map(int, input().strip().split())) max_lr, min_lr = [a[0]], [a[0]] for i in range(1, n): max_lr.append(max(max_lr[i - 1] + a[i], a[i])) min_lr.append(min(min_lr[i - 1] + a[i], a[i])) max_rl = [(0) for i in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR NUMBER LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) ar = list(map(int, input().split())) minleft = n * [0] maxleft = n * [0] minleft[0] = maxleft[0] = ar[0] for i in range(1, n): minleft[i] = min(ar[i], minleft[i - 1] + ar[i]) maxleft[i] = max(ar[i], maxleft[i - 1] + ar[i]) minrig...
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 VAR LIST NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CAL...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] leftdp = [[(0) for i in range(n)] for j in range(2)] rightdp = [[(0) for i in range(n)] for j in range(2)] leftdp[0][0] = a[0] leftdp[1][0] = a[0] for i in range(1, n): leftdp[0][i] = max(leftdp[0][i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN V...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
class node: def __init__(self, size, elements): self.size = size self.elements = elements def solve(inputs, size): maxr = [0] * size maxl = [0] * size minr = [0] * size minl = [0] * size maxl[0] = minl[0] = inputs[0] maxr[size - 1] = minr[size - 1] = inputs[size - 1] f...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def delish(arr, n): minpref = [(0) for _ in range(n)] maxpref = [(0) for _ in range(n)] minsuf = [(0) for _ in range(n)] maxsuf = [(0) for _ in range(n)] minpref[0] = maxpref[0] = arr[0] curmax, curmin = arr[0], arr[0] for i in range(1, n): curmax = max(curmax + arr[i], arr[i]) ...
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR V...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def leftMin(a, n): r = [] minSum = a[0] curSum = 0 i = 0 while i < n - 1: if curSum >= 0: curSum = a[i] else: curSum += a[i] if minSum > curSum: minSum = curSum r.append(minSum) i += 1 return r def rightMin(a, n): ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) min_p = [a[0]] * n max_p = [a[0]] * n for i in range(1, n): min_p[i] = min(min_p[i - 1] + a[i], a[i]) max_p[i] = max(max_p[i - 1] + a[i], a[i]) min_s = [a[-1]] * n max_s = [a[-1]] * n for i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMB...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): N = int(input()) a = list(map(int, input().split()))[::-1] mxsfr = [0] * N mv = float("-inf") tmv = 0 for i in range(N): tmv = tmv + a[i] if mv < tmv: mv = tmv if tmv < 0: tmv = 0 mxsfr[-i - 1] = mv mn = fl...
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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for case in range(int(input())): N = int(input()) L = list(map(int, input().split())) leftMaSum = [None] * N leftMiSum = [None] * N leftMa = [None] * N leftMi = [None] * N leftMaSum[0] = L[0] leftMiSum[0] = L[0] leftMa[0] = L[0] leftMi[0] = L[0] for i in range(1, N): ...
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 NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN ...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
T = int(input()) for i in range(T): n = int(input()) l = list(map(int, input().split())) premin = [0] * n premax = [0] * n sufmin = [0] * n sufmax = [0] * n premin[0] = premax[0] = l[0] sufmin[-1] = sufmax[-1] = l[-1] for i in range(1, n): premin[i] = min(premin[i - 1], 0) + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NU...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) a = [[0, 0] for i in range(n)] b = [[0, 0] for i in range(n)] x = arr[0] y = arr[0] for i in range(1, n): a[i][0] = x a[i][1] = y if x < 0: x = arr[i] else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER F...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) minleft = [0] * n maxleft = [0] * n minright = [0] * n maxright = [0] * n minleft[0] = maxleft[0] = a[0] for i in range(1, n): minleft[i] = min(minleft[i - 1] + a[i], a[i]) maxleft[i] = max...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
t = int(input()) for x in range(t): n = int(input()) m = input().strip().split() a = [] for val in m: a.append(int(val)) f = list() b = list() for i in range(n): f.append([0, 0]) b.append([0, 0]) f[0][0] = a[0] f[0][1] = a[0] for i in range(1, n): ...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
T = int(input()) output = [] srmax, hlmin, hrmax = {}, {}, {} slmax, hrmin, hlmax = {}, {}, {} def hard_left_min(array, j): if j == 0: return array[0] elif j in hlmin: return hlmin[j] else: tmp = min(array[j], hard_left_min(array, j - 1) + array[j]) hlmin[j] = tmp r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR DICT DICT DICT ASSIGN VAR VAR VAR DICT DICT DICT FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN ...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
import sys for t in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] lma = [(0) for i in range(n)] lmi = [(0) for i in range(n)] rma = [(0) for i in range(n)] rmi = [(0) for i in range(n)] s1 = a[0] s2 = a[-1] ma = ma1 = -sys.maxsize mi = mi1 = sys.max...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN ...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
def lrimax(n, l): dplri = [0] * n dplri[0] = l[0] for i in range(1, n): dplri[i] = max(dplri[i - 1] + l[i], l[i]) for i in range(1, n): dplri[i] = max(dplri[i - 1], dplri[i]) return dplri def lrimin(n, l): dp = [999999999999999999999999999] * n dp[0] = l[0] for i in ran...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER...
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
for _ in range(int(input())): n = int(input()) my = [int(i) for i in input().split()] leftmax = [my[0]] rightmax = [1000000] rightmin = [1000000] leftmin = [my[0]] total = my[0] totmin = my[0] for i in range(1, n): leftmax.append(0) rightmax.append(0) leftmin....
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER V...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
s = input() n = len(s) palindromic = [[(False) for i in range(n)] for y in range(n)] start = [[(0) for i in range(n)] for y in range(n)] end = [[(0) for i in range(n)] for y in range(n)] for i in range(n): for j in range(i + 1): if i == j: palindromic[j][i] = True elif s[j] == s[i] and j...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR 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 NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASS...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
def oddPalindrome(task): answer = [0] * len(task) for i in range(len(task)): for k in range(min(len(task) - i, i + 1)): if task[i - k] != task[i + k]: break else: answer[i] += 1 return answer def evenPalindrome(task): answer = [0] * (len(...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FO...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
s = str(input()) n = len(s) DP = [([0] * n) for _ in range(n)] P = [([0] * n) for _ in range(n)] LR = [([0] * n) for _ in range(n)] RL = [([0] * n) for _ in range(n)] for i in range(n): for j in range(n): s2 = s[i : j + 1] if s[i : j + 1] == s2[::-1]: P[i][j] = 1 if i > j: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FO...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
st = str(input()) def checkpal(i, j, k, l): a = i b = l while a < b: if st[a] != st[b]: return -1 if a == j: a = k - 1 if b == k: b = j + 1 a += 1 b -= 1 return 1 l = len(st) count = 0 for i in range(l): for j in range(i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VA...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
DP = [] for i in range(1002): temp = [] for j in range(1002): temp.append(False) DP.append(temp) def Pre_process(s): n = len(s) for i in range(n): for j in range(n): DP[i][j] = False for j in range(1, n + 1): for i in range(0, n - j + 1): if j <=...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR 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 ...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
def binarySearch(arr, l, r, x): mid = 0 while l <= r: mid = l + (r - l) // 2 if arr[mid] == x: return mid + 1 elif arr[mid] < x: l = mid + 1 else: r = mid - 1 if mid != len(arr): if arr[mid] < x: return mid + 1 retur...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIS...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
s = input() N = len(s) Nkj = [([0] * N) for _ in range(N)] for k in range(N): for j in range(N - 1, k, -1): if s[j] == s[k]: Nkj[k][j] = 1 + (Nkj[k - 1][j + 1] if k > 0 and j < N - 1 else 0) else: Nkj[k][j] = 0 Nkj[j][k] = Nkj[k][j] Pab = [([0] * N) for _ in range(N)]...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER A...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
def func(S): N = len(S) visit = [[None for _ in range(N)] for _ in range(N)] for i in range(N): visit[i][i] = True for i in range(N - 1): if S[i] == S[i + 1]: visit[i][i + 1] = True else: visit[i][i + 1] = False for k in range(3, N + 1): for i ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NONE 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 BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL...
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
def palSub(s, n, isPal): for gap in range(n): for i in range(n - gap): j = i + gap if gap == 0: isPal[i][j] = 1 elif gap == 1: isPal[i][j] = 1 if s[i] == s[j] else 0 else: isPal[i][j] = 1 if s[i] == s[j] and isPa...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER RETURN VAR FUNC_DEF FOR VAR FU...
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 = 10**9 + 7 N = 1000 ways = [1] + [0] * N for k in range(N): for b in (1, 2, 3, 4): if k + b <= N: ways[k + b] += ways[k] ways[k] %= M def solve(height, width): combs = [pow(w, height, M) for w in ways] no_gaps = [0] * (width + 1) for w in range(1, width + 1): no_gaps...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUM...
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...
import sys MOD = 1000000007 T = int(input()) for testcases in range(T): N, M = [int(z) for z in input().split()] rows = [1, 1, 2, 4] while len(rows) <= M: rows.append(sum(rows[-4:]) % MOD) total = [pow(c, N, MOD) for c in rows] unstable = [0, 0, 1] for i in range(3, M + 1): unst...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER 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 V...
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...
P = 10**9 + 7 MAX_M = 1000 nr_ways_ending = [0] * (MAX_M + 1) nr_ways_ending[0] = 1 for i in range(MAX_M): for s in (1, 2, 3, 4): if i + s < MAX_M + 1: nr_ways_ending[i + s] += nr_ways_ending[i] def solve(N, M): A = [0] * (M + 1) solution = [0] * (M + 1) solution[0] = 1 for k i...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER A...
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 expand_row_config_arr(width): curr_len = len(row_config_arr) while curr_len <= width: a = row_config_arr[-1] b = row_config_arr[-2] c = row_config_arr[-3] d = row_config_arr[-4] next_num = (a + b + c + d) % 1000000007 row_config_arr.append(next_num) cu...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER 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...
T = int(input()) mu = 10**9 + 7 def mod_pow(x, p): b = [int(d) for d in format(p, "b")[::-1]] product = 1 for i in range(0, len(b)): if not b[i]: continue factor = x % mu for j in range(i): factor = factor**2 % mu product = product * factor % mu ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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...
MAX = 1000000007 def calcLevels(levels): N = len(levels) M = len(levels[1]) levels[1][0] = 1 p = 1 while p < M: i = 1 while i <= 4 and p - i >= 0: levels[1][p] = (levels[1][p] + levels[1][p - i]) % MAX i += 1 p += 1 n = 2 while n < N: ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSI...
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...
memos = dict({(0): 1, (-1): 0, (-2): 0, (-3): 0}) def calc_one_high_wall(width): if width in memos: return memos[width] ans = sum(calc_one_high_wall(x) for x in range(width - 4, width)) % 1000000007 memos[width] = ans return ans one_high_wall = [calc_one_high_wall(x) for x in range(1100)] me...
ASSIGN VAR FUNC_CALL VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR 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...
import sys MOD = 1000000007 bufArr = [1, 2, 4, 8] powArr = [1] solArr = [1] def makeBufArr(width): for i in range(len(bufArr), width): bufArr.append( (bufArr[i - 1] + bufArr[i - 2] + bufArr[i - 3] + bufArr[i - 4]) % MOD ) def makePowArr(height, width): for i in range(1, width): ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL 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 FUNC_DEF FOR ...
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 def ways_to_build_solid_block(N, M, block_sizes): M_TO_SOLVE = M M = max(M, 4) total = [0] * (M + 1) for block_size in block_sizes: total[block_size] = 1 for i in range(1, M + 1): sum_total_i = 0 for block_size in block_sizes: if i - block_size ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR A...
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...
maxb = 4 maxl = 1000 M = 10**9 + 7 arrange = [1] for i in range(1, maxl + 1): ways = 0 for j in range(1, maxb + 1): if i - j >= 0: ways += arrange[i - j] arrange.append(ways % M) t = int(input()) for _ in range(t): n, m = map(int, input().split()) valid = [1] total = [0] ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL ...
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...
K = 1000000007 MAXM = 1001 T = int(input().strip()) W = [-1] * MAXM for m, c in enumerate((0, 1, 2, 4, 8, 15, 29, 56, 108)): W[m] = c for m in range(9, MAXM): W[m] = ((W[m - 1] << 1) - W[m - 5]) % K for t in range(T): N, M = map(int, input().strip().split()) if N == 1: print(1 if 0 < M < 5 else ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NU...
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...
P = 10**9 + 7 MMAX = 1001 def main(): L = [0] * MMAX L[0] = 1 for i in range(1, MMAX): for j in range(1, min(4, i) + 1): L[i] = (L[i] + L[i - j]) % P T = int(input()) for _ in range(T): N, M = map(int, input().split()) NonSolid = [pow(L[m], N, P) for m in range(...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FU...