description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0). Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can us...
__author__ = "Omotola" N, C = [int(nc) for nc in input().strip().split(" ")] A = [int(a) for a in input().strip().split(" ")] B = [int(b) for b in input().strip().split(" ")] check = [(0) for ch in range(N)] failed = debt = credit = 0 i = N - 1 j = 0 while j < N and check[i] == 0: if check[i] == 0: check[i]...
ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR...
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0). Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can us...
N, C = map(int, input().split()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] A = A * 2 B = B * 2 R = [(0) for x in range(2 * N + 1)] for i in range(2 * N - 1, -1, -1): R[i] = R[i + 1] + B[i] if R[i] > C: print(0) exit() else: R[i] = max(0, R[i] - A[i])...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR B...
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0). Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can us...
def first_starting_index(available_fuel, required_fuel, tank_capacity, n_cities): city_index = 0 while city_index < n_cities: current_city = city_index returned_to_start = False tank = 0 while not returned_to_start: tank = ( tank_capacity ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR RETURN VAR VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN...
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0). Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can us...
import sys def travel(fuels, paths, num, cap): start_index = 0 cur_city = start_index fuel_gathered = 0 while ( cur_city != (start_index - 1) % num or paths[cur_city] > min(fuel_gathered + fuels[cur_city], cap) ) and start_index < num: fuel_gathered = min(fuel_gathered + fu...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_...
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0). Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can us...
N, C = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] b = [int(_) for _ in input().split()] def nbCity(N, C, a, b): start = 0 while start < N: c, valid = 0, True for i in range(N): c = min(C, c + a[(start + i) % N]) if c < b[(start + i) % N]: ...
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 ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_O...
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0). Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can us...
def travelAroundTheWorld(a, b, c, n): d = [] dmin = [] for i in range(n): d.append(a[i] - b[i]) dmin.append(0) dmin[n - 1] = d[n - 1] for i in range(n - 2, -1, -1): dmin[i] = min(d[i], d[i] + dmin[i + 1]) dmin[n - 1] = min(d[n - 1], d[n - 1] + dmin[0]) for i in range(...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution1: def palindromePartition(self, s: str, k: int) -> int: dp = [([0] * len(s)) for i in range(len(s))] n = len(s) def transferPalimCount(s) -> int: res = 0 q = len(s) - 1 p = 0 while p < q: if s[p] != s[q]: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR FOR VAR FUN...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) palindrome = [[(0) for x in range(n)] for y in range(n)] for i in range(n - 1): if s[i] != s[i + 1]: palindrome[i][i + 1] = 1 for gap in range(2, n): for start in...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP V...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: def getCount(i: int, j: int): count = 0 while i < j: if s[i] != s[j]: count += 1 i += 1 j -= 1 return count INT_MAX = 21474...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR FO...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: dp = [[(2**30) for _ in range(k + 1)] for _ in range(len(s) + 1)] for p in range(k + 1): dp[0][p] = 0 def minChange(s: str) -> int: i, j = 0, len(s) - 1 cnt = 0 while i < j...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FUNC_DEF VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR ...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: def count_char(a): n = len(a) b = a[::-1] return sum(a[i] != b[i] for i in range(n)) // 2 n = len(s) d = {} for i in range(n): for j in range(i, n): ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def cost(self, i, j): if i + 1 >= j: return 0 if i + 2 == j: return 0 if self.s[i] == self.s[j - 1] else 1 try: return self.cost_cache[i, j] except KeyError: ret = self.cost(i + 1, j - 1) + (0 if self.s[i] == self.s[j -...
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN V...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: @lru_cache(None) def dp(index, l): if l == 1: leftstr = s[index:] count = 0 left, right = 0, len(leftstr) - 1 while left < right: if...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: self.cache = {} return self.dfs(s, k) def dfs(self, s, k): if (s, k) in self.cache: return self.cache[s, k] if k == 1: self.cache[s, k] = self.helper(s) return self.cache[s...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def __init__(self): self.table = {} def palindromePartition(self, s: str, k: int) -> int: def distanceToPalindrome(subs): k = 0 for i in range(int(len(subs) / 2)): if subs[i] != subs[len(subs) - i - 1]: k += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR F...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int): prefix = [([0] * len(s)) for _ in range(len(s))] for r in range(len(prefix)): for c in range(len(prefix[0])): if r < c: prefix[r][c] = self.find_change(s, r, c) dp = [([0] * len(s)...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR ...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: memo = dict() n = len(s) def find_cost(l, r): cost = 0 while l < r: if s[l] != s[r]: cost += 1 l += 1 r -= 1 return ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUM...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: dp = {} def pali(i, j): diff = 0 while i >= 0 and j < len(s): if s[i] != s[j]: diff += 1 dp[i, j] = diff i -= 1 j += 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF ...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: def count(s): l = len(s) c = 0 for i in range(int(l // 2)): if s[i] != s[l - 1 - i]: c += 1 return c s = "#" + s n = len(s) dp ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMB...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) dp = [[(0) for j in range(k)] for i in range(n)] memo = {} def cost(i, j): if memo.get((i, j)): return memo[i, j] c = 0 while i < j: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CA...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) dp = [[math.inf for _ in range(k + 1)] for _ in range(n + 1)] dp[0][0] = 0 def changes(start, end): cnt = 0 while start < end: if s[start] != s[end]: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR N...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) dp = [[float("inf") for _ in range(k)] for _ in range(n)] def getMinChange(i, j): count = 0 while i < j: if s[i] != s[j]: count += 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
def ch(a): l = len(a) c = 0 for i in range(l // 2): c += a[i] != a[l - i - 1] return c def f(s, ci, k, d): l = len(s) if k == 0: if ci != l: return math.inf return 0 if ci == l: return math.inf if d[ci][k] != -1: return d[ci][k] r...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER IF VAR VAR RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR STRING...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, S: str, K: int) -> int: def palindrome_distance(li, ri): count = 0 while li < ri: count += S[li] != S[ri] li += 1 ri -= 1 return count def dfs(i, k): if i ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN VAR VAR VAR NUMBER NUMBER VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, key: int) -> int: @lru_cache(None) def repair(string: s) -> int: return sum( [ (1 if string[i] != string[-1 - i] else 0) for i in range(len(string) // 2) ] ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NONE VAR FUNC_DEF VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VA...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: self.memo = {} return self.dfs(s, k) def dfs(self, s, k): if (s, k) not in self.memo: res = float("inf") if len(s) == k: res = 0 elif k == 1: res = ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMB...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) self.cost = [[(0) for _ in range(n)] for _ in range(n)] for l in range(2, n + 1): i = 0 while i + l - 1 < n: j = i + l - 1 self.cost[i][j] = self.cost[i +...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: def count_changes(_s): m = len(_s) // 2 return sum([int(c1 != c2) for c1, c2 in zip(_s[:m], _s[::-1][:m])]) n = len(s) if n == k: return 0 dp = [([float("inf")] * (n + 1)) for...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER F...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, K: int) -> int: n = len(s) dp = [[(101) for k in range(K + 1)] for i in range(n)] num = [[(0) for j in range(n)] for i in range(n)] for i in range(n): for j in range(i): num[j][i] = self.helper(s[j : i...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CA...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: @lru_cache(None) def dfs(subs, k): if k == len(subs): return 0 if k == 1: return sum(subs[i] != subs[-1 - i] for i in range(len(subs) // 2)) res = float("inf") ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR V...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: changes = [([0] * len(s)) for _ in range(len(s))] for i in range(len(s)): for j in range(i, len(s)): start, end = i, j tmp = 0 while start < end: if ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) memo = dict() cost_memo = dict() def find_cost(l, r): a, b = l, r if (l, r) not in memo: cost = 0 while l < r: cost += s[l] !...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF ...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: sLen = len(s) dp = {} def moveOnce(prei, i0, k0): if (prei, i0, k0) in dp: return dp[prei, i0, k0] if k0 == k: l = prei r = sLen - 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR ASSIG...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: if len(s) <= k: return 0 def num_change(w): l, r = 0, len(w) - 1 count = 0 while l < r: if w[l] != w[r]: count += 1 l += 1 ...
CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASS...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def numChanges(self, s: str, start: int, end: int) -> int: num = 0 while start < end: if not s[start] is s[end]: num += 1 start += 1 end -= 1 return num def palindromePartition(self, s: str, k: int) -> int: cac...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUM...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) dp = [([float("inf")] * (k + 1)) for _ in range(n + 1)] dp[0][0] = 0 def cald(s): if len(s) == 1: return 0 else: lo, hi = 0, len(s) - 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR V...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: def change(s): if len(s) == 1: return 0 i, j = 0, len(s) - 1 count = 0 while i < j: if s[i] != s[j]: count += 1 i += 1 ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) costs = [([0] * (n - i)) for i in range(n)] for l in range(1, n): for start in range(n - l): old = costs[start + 1][l - 2] if l > 1 else 0 costs[start][l] = old + (0 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR N...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int): cost = [([0] * len(s)) for _ in range(len(s))] for i in range(len(s) - 1, -1, -1): for j in range(i + 1, len(s)): if s[i] == s[j]: cost[i][j] = cost[i + 1][j - 1] else: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIG...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: def min_change(s, i, j): a = 0 while i < j: if s[i] != s[j]: a += 1 i += 1 j -= 1 return a cost = [[(0) for j in range(len(...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR B...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: l = len(s) def jbn(a): le = len(a) return sum(a[i] != a[le - 1 - i] for i in range(le // 2)) dp = [([0] * (l + 1)) for _ in range(k + 1)] for j in range(1, l + 1): dp[1][j] = ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR 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 NUMB...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) s = "#" + s dp = [([float("inf")] * (k + 1)) for _ in range(n + 1)] dp[0][0] = 0 count = [([0] * (n + 1)) for _ in range(n + 1)] for lens in range(2, n + 1): for i in range(n...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: def substring_palindrome(substring): l = 0 r = len(substring) - 1 ans = 0 while l <= r: if substring[l] != substring[r]: ans += 1 l += 1...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP V...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: if not s: return self.memo = {} return self.helper(0, len(s), k, s) def helper(self, i, j, k, s): if (i, j, k) in self.memo: return self.memo[i, j, k] if len(s) <= k: ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN ASSIGN VAR DICT RETURN FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR S...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: dp = defaultdict(int) def pali(i, j): diff = 0 while i >= 0 and j < len(s): if s[i] != s[j]: diff += 1 dp[i, j] = diff i -= 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, k: int) -> int: n = len(s) visited = {} dic = {} def dfs(start, k): if (start, k) in dic: return dic[start, k] if k == 0: i = start j = n - 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BI...
You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is palindrome. Return the minimal number of characters that you need to change to div...
class Solution: def palindromePartition(self, s: str, K: int) -> int: len_s = len(s) if K >= len_s: return 0 dp = [([float("inf")] * (K + 1)) for _ in range(len_s + 1)] s = "0" + s dp[0][0] = 0 for i in range(1, len_s + 1): for k in range(1, m...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC...
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters. Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (...
n = int(input()) arr = list(map(int, input().split())) p = int(input()) dp = [[[(0) for k in range(n + 1)] for i in range(p + 1)] for i in range(n + 1)] for j in range(p + 1): for k in range(n + 1): dp[0][j][k] = 1 for i in range(1, n + 1): for j in range(p + 1): for k in range(1, n + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP VAR NUMBER FOR VAR F...
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters. Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (...
n = input() n = int(n) arr = [0] * n fact = [0] * 51 a = input().split() p = input() p = int(p) for i in range(n): arr[i] = int(a[i]) if n == 1: if arr[0] <= p: print(1) else: print(0) exit(0) def pre(): fact[0] = 1 for i in range(1, 51): fact[i] = fact[i - 1] * i def...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_C...
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters. Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (...
n = int(input()) a = list(map(int, input().split())) p = int(input()) fact = [1] for i in range(1, 51): fact.append(fact[-1] * i) if sum(a) <= p: print(n) else: dp = [([0] * 56) for _ in range(56)] dp[0][0] = 1 for i in range(n): for j in range(n, -1, -1): for k in range(p): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMB...
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can...
n, k = list(map(int, input().split())) ra = [([0] * k) for _ in range(n)] for p in range(k): for i, v in enumerate(map(int, input().split())): v -= 1 ra[v][p] = i g = [[] for _ in range(n)] for u in range(n): for v in range(n): if all(x < y for x, y in zip(ra[u], ra[v])): g[u...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR F...
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can...
import sys input = sys.stdin.readline n, k = map(int, input().split()) a = [list(map(int, input().split())) for i in range(k)] g = [[] for i in range(n + 1)] for i in range(n): x = a[0][i] s = set(a[0][i + 1 :]) for j in range(k): idx = a[j].index(x) s1 = set(a[j][idx + 1 :]) s = s ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR N...
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can...
def main(): n, k = tuple(map(int, input().split())) a = [set(range(n)) for _ in range(n)] for i in range(k): p = set() for j in map(int, input().split()): a[j - 1] -= p p.add(j - 1) sa = sorted(list(range(n)), key=lambda i: len(a[i])) maxx = [0] * n res = ...
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 VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR ...
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can...
def solve(): n, k = map(int, input().split()) c = [[(-1) for i in range(n + 1)] for i in range(k)] dp = [(0) for i in range(n + 1)] a = [] for i in range(k): b = list(map(int, input().split())) for j, v in enumerate(b): c[i][v] = j a.append(b) for i in range(n...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUN...
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can...
n, k = list(map(int, input().split())) a, b = [[] for row in range(6)], [[(0) for col in range(n + 1)] for row in range(6)] for i in range(k): a[i] = list(map(int, input().split())) for j in range(n): b[i][a[i][j]] = j dp = [1] * n for i in range(n): for j in range(i): flag = 1 for x...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VA...
The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-...
N, K, X = list(map(int, input().split())) arr = [0] + [int(i) for i in input().split()] dp = [[float("-inf") for _ in range(X + 1)] for _ in range(N + 1)] dp[0][X] = 0 for i in range(1, N + 1): for x in range(X): for p in range(1, K + 1): if i - p < 0: break if dp[i -...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP ...
The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-...
import sys S = sys.stdin.read() S = list( [ list(map(int, x)) for x in list([x.split() for x in [x for x in S.split("\n") if len(x) > 1]]) ] ) n, k, x, B = S[0][0], S[0][1], S[0][2], S[1] X = [[(-1) for i in range(x + 1)] for i in range(n + 1)] X[0][0] = 0 for i in range(1, n + 1): for j in...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NU...
The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-...
import sys input = sys.stdin.readline n, k, x = map(int, input().split()) a = list(map(int, input().split())) dp = [-1] * (n + 1) dp[0] = 0 for c in range(1, x + 1): dp0 = [-1] * (n + 1) for i in range(c, n + 1): ma = -1 for j in range(1, min(i, k) + 1): ma = max(ma, dp[i - j]) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FO...
The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-...
n, k, x = map(int, input().split()) a = [None] + list(map(int, input().split())) lo, hi = 0, 10**9 * 5000 q = [None] * (n + 1) def get(mid): f, r = 0, 0 q[0] = 0, 0, 0 for i in range(1, n + 1): if q[r][2] == i - k - 1: r += 1 cur = q[r][0] + a[i] - mid, q[r][1] + 1, i w...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NU...
The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-...
n, k, x = list(map(int, input().split())) a = [None] + list(map(int, input().split())) dp = [([-1] * (n + 1)) for i in range(x + 1)] dp[0][0] = 0 for i in range(1, x + 1): for j in range(1, n + 1): dp[i][j] = max(dp[i - 1][j2] for j2 in range(max(0, j - k), j)) if dp[i][j] != -1: dp[i][j...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBE...
Given an array A of N positive integers. The task is to count the number of Arithmetic Progression subsequence in the array. Note: Empty sequence or single element sequence is Arithmetic Progression. Example 1: Input : N = 3 A[] = { 1, 2, 3 } Output : 8 Explanation: Arithmetic Progression subsequence from the given...
class Solution: def count(self, N, A): dp = [] x = max(A) - min(A) y = min(A) - max(A) for i in range(N): d1 = {} dp.append(d1) c = N + 1 for i in range(N): for j in range(i): if A[i] - A[j] not in dp[j]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR V...
Given an array A of N positive integers. The task is to count the number of Arithmetic Progression subsequence in the array. Note: Empty sequence or single element sequence is Arithmetic Progression. Example 1: Input : N = 3 A[] = { 1, 2, 3 } Output : 8 Explanation: Arithmetic Progression subsequence from the given...
class Solution: def count(self, n, a): mini = min(a) maxi = max(a) dp = [(0) for i in range(n + 1)] r = n + 1 for d in range(mini - maxi, maxi - mini + 1): sumi = [(0) for i in range(100000)] for i in range(n): dp[i] = 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF ...
Given an array A of N positive integers. The task is to count the number of Arithmetic Progression subsequence in the array. Note: Empty sequence or single element sequence is Arithmetic Progression. Example 1: Input : N = 3 A[] = { 1, 2, 3 } Output : 8 Explanation: Arithmetic Progression subsequence from the given...
class Solution: def count(self, N, arr): dp = [{} for i in range(0, N)] ans = N + 1 for i in range(1, N): for j in range(0, i): diff = arr[i] - arr[j] val = 1 + dp[j].get(diff, 0) if diff in dp[i]: dp[i][diff] +...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
mod = 1000000007 ncr = [([0] * (n + 1)) for n in range(301)] for n in range(301): ncr[n][0] = ncr[n][n] = 1 for r in range(1, n): ncr[n][r] = ncr[n - 1][r] + ncr[n - 1][r - 1] T = int(input()) for _ in range(T): N, M = [int(i) for i in input().split()] x = [(int(i) - 1) for i in input().split()]...
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
MOD = 1000000007 Paths = [] Solve = [] Choose = [] p = [] s = [] N = 0 M = 0 def C(n, k): if n == 0 or k == 0 or k >= n: return 1 if Choose[n][k] != -1: return Choose[n][k] result = C(n - 1, k - 1) + C(n - 1, k) result %= MOD Choose[n][k] = result return result def paths(idx,...
ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP ...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
import sys MOD = 1000000007 def choose(n, k): if k < 0 or k > n: return 0 else: p, q = 1, 1 for i in range(1, min(k, n - k) + 1): p *= n q *= i n -= 1 return p // q def count_ways(N, M, D): ways = [[([0] * D[i]) for _ in range(M + 1)] ...
IMPORT ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
def memoize(func): pool = {} def wrapper(*arg): if arg not in pool: pool[arg] = func(*arg) return pool[arg] return wrapper mod = 1000000007 ncr_max = 310 ncr = [([0] * ncr_max) for _ in range(ncr_max)] for i in range(ncr_max): ncr[i][0] = ncr[i][i] = 1 for j in range(...
FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_O...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
M, F, IF = 10**9 + 7, [1] * 301, [1] * 301 def powM(b, e): return ( b if e == 1 else powM(b, e >> 1) ** 2 * b % M if e & 1 else powM(b, e >> 1) ** 2 % M ) for i in range(2, 301): F[i] = F[i - 1] * i % M IF[i] = powM(F[i], M - 2) def C(n, m): return F[n] * IF[n - m] % M ...
ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUM...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
import sys DEBUG = 0 if DEBUG: handler = open("./input") else: handler = sys.stdin cases = int(handler.readline()) MOD = 1000000007 def mirror(grid, upper_bound): ret = list(grid) for i in range(len(grid)): if ret[i] * 2 > upper_bound[i] + 1: ret[i] = upper_bound[i] + 1 - grid[i] ...
IMPORT ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN ...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
T = int(input()) MOD = 1000000007 C = [([0] * 400) for _ in range(400)] C[0][0] = 1 for i in range(400): C[i][0], C[i][i] = 1, 1 for j in range(1, i): C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD for t in range(T): N, M = [int(c) for c in input().split()] X = [int(c) for c in input().split()]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
def nCk(n, k): if k >= 0 and k <= n: ntok = 1 ktok = 1 T = min(k, n - k) + 1 for t in range(1, T): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 def CalculateD(StartingPoint, Dim, N, M): D = [([0] * (M + 1)...
FUNC_DEF IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VA...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
MOD = 1000000007 t = eval(input()) def predict(x, d, value): return x + value if x + value <= d and x + value >= 1 else x combi = [([1] * (300 + 1)) for i in range(300 + 1)] for i in range(1, 300 + 1): for j in range(1, i + 1): if j >= i // 2 + 1: combi[i][j] = combi[i][i - j] el...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
def grid_walking(N, M, X, D): W = [[(0) for _ in range(N + 1)] for _ in range(M + 1)] for i in range(N): T = [[(0) for _ in range(M + 1)] for _ in range(D[i] + 1)] for j in range(1, D[i] + 1): T[j][0] = 1 for j in range(1, M + 1): for k in range(1, D[i] + 1): ...
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 VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
def grid_walking(startpos, maxpos, maxsteps): mod = 1000000007 one_d = [] for dim in range(len(maxpos)): table = [list([1] + [0] * maxsteps) for _ in range(maxpos[dim])] for steps in range(1, maxsteps + 1): for pos in range(1, maxpos[dim]): table[pos][steps] = tab...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER F...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
def cal(loc, dim, n, m): if m == 0: return 1 ans = 0 for i, x in enumerate(loc): for step in [-1, 1]: if 0 < x + step <= dim[i]: curr = loc.copy() curr[i] = x + step ans += cal(curr, dim, n, m - 1) return ans def dimension(x, ...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR LIST NUMBER NUMBER IF NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP ...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
tableCnK = {} def CnK(n, k): if k == 0: return 1 if k == 1: return n if (n, k) not in tableCnK: tableCnK[n, k] = CnK(n, k - 1) * (n - k + 1) // k return tableCnK[n, k] table = {} def PathsInOneDim(x, steps, max_x): global table if x > max_x or x < 1: return ...
ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR IF...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
def f(di, xi, m): if not hasattr(f, "cache"): f.cache = [None] * 101 if f.cache[di] == None: f.cache[di] = [([-1] * 301) for i in range(di + 1)] if m == 0: res = 1 else: if f.cache[di][xi][m] == -1: f.cache[di][xi][m] = (f(di, xi - 1, m - 1) if xi > 0 else 0) ...
FUNC_DEF IF FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP LIST NONE NUMBER IF VAR VAR NONE ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NU...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
MOD = 10**9 + 7 def main(): ncases = int(input()) for case in range(ncases): ndim, nmoves = readints() x = readints() d = readints() assert ndim == len(x) == len(d) print(solve(nmoves, x, d)) def readints(): return list(map(int, input().split())) def solve(m, x,...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_C...
You are situated in an $n$ dimensional grid at position $\left(x[1],x[2],\ldots,x[n]\right)$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstr...
def fillOneDWalks(walksOneD, maxPoint): for size in maxPoint: if size in walksOneD: continue walksOneD[size] = walks1D(size, steps) def walks1D(size, steps): walks = [[(0) for s in range(0, steps + 1)] for origin in range(0, size + 1 + 1)] for origin in range(1, size + 1): ...
FUNC_DEF FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER F...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) l = [[*map(int, input().split())], [*map(int, input().split())]] dp = [0, 0] for i in range(n): new_dp = dp[:] new_dp[0] = max(new_dp[0], dp[1] + l[0][i]) new_dp[1] = max(new_dp[1], dp[0] + l[1][i]) dp = new_dp print(max(dp))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_C...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) r1 = [int(i) for i in input().split()] r2 = [int(i) for i in input().split()] dp1 = [0] * n dp2 = [0] * n dp1[0] = r1[0] dp2[0] = r2[0] for i in range(n - 1): if i < n - 2: dp1[i + 2] = max(dp1[i + 2], dp2[i] + r1[i + 2]) dp2[i + 2] = max(dp2[i + 2], dp1[i] + r2[i + 2]) dp1[i + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER I...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) dp = [[(0) for i in range(2)] for j in range(n + 2)] for i in range(1, n + 1): dp[i][0] = max(dp[i - 1][1] + l1[i - 1], dp[i - 1][0]) dp[i][1] = max(dp[i - 1][0] + l2[i - 1], dp[i - 1][1]) print(max(dp[n][0], dp[n][1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
dp = [[], []] def solve(T, N): dp[0].append(T[0][0]) dp[1].append(T[1][0]) for i in range(1, N): dp[0].append(T[0][i] + max(dp[1][i - 1], dp[1][i - 2] if i >= 2 else 0)) dp[1].append(T[1][i] + max(dp[0][i - 1], dp[0][i - 2] if i >= 2 else 0)) print(max(dp[0][-1], dp[1][-1])) n = int(...
ASSIGN VAR LIST LIST LIST FUNC_DEF EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
def CF1195C(): N = int(input()) r1 = tuple(map(int, input().split())) r2 = tuple(map(int, input().split())) r1sum = r1[-1] r2sum = r2[-1] for i in range(N - 2, -1, -1): r1sum, r2sum = max(r1[i] + r2sum, r1sum), max(r2[i] + r1sum, r2sum) return max(r1sum, r2sum) res = CF1195C() prin...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR ...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) x = y = 0 for i in range(n): x, y = max(x, y + a[i]), max(y, x + b[i]) print(max(x, y))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) r1 = [int(i) for i in input().split(" ")] r2 = [int(i) for i in input().split(" ")] stat = [-1] * 240000 rm1 = r1[-1] rm2 = r2[-1] for i in range(n - 2, -1, -1): nrm1 = max(rm1, rm2 + r1[i]) nrm2 = max(rm2, rm1 + r2[i]) rm1 = nrm1 rm2 = nrm2 print(max(rm1, rm2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CA...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
def solve(): n = int(input()) t1 = list(map(int, input().split())) t2 = list(map(int, input().split())) t1_score = [(0) for i in range(n)] t2_score = [(0) for i in range(n)] n -= 1 t1_score[n] = t1[n] t2_score[n] = t2[n] n -= 1 while n >= 0: t1_score[n] = max(t2_score[n +...
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 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 VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR V...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ans = [a[n - 1], b[n - 1]] bans = [0, 0] for i in range(n - 2, -1, -1): bans[0] = max(a[i] + ans[1], ans[0]) bans[1] = max(b[i] + ans[0], ans[1]) ans[0] = bans[0] ans[1] = bans[1] bans[0] = 0 bans[1] = 0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
N = int(input()) line2 = list(map(int, input().split())) line3 = list(map(int, input().split())) h = [line2, line3] dp = [[(0) for a in range(4)] for b in range(N + 2)] for i in range(N): for row in range(1, 4): if row == 1: first = dp[i - 1][2] + h[0][i] second = dp[i - 1][3] + h[0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL ...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
input() c, d = 0, 0 for i, j in zip(map(int, input().split()), map(int, input().split())): c, d = max(c, d + i), max(d, c + j) print(max(c, d))
EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) a = [*map(int, input().split())] b = [*map(int, input().split())] cache1 = [a[0]] cache2 = [b[0]] for i in range(n - 1): cache1.append(max(cache1[i], cache2[i] + a[i + 1])) cache2.append(max(cache2[i], cache1[i] + b[i + 1])) print(max(cache1[-1], cache2[-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR ...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
def gns(): return list(map(int, input().split())) n = int(input()) ps = [] ps.append(gns()) ps.append(gns()) dp = [([0] * 2) for i in range(n)] def get(i, t): if i < 0: return 0 else: return dp[i][t] ans = 0 for i in range(n): for t in range(2): mx = max(get(i - 1, 1 - t), ...
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 LIST EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN VAR VAR VAR ASSIGN VAR N...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) m1 = l1[0] m2 = l2[0] ans = max(m1, m2) i = 1 while i < n: l1[i] = max(l1[i], l1[i] + m2) l2[i] = max(l2[i], l2[i] + m1) m1 = max(m1, l1[i]) m2 = max(m2, l2[i]) ans = max(ans, l1[i], l2[i]) i = i + 1 print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR B...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
from sys import stdin input = stdin.readline n = int(input()) h_1 = [int(i) for i in input().split()] h_2 = [int(i) for i in input().split()] max_h = [[(0) for i in range(n)] for j in range(2)] max_h[0][0] = h_1[0] max_h[1][0] = h_2[0] if n > 1: max_h[0][1] = h_1[1] + h_2[0] max_h[1][1] = h_2[1] + h_1[0] for i...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER A...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) arr1 = [int(i) for i in input().split()] arr2 = [int(i) for i in input().split()] maxleft = arr1[-1] maxright = arr2[-1] extra = 0 dp = [(0, 0) for i in range(n)] dp[n - 1] = maxleft, maxright ans = max(maxleft, maxright) for i in range(n - 2, -1, -1): if i + 2 < n: maxleft = max(maxleft, a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL ...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
try: while True: n = int(input()) dp = [([0] * 100005) for _ in range(2)] a = [([0] * n) for _ in range(2)] a[0] = list(map(int, input().split())) a[0].insert(0, 0) a[1] = list(map(int, input().split())) a[1].insert(0, 0) for i in range(1, n + 1): ...
WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR F...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
I = lambda: map(int, input().split()) n = I() temp = [0] * 3 for x, y in zip(I(), I()): c = max(temp[0], temp[1]) a = max(temp[1] + x, temp[2] + x, x) b = max(temp[0] + y, temp[2] + y, y) temp = [a, b, c] print(max(temp[0], temp[1]))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) v = [[int(i) for i in input().split()], [int(i) for i in input().split()]] dp = [[0] * (n + 1), [0] * (n + 1)] for i in range(1, n + 1): dp[0][i] = max(dp[0][i - 1], dp[1][i - 1] + v[0][i - 1]) dp[1][i] = max(dp[1][i - 1], dp[0][i - 1] + v[1][i - 1]) print(max(dp[0][n], dp[1][n]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR ...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
n = int(input()) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) if n == 1: print(max(a1[0], a2[0])) else: f = [a1[0], a2[0]] s = [a1[1] + f[1], a2[1] + f[0]] dp = [f, s] for i in range(2, n): an = [ max(dp[i - 1][1] + a1[i], dp[i - 2][1] + a1[i]), ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NU...