description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
def checkWordBreak(s, wordDict, idx, ans, arr): if idx == len(s): ans.append([] + arr) return for i in range(idx, len(s)): newStr = s[idx : i + 1] arr.append(newStr) if newStr in wordDict: checkWordBreak(s, wordDict, i + 1, ans, arr) arr.pop() ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR CLASS_DEF FUN...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): dictionary = {item: (True) for item in dict} dp = [list() for i in range(len(s))] for i in range(len(s)): word = "" for j in range(i, -1, -1): word = s[j] + word if dictionary.get(word):...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NU...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, d, s): d = set(d) ans = [] cans = [] def rec(i, w): if i == len(s): if w == "": ans.append(" ".join(cans)) return w1 = w + s[i] rec(i + 1, w1) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
def func(s, dic, temp, ans): if not s: ans.append(temp[:]) return for i in range(1, len(s) + 1): if s[:i] in dic: func(s[i:], dic, temp + [s[:i]], ans) class Solution: def wordBreak(self, n, dic, s): ans = [] func(s, dic, [], ans) re = [] ...
FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR LIST VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def __init__(self): self.ans = [] def wordBreak(self, n, dict, s): self.util(n, dict, list(s), [], []) return self.ans def util(self, n, dict, s, word, listOfWords): if s == [] and word == []: self.ans.append(" ".join(listOfWords)) r...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR LIST LIST RETURN VAR FUNC_DEF IF VAR LIST VAR LIST EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN IF VAR LIST RETURN EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL V...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dictionary, line): dic = {} for i in dictionary: dic[i] = 1 def manu(dic, word, f, a): if word == "": a.append(" ".join(f)) return True x = False for i in range(len(word))...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NU...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def util(self, s, d, ans): global a if len(s) == 0: a[ans] = 1 return for k in range(1, len(s) + 1): if d.get(s[:k]) != None: if len(ans) == 0: self.util(s[k:], d, ans + s[:k]) else: ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NONE IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR STRING VAR VAR RETURN FUNC...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class trieNode: def __init__(self): self.children = [None] * 26 self.isEnd = False class trie: def __init__(self): self.root = trieNode() def insert(self, word): r = self.root cnt = 1 for i in word: if r.children[ord(i) - ord("a")] == None: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR ASSIGN VAR VAR BIN_OP...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): N = len(s) dp = [[] for i in range(N + 1)] dp[0].append("") for i in range(1, N + 1): temp = "" lis = [] for j in range(i, 0, -1): temp = s[j - 1] + temp if temp in d...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR FOR VAR VAR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): mp = set() for i in dict: mp.add(i) res = [] def findsent(i, st, sent, s, mp): if i >= len(s): if st == "": res.append(sent) return if st + s[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP BIN_OP BIN_OP VAR STRING VAR VAR VAR VAR V...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): dp = {} def word_break(s): if s in dp: return dp[s] res = [] for word in dict: if s[: len(word)] == word: if len(s) == len(word): res.app...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR VAR VAR RETUR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, d, s, till=[]): if s == "": return [" ".join(till)] re = [] for x in range(1, len(s) + 1): select = s[:x] if select in d: re += self.wordBreak(n, d, s[x:], [*till, s[:x]]) return re
CLASS_DEF FUNC_DEF LIST IF VAR STRING RETURN LIST FUNC_CALL STRING VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR LIST VAR VAR VAR RETURN VAR
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): def solve(arr, st, l, res): if st == len(s): res.append(l[:]) for word in arr: if s[st : st + len(word)] == word: l.append(word) solve(arr, st + len(word), l, re...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER LIST VAR ASSIGN VAR FUNC_CALL STRING VAR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def word_machingII(self, str1, dict1, st, res, list1): if st == len(str1): res.append(list1[:-1]) return for end in range(st, len(str1) + 1): if str1[st:end] in dict1: self.word_machingII(str1, dict1, end, res, list1 + str1[st:end]...
CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR STRING FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): dict_set = set(dict) dp = [False] * (len(s) + 1) dp[0] = True for i in range(1, len(s) + 1): for j in range(i): if dp[j] and s[j:i] in dict_set: dp[i] = True break ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FUNC_CALL ...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): n = len(s) res = [] def rec(i=0, curr=[]): if i >= n: res.append(" ".join(curr)) temp = "" for idx in range(i, n): temp += s[idx] if temp in dict: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF NUMBER LIST IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR RETU...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dic, s): m = len(s) l = [[(True if j == 0 else False) for j in range(m + 1)] for i in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): x = len(dic[i - 1]) if x > j: contin...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR BIN_O...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): return self.break_sentence(dict, s) def break_sentence(self, words, sentence, slist=None, collect=None): if slist is None: slist = [] if collect is None: collect = [] if len(sentence) == 0: col...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_DEF NONE NONE IF VAR NONE ASSIGN VAR LIST IF VAR NONE ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, _dict, s): words = set(_dict) ans = [] slen = len(s) def backtrack(starti, arr): nonlocal ans, s, slen, words if starti == slen: ans.append(" ".join(arr)) for endi in range(starti, slen): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): def breakutil(s, x, res): for i in range(1, x + 1): if s[:i] in l: if i == x: ans.append(res + s[:i]) return breakutil(s[i:], x - i, res + s[...
CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR STRING ASSIGN VAR LIST ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING RETURN VAR
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): res = [] path = [] def backtrack(j): if j == len(s): res.append(" ".join(path)) for i in range(n): wordLength = len(dict[i]) if s[j : j + wordLength] != dict[i]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUM...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): dic = {} for ele in dict: dic[ele] = 1 ans = [] li = [] self.helper(dic, s, ans, li, len(s)) return ans def helper(self, dic, s, ans, li, l): if l == 0: ans.append(" ".join(ele for ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): d = {} for i in dict: d[i] = d.get(i, 0) + 1 final = [] temp = "" self.solutions(s, d, n, final, temp) return final def solutions(self, s, d, n, final, temp): if s == "": final.appe...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR STRING EXPR FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUM...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): self.sentences = [] self.dict = set(dict) self.s = s self.n = len(s) self.makeSentences(0, "", []) return self.sentences def makeSentences(self, index, word, sentence): if index >= self.n: if w...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING LIST RETURN VAR FUNC_DEF IF VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP VAR LIST...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, d, s): d = set(d) pre = set() for word in d: for i in range(1, len(word) + 1): pre.add(word[:i]) def count(s): ans = [] for i in range(1, len(s) + 1): word = s[:i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR IF VAR FUNC_CALL VAR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): list = [] sett = set(dict) Solution.traverse(0, list, s, sett, "") return list @staticmethod def traverse(index, list, s, sett, str): if index >= len(s): list.append(str) else: for i in...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR VAR STRING RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def solve(self, ans, curr, i, dict, s): temp = s[:i] if i == len(s): if temp in dict: ans.append(" ".join(curr + [temp])) return if temp not in dict: self.solve(ans, curr, i + 1, dict, s) return curr.app...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR LIST VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR V...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): res = [] def backtrack(bag, s_): nonlocal res if len(s_) == 0: res.append(" ".join(bag[:])) return for i in range(0, len(s_)): prefix = str(s_[: i + 1]) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CAL...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): def func(ind, nn, res, ans, dict): if ind == nn: res.append(ans[:-1]) return for i in range(ind, nn + 1): if s[ind:i] in dict: func(i, nn, res, ans + s[ind:i] + " ",...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR STRING VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VA...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def __init__(self): self.ans = [] def wordBreak(self, n, Dict, s): l = len(s) dp = [0] * l for i in range(l): arr = [] for j in range(i + 1, l + 1): if s[i:j] in Dict: arr.append(s[i:j]) dp[...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FU...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): sentence = [] sentences = [] self.wordBreakUtil(s, 0, sentence, sentences, dict, len(s)) sentences = [" ".join(word) for word in sentences] return sentences def wordBreakUtil(self, input, prev, sentence, sentences, dict, ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FU...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, d, s): ans = [] m = len(s) flag = [[(False) for _ in range(m)] for _ in range(m)] for i in range(m): for j in range(m): if s[i : j + 1] in d: flag[i][j] = True def solve(start, ans, temp,...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR RETURN FOR VA...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordbreak(self, n, dict, s): if s == "": if self.temp == "": return self.ans.append(self.temp[:-1]) for i in range(len(s)): if s[: i + 1] in dict: self.temp += s[: i + 1] self.temp += " " ...
CLASS_DEF FUNC_DEF IF VAR STRING IF VAR STRING RETURN EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST A...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): ind = 0 ans = "" res = [] def getAns(ind, ans, res): if ind == len(s): res.append(ans) return for i in range(ind, len(s)): if s[ind : i + 1] in dict: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR STRING STRING STRING VAR VAR BIN_OP VAR NUMBER VA...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): dict = set(dict) m = len(s) ans = [] cans = [] def rec(i, w): if i == m: if w == "": ans.append(" ".join(cans)) return temp = w + s[i] if...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR EXP...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): wordset = set(dict) res = [] def word(ind=0, path=[]): if ind == len(s): res.append(" ".join(path)) for j in range(ind + 1, len(s) + 1): words = s[ind:j] if words in wor...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF NUMBER LIST IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR LIST VAR EXPR FUNC_CALL VAR RE...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def search(self, word, dict): if word in dict: return True return False def solve(self, start, end, s, dict, words, ans): if start > end: ans.append(words[:]) return for i in range(start, end + 1): if self.search(s...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, words, s): ans = [] rec(s, words, [], ans) return ans def rec(s, words, acc, ans): if not s: ans.append(" ".join(acc)) return for w in words: if s.startswith(w): acc.append(w) rec(s[len(w) :], w...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR LIST VAR RETURN VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): res = [] def backtrack(pos, sub, s): if pos == len(s): copy = " ".join(sub) res.append(copy) return for idx in range(pos, len(s)): temp = s[pos : idx + 1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): n = len(s) ans = [] def solve(idx, curr, n): if idx == n: ans.append(" ".join(curr.copy())) return for i in range(idx, n + 1): substr = s[idx : i + 1] if...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: sents = [] def wordBreak(self, n, dictionary, line): self.sents = [] r = "" self.sol(line, dictionary, 0, r) return self.sents def sol(self, line, dic, i, r): if i == len(line): if r[0] == " ": r = r[1:] self.s...
CLASS_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER VAR RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, wordDict, s): ans = [] def backtrack(idx, word, spaces): if idx == len(s) and len(word) - spaces == len(s): ans.append(word[1:]) return if idx > len(s): return for w in wordDi...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN IF VAR FUNC_CALL VAR VAR RETURN FOR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): ans = [] def recurbreak(string, m, result): for i in range(1, m + 1): prefix = string[:i] if prefix in dict: if i == m: result += prefix ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING RETURN VAR
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, d, s): def WordBreak(indx, n, dict, s, curr, ans): if indx == n: ans.append(curr) return str = "" for i in range(indx, n): str += s[i] if str in dict: ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VA...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Node: def __init__(self, val): self.val = val self.children = [None for _ in range(26)] self.eow = False class Trie: def __init__(self): self.root = Node(-1) def insert(self, word, node=None, i=0): if node is None: node = self.root c = w...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF NONE NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR IF ...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
def word_break_util(input_string, result_arr: [], input_dict: {}, output_string): if len(input_string) == 0: if output_string != "": result_arr.append(output_string) return n = len(input_string) for i in range(0, n): word = input_string[0 : i + 1] if word in input...
FUNC_DEF LIST DICT IF FUNC_CALL VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING FUNC_DEF LIST DICT ASSIG...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): def wordbreakUtil(ind, dict, s, temp): if ind == len(s): res.append(temp[:]) return t = "" for i in range(ind, len(s)): t += s[i] if t in dict: ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR RETURN ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER VAR VAR LIST...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
def words(dict, s, cur, ans): if s == "": ans.append(cur[0 : len(cur) - 1]) for i in range(1, len(s) + 1): if s[0:i] in dict: words(dict, s[i:], cur + s[0:i] + " ", ans) class Solution: def wordBreak(self, n, dict, s): ans = [] words(dict, s, "", ans) r...
FUNC_DEF IF VAR STRING EXPR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR STRING VAR RETU...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, store, s): return self.helper(s, store, "") def helper(self, s, store, output): if not s: return [output[:-1]] result = [] for item in store: n = len(item) if s[:n] == item: result += sel...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR STRING FUNC_DEF IF VAR RETURN LIST VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR STRING RETURN VAR
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Node: def __init__(self): self.map = {} self.isWord = False class Trie: def __init__(self): self.head = Node() self.ans = [] def insert(self, word): temp = self.head for i in word: if i not in temp.map: temp.map[i] = Node...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF STRING IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN ASSIGN VAR VAR FOR VAR FUNC_CAL...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): def backtrack(s, n, dict, index, output): if index == len(s): result.append(" ".join(output)) return for word in dict: if index + len(word) <= len(s) and s[index : index + len(word)] ==...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR ...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def search(self, word, dict): if word in dict: return True return False def solve(self, start, end, s, word_map, words, ans): if start > end: ans.append(words[:]) return for i in range(start, end + 1): if word_map....
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): ans = [] def func(i, st): if i == len(s): ans.append(st[:-1]) return for j in range(i, len(s) + 1): if s[i:j] in dict: func(j, st + s[i:j] + " ") fu...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER STRING RETURN VAR
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, m, dic, s): global ans ans = [] n = len(s) solve(dic, n, s, 0, "") return ans def solve(dic, n, s, i, res): if i == n: ans.append(res.strip()) return for j in range(i, n): wd = s[i : j + 1] if wd i...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER STRING RETURN VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dict, s): return self.explore(s, dict, {}) def explore(self, target, wordbank, memo): if target == "": return [""] if target in memo: return memo[target] res = [] for word in wordbank: if target....
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR DICT FUNC_DEF IF VAR STRING RETURN LIST STRING IF VAR VAR RETURN VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL STRING LIST VAR VAR ASSIGN VA...
Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples for better understanding. Example 1: Input: s = "catsanddog", n = 5 dict ...
class Solution: def wordBreak(self, n, dicti, s): wordSet = set(dicti) res = [] def backtrack(i, j, temp): if i == len(s) - 1 or j == len(s) - 1: if s[i : j + 1] in wordSet: z = temp + " " + s[i : j + 1] res.append(z[1:]) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FU...
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse. He's got problems wi...
n, m = map(int, input().split()) swapped = False if n < m: n, m = m, n swapped = True ans = "" if n == 1 and m == 1: ans = "0\n." if n == 2 and m == 1: ans = "0\n.\n." if n == 2 and m == 2: ans = "0\n..\n.." if n == 3 and m == 1: ans = "0\n.\n.\n." if n == 3 and m == 2: ans = "0\n..\n..\n.."...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF ...
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse. He's got problems wi...
r = {} r[1, 1] = "0\n.\n" r[1, 2] = "0\n..\n" r[1, 3] = "0\n...\n" r[1, 4] = "0\n....\n" r[1, 5] = "0\n.....\n" r[1, 6] = "0\n......\n" r[1, 7] = "0\n.......\n" r[1, 8] = "0\n........\n" r[1, 9] = "0\n.........\n" r[2, 2] = "0\n..\n..\n" r[2, 3] = "0\n...\n...\n" r[2, 4] = "0\n....\n....\n" r[2, 5] = "0\n.....\n.....\n...
ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBE...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
R = lambda: map(int, input().split()) I = 10**10 n = int(input()) s, c = list(R()), list(R()) r = min( c[j] + min([I] + [c[i] for i in range(j) if s[i] < s[j]]) + min([I] + [c[i] for i in range(j + 1, n) if s[i] > s[j]]) for j in range(n) ) print((r, -1)[r > I])
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FU...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) a, b = 1000000000000000.0, 1000000000000000.0 ans = 1000000000000000.0 for i in range(1, n): a, b = 1000000000000000.0, 1000000000000000.0 for j in range(0, i): if s[i] > s[j]: a = min(a, c[j]) for j...
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VA...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) INF = 10**18 dp2 = [INF] * n for i in range(n): for j in range(0, i): if s[i] > s[j] and dp2[i] > c[i] + c[j]: dp2[i] = c[i] + c[j] dp3 = [INF] * n for i in range(n): for j in range(0, i): if s[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 ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VA...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) num = float("inf") rec1 = [float("inf")] * n rec2 = [float("inf")] * n for i in range(n): for j in range(i + 1, n): if s[i] < s[j] and rec1[i] > c[j]: rec1[i] = c[j] for i in range(1, n): for j in range(...
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 FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL V...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = [int(i) for i in input().split()] c = [int(i) for i in input().split()] dp = [[float("inf") for _ in range(4)] for _ in range(n)] for i in range(n): dp[i][1] = c[i] for i in range(n): for j in range(1, 4): for r in range(i): if s[r] < s[i]: dp[i][j] = min...
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 FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VA...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().strip().split())) c = list(map(int, input().strip().split())) dp = [float("inf") for i in range(n)] for i in range(n): for j in range(i): if s[j] < s[i]: dp[i] = min(dp[i], c[i] + c[j]) dp2 = [float("inf") for i in range(n)] for i in range(n): for j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR AS...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
def solve(n, s, c): INF = float("inf") ans = INF for i in range(n): first = INF for j in range(i): if s[j] < s[i]: first = min(first, c[j]) if first == INF: continue second = INF for j in range(i + 1, n): if s[i] < s...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSI...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
import sys def get_ints(): return list(map(int, sys.stdin.readline().strip().split())) def solve(N, S, C): dp = [float("inf")] * N for i in range(1, N): for j in range(i): if S[j] < S[i]: dp[i] = min(dp[i], C[j] + C[i]) dp2 = [float("inf")] * N for i in range(...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) l = list(map(int, input().split())) l1 = list(map(int, input().split())) ans = [] j = 1 while j < n - 1: m1 = m2 = 2000000000.0 i = j - 1 k = j + 1 while i >= 0: if l[i] < l[j]: m1 = min(m1, l1[i]) i -= 1 while k < n: if l[k] > l[j]: m...
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 ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) dp = [float("inf")] * n for i in range(1, n): mn = float("inf") for j in range(i): if s[i] > s[j]: mn = min(mn, c[i] + c[j]) dp[i] = mn res = float("inf") for i in range(1, n): for j in range(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 ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR V...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) minCost = float("inf") for j in range(1, n - 1): curr = s[j] minLs = float("inf") minMax = float("inf") for i in range(j): if s[i] < curr: minLs = min(minLs, c[i]) for i in range(j + 1, n): ...
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 FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_C...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
ans = float("inf") n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(n): b = -1 c_ = c[i] for j in range(i): if s[j] >= s[i]: continue if b == -1 or c[b] > c[j]: b = j if b == -1: continue c_ += c[b...
ASSIGN VAR FUNC_CALL VAR STRING 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
R = lambda: [int(i) for i in input().split()] I = 10**9 n = int(input()) s, c = R(), R() r = I for j in range(n): t1 = I for i in range(j): if s[i] < s[j]: t1 = min(t1, c[i]) t2 = I for i in range(j + 1, n): if s[i] > s[j]: t2 = min(t2, c[i]) r = min(c[j] + t1...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) ss = list(map(int, input().strip().split())) cs = list(map(int, input().strip().split())) dp = [([float("inf")] * 4) for _ in range(n + 1)] for i in range(1, n + 1): dp[i][1] = cs[i - 1] for i in range(2, n + 1): for j in range(2, 4): s, c = ss[i - 1], cs[i - 1] for k in range(1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
class SegTree: def __init__(self, init_val, ide_ele, segfunc): self.n = len(init_val) self.num = 2 ** (self.n - 1).bit_length() self.ide_ele = ide_ele self.segfunc = segfunc self.seg = [ide_ele] * 2 * self.num for i in range(self.n): self.seg[i + self.num...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR V...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) dp2 = [float("inf") for i in range(n)] dp3 = [float("inf") for i in range(n)] for i in range(1, n): j = i - 1 while j >= 0: if s[j] < s[i]: dp2[i] = min(c[i] + c[j], dp2[i]) j -= 1 ans = float("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 ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) S = [int(x) for x in input().split(" ")] C = [int(x) for x in input().split(" ")] dp = [float("inf")] * n ans = float("inf") for i in range(n): for j in range(i + 1, n): if S[j] > S[i] and C[j] < dp[i]: dp[i] = C[j] for i in range(n): for j in range(i + 1, n): if S[j...
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 FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
def main(): n, inf, res = int(input()), 9000000000.0, [] ss = list(map(float, input().split())) cc = list(map(float, input().split())) tmp = [(ss[0], cc[0])] for s, c in zip(ss[1:-1], cc[1:-1]): res.append(min((b for a, b in tmp if a < s), default=inf) + c) tmp.append((s, c)) res...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER LIST 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 NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
class Display: def __init__(self, index, size, cost): self.index = index self.size = size self.cost = cost self.totalcost = cost self.next = None self.level = 0 def nextcycle(displays, level): for j in range(n): displays[j].next = None for k in ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR NONE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR NONE ASSIGN...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s1 = list(map(int, input().split())) s2 = list(map(int, input().split())) cn = 300000001 ext = 0 for i in range(1, n - 1): indj = s1[i] vali, valk, valj = 100000001, 100000001, s2[i] for j in range(0, i): if s1[j] < indj: if s2[j] < vali: vali = s2[j] ...
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR FOR ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) ans = 10**10 for j in range(1, n - 1): now_ans = c[j] money = 10**10 for i in range(j): if s[i] < s[j]: money = min(money, c[i]) if money == 10**10: pass now_ans += money money = ...
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 BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) arr = list(map(int, input().split())) cost = list(map(int, input().split())) ans = 10**10 for i in range(1, n - 1): cur = arr[i] l, r = 10**10, 10**10 for j in range(i - 1, -1, -1): if arr[j] < cur: l = min(l, cost[j]) for j in range(i + 1, n): if arr[j] > cu...
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 BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = (10**9 + 1) * 3 m = 10**9 + 1 m1 = 10**9 + 1 t = 0 for i in range(0, n): m = 10**9 + 1 m1 = 10**9 + 1 su = b[i] for j in range(0, i): if a[j] < a[i]: m = min(m, b[j]) for j in range(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 ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NU...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1): n = nmbr() a = lst() b = lst() ans = PI = float("inf") dp = [[PI for _ in range(4)] for _ in range(n)] for i in range(n): dp[i][1] = b[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
class node: def __init__(self): self.id = 0 self.c = 0 self.s = 0 n = int(input()) p = [node() for i in range(n)] for i in range(n): p[i].id = i a = list(map(int, input().split())) for i in range(n): p[i].s = a[i] a = list(map(int, input().split())) for i in range(n): p[i].c =...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1): n = nmbr() a = lst() b = lst() dp = [0] * n for i in range(n): v = float("inf") for j in range(i + 1, n): if a[j] > a[i]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) j1 = [float("inf")] * n j2 = [float("inf")] * n for i in range(n): for j in range(i + 1, n): if a[i] < a[j]: j1[j] = min(j1[j], b[i] + b[j]) for i in range(n): for j in range(i + 1, n): if a[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 ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) l = list(map(int, input().split())) v = list(map(int, input().split())) d = dict() for i in range(n): take = [] for j in range(i + 1, n): if l[i] < l[j]: take.append(v[j]) d[i] = sorted(take) mini = 99999999999 for i in range(n): sum1 = v[i] for j in range(i + 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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VA...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
from sys import stdin n = int(stdin.readline()) size = list(map(int, stdin.readline().split())) price = list(map(int, stdin.readline().split())) temp = [3 * 10**8 + 1] * n ans = [3 * 10**8 + 1] * n for i in range(n): for j in range(i + 1, n): if size[i] >= size[j]: continue temp[j] = mi...
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 BIN_OP LIST BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
def fxn1(arr, ls, j, m1=10**9): for i in range(0, j): if arr[i] < arr[j]: m1 = min(m1, ls[i]) return m1 def fxn2(arr, ls, j, m2=10**9): for k in range(j + 1, len(arr)): if arr[k] > arr[j]: m2 = min(m2, ls[k]) return m2 t1 = 10**9 t2 = 10**9 z = 10**9 n = int(i...
FUNC_DEF BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASS...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
from sys import stdin, stdout inf = 3000000000.0 n = int(input()) s = [int(x) for x in input().strip().split(" ")] c = [int(x) for x in input().strip().split(" ")] dp1 = [inf for x in s] dp2 = [inf for x in s] for i in range(1, n - 1): for j in range(0, i): if s[j] < s[i]: dp1[i] = min(dp1[i], ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) S = [int(x) for x in input().split(" ")] C = [int(x) for x in input().split(" ")] bestCost = float("inf") for i in range(len(S)): minLeft = float("inf") minRight = float("inf") for j in range(i): if S[j] < S[i] and C[j] < minLeft: minLeft = C[j] if minLeft == float("...
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 FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) ar = list(map(int, input().split())) ar1 = list(map(int, input().split())) ans3 = 10**18 for i in range(n): ans1 = 10**9 + 1 ans2 = 10**9 + 1 for j in range(i - 1, -1, -1): if ar[i] > ar[j]: ans1 = min(ans1, ar1[j]) for j in range(i + 1, n): if ar[i] < ar[j]:...
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 BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMB...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
inf = 1234567890 class fenwick: def __init__(self, n): self.n = n self.f = [inf] * n def get(self, x): i = x ret = inf while i >= 0: ret = min(ret, self.f[i]) i = (i & i + 1) - 1 return ret def add(self, x, y): i = x ...
ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
import sys n = int(input().strip()) sizes = list(map(int, input().strip().split())) cost = list(map(int, input().strip().split())) tot = [] for i in range(n): tot.append([sizes[i], cost[i]]) ret = False lcomp = [] for j in range(len(tot)): if j > 0 and j < len(tot) - 1: temp1 = tot[:j] temp2 = ...
IMPORT 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) S = [int(x) for x in input().split()] s = tuple(S) c = tuple(int(x) for x in input().split()) S.sort() def min(x, y): if x < y: return x else: return y def rank(x): l = 0 r = n - 1 while l < r: mid = l + r >> 1 if S[mid] < x: l = mid +...
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE V...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
def main(): n = int(input()) s = [int(x) for x in input().split()] c = [int(x) for x in input().split()] Max = 2 * sum(c) f = [x for x in c] for _ in range(2): for i in range(n - 1, -1, -1): min_fj = Max for j in range(i): if s[j] < s[i]: ...
FUNC_DEF 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 NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VA...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) ans = float("inf") dp = [[float("inf") for x in range(3)] for u in range(len(s) + 1)] for i in range(len(s)): dp[i][0] = c[i] for j in range(1, 3): dp[i][j] = float("inf") for k in range(i): if s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
import sys inf = float("inf") abc = "abcdefghijklmnopqrstuvwxyz" abd = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7, "i": 8, "j": 9, "k": 10, "l": 11, "m": 12, "n": 13, "o": 14, "p": 15, "q": 16, "r": 17, "s": 18, "t": ...
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NU...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
INF = 10000000000 n = int(input()) s = list(map(int, input().split())) c = list(map(int, input().split())) min_v = INF for j in range(1, n): left = INF for i in range(j): if s[j] > s[i]: left = min(left, c[i] + c[j]) curr = INF for k in range(j + 1, n): if s[k] > s[j]: ...
ASSIGN 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL ...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
def read_line(): return [int(x) for x in input().split()] def read_int(): return int(input()) def solve(): n = read_int() a = read_line() b = read_line() res = 1e18 for j in range(n): cost = [1e18, 1e18] for i in range(0, j): if a[i] < a[j]: co...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSI...
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
import sys imput = sys.stdin.readline class SegmentTree: def __init__(self, n): self.n = n self.INF = 2**31 - 1 self.size = 1 while self.size < n: self.size *= 2 self.node = [self.INF] * (2 * self.size - 1) def update(self, i, val): i += self.size...
IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN...