description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
A.sort()
self.ans = 0
def check(A, i, path):
return int((A[i] + path[-1]) ** 0.5 + 0.0) ** 2 == A[i] + path[-1]
def dfs(A, path):
if not A:
self.ans += 1
retur... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR FUN... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def dfs(self, pos):
if pos == self.n:
self.ans += 1
return
last = None
for i, val in enumerate(self.a):
if self.usable[i]:
if val == last:
continue
if pos - 1 >= 0 and val + self.rec[pos ... | CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER RETURN ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_DEF VAR VAR ASSIGN ... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A):
A.sort()
N = len(A)
graph = [([0] * N) for _ in range(N)]
for i in range(N):
for j in range(N):
if i == j:
continue
if int((A[i] + A[j]) ** 0.5) ** 2 == A[i] + A[j]:
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VA... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
d = defaultdict(int)
res = 0
ps = {}
i = 0
while i * i <= 2 * max(A):
ps[i * i] = True
i += 1
def ok(x):
return x in ps
def solve(x):
nonlocal ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER FUNC_DEF RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | def getPermutations(array):
ans = set()
def helper(arr, i, ans):
if i == len(arr) - 1:
ans.add(tuple(arr))
return
for j in range(i, len(arr)):
if not (arr[i] == arr[j] and i != j):
test = i <= 1 or (arr[i - 1] + arr[i - 2]) ** 0.5 == int(
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
A.sort()
n = len(A)
visited = [False] * n
res = []
self.count = 0
def dfs(curr):
if len(curr) == n:
self.count += 1
return
for i in range(n):
... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR N... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
def edge(x, y):
return int((x + y) ** 0.5) ** 2 == x + y
def dfs(x, t):
count[x] -= 1
if t == 0:
ans = 1
else:
ans = 0
for y in graph[x... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR FUNC_DEF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA... |
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.
Your input will be... | class Solution:
def makesquare(self, nums):
if len(nums) < 4:
return False
length = sum(nums)
if length % 4:
return False
length = int(length / 4)
nums.sort(reverse=True)
if length < nums[0]:
return False
elif length == num... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR LIST NUMBER NUMBER VAR NUMBER AS... |
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.
Your input will be... | class Solution:
def makesquare(self, nums):
def checkv(t, c, nums, used):
if t == 0:
return True
if t < 0:
return False
while c < len(nums) and used[c]:
c = c + 1
if c >= len(nums):
return False... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NU... |
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.
Your input will be... | class Solution:
def makesquare(self, nums):
total = sum(nums)
if total % 4 != 0 or len(nums) < 4:
return False
size = total / 4
nums.sort(reverse=True)
used = [False] * len(nums)
def dfs(i, expect):
if i >= len(nums):
return e... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR BIN_OP ... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
limit = Counter(letters)
n = len(words)
subsets = []
def back(i, curr):
if i == n:
subsets.append(curr)
return
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
res = []
i = 0
letters = collections.Counter(letters)
res = [0]
self.dfs(i, words, letters, score, 0, res)
return res[0]
def dfs(self, i, words,... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR RETURN VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSI... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
let = Counter(letters)
sc = {}
for i in range(26):
sc[chr(i + ord("a"))] = score[i]
word = {}
for w in words:
word[w] = Counter(w)
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FO... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
def letterScore(c):
return score[ord(c) - ord("a")]
def helper(i, remaining, scoreSoFar):
if not remaining or i == len(words):
return score... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF IF VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
max_score = 0
word_limits = Counter(letters)
def helper(curr, chars, curr_words):
nonlocal max_score
if curr >= len(words):
if chars... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUN... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
lcnt = Counter(letters)
words = [w for w in words if all(Counter(w)[l] <= lcnt[l] for l in w)]
al = "abcdefghijklmnopqrstuvwxyz"
scores = {w: sum(score[al.index(l)] ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
def solve(idx, counter):
if idx == len(words):
return 0
wc = collections.Counter(words[idx])
if all(counter[key] >= wc[key] for key in w... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
lettersCounter = collections.Counter(letters)
scoreDict = {
letter: score for letter, score in zip("abcdefghijklmnopqrstuvwxyz", score)
}
self.cache = [{... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR DICT VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL V... |
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
It is not necessary to use all characters in letters and each letter can only be used once. ... | class Solution:
def maxScoreWords(
self, words: List[str], letters: List[str], score: List[int]
) -> int:
n = len(words)
m = len(letters)
letters = collections.Counter(letters)
ans = 0
for i in range(1, n + 1):
combinations = list(itertools.combinatio... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR F... |
In LeetCode Store, there are some kinds of items to sell. Each item has a price.
However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
You are given the each item's price, a set of special offers, and the number we need to buy for each item... | class Solution:
def shoppingOffers(self, price, special, needs):
d = {}
n = len(needs)
def minp(needs, d):
if str(needs) in d:
return d[str(needs)]
res = 0
for i in range(n):
res += price[i] * needs[i]
for s in... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_... |
In LeetCode Store, there are some kinds of items to sell. Each item has a price.
However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
You are given the each item's price, a set of special offers, and the number we need to buy for each item... | class Solution:
def shoppingOffers(self, price, special, needs):
res = 0
for pric, need in zip(price, needs):
res += pric * need
for offer in special:
clone = list(needs)
i = 0
while i < len(needs):
diff = clone[i] - offer[i]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR ... |
In LeetCode Store, there are some kinds of items to sell. Each item has a price.
However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
You are given the each item's price, a set of special offers, and the number we need to buy for each item... | class Solution:
def shoppingOffers(self, price, special, needs):
a = 0
n = len(needs)
for i in range(n):
a += needs[i] * price[i]
for s in special:
new_needs = needs.copy()
check = True
for i in range(n):
new_needs[i] =... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR... |
In LeetCode Store, there are some kinds of items to sell. Each item has a price.
However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
You are given the each item's price, a set of special offers, and the number we need to buy for each item... | class Solution:
def shoppingOffers(self, price, special, needs):
def directPurchase(price, needs):
total = 0
for i in range(len(needs)):
total += price[i] * needs[i]
return total
def dfs(price, special, needs, index):
local_min = dir... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR LIST ... |
In LeetCode Store, there are some kinds of items to sell. Each item has a price.
However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
You are given the each item's price, a set of special offers, and the number we need to buy for each item... | class Solution:
def shoppingOffers(self, rps, sos, tq):
if len(sos) < 1:
return sum([(x * y) for x, y in zip(rps, tq)])
so = sos.pop()
m = self.shoppingOffers(rps, sos, tq)
ss = so[:]
while all([(x <= y) for x, y in zip(ss, tq)]):
rq = [(x - y) for x,... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_... |
In LeetCode Store, there are some kinds of items to sell. Each item has a price.
However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
You are given the each item's price, a set of special offers, and the number we need to buy for each item... | class Solution:
def shoppingOffers(self, price, special, needs):
def dfs(curr, special, needs):
p = curr + sum(p * needs[i] for i, p in enumerate(price))
for si in range(len(special)):
s = special[si]
if all(n >= s[i] for i, n in enumerate(needs)):
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR V... |
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1
The number at the ith position is divisible by i.
i is divisible by the number at the ith position.
Now given N, how man... | class Solution:
def countArrangement(self, N):
cache = {}
def helper(i, X):
if i == 1:
return 1
key = i, X
if key in cache:
return cache[key]
total = sum(
helper(i - 1, X[:j] + X[j + 1 :])
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR RETURN FU... |
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1
The number at the ith position is divisible by i.
i is divisible by the number at the ith position.
Now given N, how man... | class Solution:
def __init__(self):
self._cache = {}
def countArrangement(self, N):
return self.countHelper(N, tuple(range(1, N + 1)))
def countHelper(self, i, array):
if i == 1:
return 1
key = i, array
if key in self._cache:
return self._ca... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR... |
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1
The number at the ith position is divisible by i.
i is divisible by the number at the ith position.
Now given N, how man... | class Solution:
def countArrangement(self, N):
return (1, 2, 3, 8, 10, 36, 41, 132, 250, 700, 750, 4010, 4237, 10680, 24679)[
N - 1
] | CLASS_DEF FUNC_DEF RETURN NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER BIN_OP VAR NUMBER |
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1
The number at the ith position is divisible by i.
i is divisible by the number at the ith position.
Now given N, how man... | class Solution:
def countArrangement(self, N):
d = {
(1): 1,
(2): 2,
(3): 3,
(4): 8,
(5): 10,
(6): 36,
(7): 41,
(8): 132,
(9): 250,
(10): 700,
(11): 750,
(12): 401... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR |
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence (or, shortly, an RBS) is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example:
* bracket sequen... | import sys
from sys import stdin
n = int(stdin.readline())
s = [list(stdin.readline()[:-1]) for i in range(n)]
smin = [0] * n
smnum = [0] * n
h = [0] * n
cnts = [{} for i in range(n)]
for i in range(n):
ts = s[i]
nmin = 0
nh = 0
for c in ts:
if c == "(":
nh += 1
else:
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASS... |
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence (or, shortly, an RBS) is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example:
* bracket sequen... | def solve():
n = int(input())
a = [[0] for i in range(n)]
mb = [0] * (1 << n)
for i in range(n):
s = input().strip()
m = 0
b = 0
for c in s:
if c == "(":
b += 1
else:
b -= 1
if b <= 0:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VA... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def shouldntwe(vals, wanted):
d = {}
def shouldwe(indx, wanted):
if (indx, wanted) in d:
return d[indx, wanted]
if indx == 0:
if wanted - vals[indx] == 0:
return 1
else:
return 0
if wanted == 0:
return 1
... | FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR ... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def solve(n, m, notes):
if m < 0:
return False
if m == 0:
return True
ncopy = notes[:]
for note in notes:
ncopy.remove(note)
if solve(n - 1, m - note, ncopy):
return True
ncopy += [note]
for t in range(int(input())):
n, m = map(int, input().split... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST F... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | from itertools import combinations
t = int(input())
for i in range(t):
n, m = map(int, input().split())
a = []
count = 0
for i in range(n):
a.append(int(input()))
for i in range(1, n + 1):
if count == 1:
break
for j in combinations(a, i):
if sum(j) ==... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def resuo(nums, act):
n = len(nums)
sol = []
count = 1 << n
for mask in range(count):
ans = []
for i in range(n):
if mask & 1 << i != 0:
ans.append(nums[i])
sol.append(sum(ans))
for i in sol:
if i == act:
return "Yes"
return... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR RETURN STRING RETURN STRING FUNC_DEF ASSIGN... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def fun(m, l):
if m == 0:
return True
elif m < 0:
return False
if len(l) == 0:
return False
for i in range(len(l)):
l1 = l.copy()
m1 = m - l1[i]
del l1[i]
s = fun(m1, l1)
if s:
return s
return False
for _ in range(int(inpu... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | import itertools
t = int(input())
for i in range(t):
n, m = map(int, input().split())
ans = []
comb = []
flag = 0
for j in range(n):
k = int(input())
if k <= m:
ans.append(k)
for g in range(len(ans) + 1):
comb_obj = itertools.combinations(ans, g)
comb... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | for i in range(int(input())):
n, s = [int(i) for i in input().split()]
arr = [int(input()) for i in range(n)]
dp = [[(0) for i in range(s + 1)] for j in range(n + 1)]
for i in dp:
i[0] = 1
for i in range(1, n + 1):
for j in range(1, s + 1):
if j < arr[i - 1]:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | for _ in range(int(input())):
n, m = map(int, input().split())
a = []
yes = False
for _ in range(n):
x = int(input())
if x <= m:
a.append(x)
ans = 0
for i in range(1, pow(2, len(a))):
for j in range(len(a)):
if i & 1 << j:
ans += a[... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VA... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | test = int(input())
for i in range(test):
n, m = map(int, input().split())
arr = []
for i in range(n):
arr.append(int(input()))
def subs(arr):
subs = [[]]
dp = []
for elem in arr:
for i in range(len(subs)):
a = subs[i] + [elem]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST LIST ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR ... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | import itertools
for t in range(int(input())):
n, m = map(int, input().split())
a = []
for _ in range(n):
b = int(input())
a.append(b)
pay = "No"
for k in range(1, n + 1):
for l in itertools.combinations(a, k):
if sum(l) == m:
pay = "Yes"
... | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | import sys
sys.setrecursionlimit(2**30)
def ans(start, arr, t):
if start == len(arr) and t == 0:
return True
if start == len(arr) and t != 0:
return False
if start > len(arr):
return False
if t == 0:
return True
elif arr[start] > t:
return ans(start + 1, ar... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUM... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | for t in range(0, int(input())):
n, k = map(int, input().split())
arr = []
for i in range(0, n):
j = int(input())
if j <= k:
arr.append(j)
total = 0
c = 0
n = len(arr)
for i in range(0, 2**n):
total = 0
for j in range(0, n):
if 1 << j &... | FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL V... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def sub(l, i, curr_sum, k):
if i == len(l):
if curr_sum == k:
return True
else:
return False
if curr_sum == k:
return True
inc = sub(l, i + 1, curr_sum + l[i], k)
exc = sub(l, i + 1, curr_sum, k)
return inc or exc
for _ in range(int(input())):
n,... | FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | from itertools import chain, combinations
t = int(input())
def powerset(list_name):
s = list(list_name)
l = []
for i in range(1, len(list_name) + 1):
for x in combinations(s, i):
l.append(x)
return l
for _ in range(t):
n, m = map(int, input().split())
dp = [-1] * 20000
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP L... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def solve():
n, amt = map(int, input().split())
dp = [([0] * (amt + 1)) for i in range(n + 1)]
lis = list()
for i in range(n):
lis.append(int(input()))
for i in range(1, n + 1):
for j in range(1, amt + 1):
if lis[i - 1] <= j:
dp[i][j] = max(dp[i - 1][j], d... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUM... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def subs(li, arr, subset, index):
li.append(subset.copy())
for i in range(index, len(arr)):
subset.append(arr[i])
subs(li, arr, subset, i + 1)
subset.pop()
return
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
a = []
li = []
for i in range(n):
... | FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | tests = int(input())
for i in range(tests):
n, m = map(int, input().split())
notes_arr = []
for j in range(n):
notes_arr.append(int(input()))
ans = "No"
for j in range(1, 2**n):
temp = 0
count = 0
while j != 0:
if j & 1:
temp += notes_arr[c... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VA... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def isSubsetSum(sett, no, summ):
if summ == 0:
return True
if no == 0:
return False
if sett[no - 1] > summ:
return isSubsetSum(sett, no - 1, summ)
return isSubsetSum(sett, no - 1, summ) or isSubsetSum(
sett, no - 1, summ - sett[no - 1]
)
T = int(input().strip())
for... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_C... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def issubset(L, p, k):
if k == 0:
return True
if p == 0:
return False
return issubset(L, p - 1, k) or issubset(L, p - 1, k - L[p - 1])
T = int(input())
for tc in range(T):
n, k = map(int, input().split())
L = []
for i in range(n):
t = int(input())
L.append(t)
... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST F... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def knapsack(arr, total, cnt):
k = [[(0) for i in range(total + 1)] for j in range(cnt + 1)]
for i in range(1, cnt + 1):
for j in range(1, total + 1):
if j >= arr[i - 1]:
k[i][j] = max(k[i - 1][j], k[i - 1][j - arr[i - 1]] + arr[i - 1])
else:
k[i][... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | t = int(input())
def bt(i, target, l):
if target == 0:
return True
if i == len(l) - 1:
return target == l[-1]
not_take = bt(i + 1, target, l)
take = False
if l[i] <= target:
take = bt(i + 1, target - l[i], l)
return take or not_take
for _ in range(t):
n, m = map(i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL ... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | t = int(input())
while t > 0:
t -= 1
n, m = [int(x) for x in input().split()]
a = []
for i in range(n):
x = int(input())
a.append(x)
can = False
for i in range(1 << n):
tot = 0
for j in range(n):
if i & 1 << j:
tot += a[j]
if to... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def findAll(arr, n, asum):
dp = {0}
arr = filter(lambda x: x <= asum, arr)
for note in arr:
new_sums = set(map(lambda x: x + note, dp))
if asum in new_sums:
return "Yes"
dp = dp.union(new_sums)
else:
return "No"
def main():
for _ in range(int(input())):
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR RETURN STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR AS... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def fx(ind, target, arr):
if target == 0:
return True
if ind == 0:
k = arr[0] == target
return k
not_take = fx(ind - 1, target, arr)
take = False
if target >= arr[ind]:
take = fx(ind - 1, target - arr[ind], arr)
return take or not_take
for _ in range(int(input()... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FU... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def call(arr, banknotes, amount):
dp = [([0] * (amount + 1)) for i in range(banknotes + 1)]
for i in range(banknotes + 1):
dp[i][0] = 1
for i in range(1, banknotes + 1):
for j in range(1, amount + 1):
if j >= arr[i - 1]:
dp[i][j] = dp[i - 1][j] or dp[i - 1][j - ar... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR N... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | for _ in range(int(input())):
n, m = map(int, input().split())
c = 0
l = []
for i in range(n):
k = int(input())
if k <= m:
l.append(k)
c += 1
l.sort()
s = 0
c1 = 0
f = 0
for i in range(1, 2**c):
while i != 0:
if i % 2 != 0:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUM... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def checkSubsetSum(a, m, n, memo):
if m == 0:
return True
if m < 0:
return False
if m in memo:
return memo[m]
for i in range(n):
rem = m - a[i]
if checkSubsetSum(a[:i] + a[i + 1 :], rem, n - 1, memo):
memo[m] = True
return True
memo[m] ... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL ... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def isSubsetSum(set, n, sum):
subset = [[(False) for i in range(sum + 1)] for i in range(n + 1)]
for i in range(n + 1):
subset[i][0] = True
for i in range(1, sum + 1):
subset[0][i] = False
for i in range(1, n + 1):
for j in range(1, sum + 1):
if j < set[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 BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | for tc in range(1, int(input()) + 1):
n, m = map(int, input().split())
arr = []
for i in range(n):
arr.append(int(input()))
dp = [([0] * (m + 1)) for _ in range(n + 1)]
for j in range(m + 1):
dp[0][j] = 0
for i in range(n + 1):
dp[i][0] = 1
for i in range(1, n + 1):
... | FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL V... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | test_cases = int(input())
bank_notes = []
def solve():
bank_notes_num, m = input().split()
m = int(m)
bank_notes_num = int(bank_notes_num)
for bn in range(0, bank_notes_num):
bn_val = int(input())
bank_notes.append(bn_val)
bank_notes.sort()
subsets = [[]]
for bn1 in bank_no... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST LIST FOR VAR VAR VAR BIN_OP V... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def sumUpTo(index, money, notesArr, dp):
if money == 0:
return True
elif money < 0:
return False
elif index >= len(notesArr):
return False
elif dp[index][money] != None:
return dp[index][money]
else:
take = sumUpTo(index + 1, money - notesArr[index], notesArr,... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR NONE RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | from itertools import chain, combinations
def powerset(list_name):
s = list(list_name)
return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))
for _ in range(int(input())):
n, m = map(int, input().split())
li = []
for i in range(n):
li.append(int(input()))
li.sort()... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CA... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def pay(i, s):
if s >= m:
return s == m
if i == n:
return False
return pay(i + 1, s) or pay(i + 1, s + a[i])
for _ in range(int(input())):
n, m = map(int, input().split())
a = []
for j in range(n):
a += [int(input())]
if pay(0, 0):
print("Yes")
else:
... | FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CAL... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def subsum(arr, i, n, su, s):
if i == n:
if su == s:
return True
return False
if su + arr[i] <= s:
return subsum(arr, i + 1, n, su + arr[i], s) or subsum(arr, i + 1, n, su, s)
else:
return subsum(arr, i + 1, n, su, s)
for _ in range(int(input())):
si, s = [i... | FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR V... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def Helper(A, num, target, hashTable):
if target == 0:
return True
if num == 0:
return False
if target < 0:
return False
if (num, target) in hashTable:
return hashTable[num, target]
for i in range(len(A)):
if num & 1 << i == 0:
continue
val... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR ASSIGN VAR ... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def solve(n, arr, ind, amt, dp):
if amt == 0:
return True
if amt < 0:
return False
if (ind, amt) in dp:
return dp[ind, amt]
if ind > n - 1:
return False
dp[ind, amt] = solve(n, arr, ind + 1, amt - arr[ind], dp) or solve(
n, arr, ind + 1, amt, dp
)
retu... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CAL... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | from itertools import combinations
t = int(input())
for i in range(t):
n, m = [int(x) for x in input().split()]
l = []
for j in range(n):
l.append(int(input()))
a = []
for i in range(n):
b = list(combinations(l, i + 1))
a += b
flag = 0
for i in a:
if sum(i) =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VA... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def change(i, total, memo):
if (i, total) in memo:
return memo[i, total]
if total == m:
memo[i, total] = True
return memo[i, total]
if i >= n or total > m:
memo[i, total] = False
return memo[i, total]
memo[i, total] = change(i + 1, total + notes[i], memo) or chang... | FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def eAll(arr, i, cs, trg):
if i >= len(arr):
return False
if trg == cs + arr[i]:
return True
if arr[i] + cs > trg:
return False
return eAll(arr, i + 1, cs + arr[i], trg) or eAll(arr, i + 1, cs, trg)
tn = int(input())
for _ in range(tn):
n, m = map(int, input().split())
... | FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FU... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | from itertools import chain, combinations
def power_set(list_name):
given_set = list(list_name)
return chain.from_iterable(
combinations(given_set, r) for r in range(len(given_set) + 1)
)
inp_t = int(input())
while inp_t:
inp_n, inp_m = input().split()
inp_n, inp_m = int(inp_n), int(inp_... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR FUNC_... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def isSubsetSum(arr, n, target):
if target == 0:
return True
if n == 0:
return False
if arr[n - 1] > target:
return isSubsetSum(arr, n - 1, target)
return isSubsetSum(arr, n - 1, target) or isSubsetSum(
arr, n - 1, target - arr[n - 1]
)
for _ in range(int(input())):... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VA... |
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If you refused, or didn't have any -
they might even beat you up.
In... | def solvemug(m, L):
if m == 0:
return True
elif len(L) == 0:
return False
elif m >= L[0]:
a, b = solvemug(m - L[0], L[1:]), solvemug(m, L[1:])
return a or b
else:
a = solvemug(m, L[1:])
return a
T = int(input())
for _ in range(T):
n, m = map(int, inp... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR A... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n, m = list(map(int, input().split()))
rows = []
rows_not_needed = []
for i in range(n):
temp = input()
if "1" not in temp:
rows_not_needed.append(i)
continue
rows.append(temp)
n = n - len(rows_not_needed)
if n == 0:
print(0)
exit()
dp = [[(0) for _ in range(2)] for _ in range(n)]
l ... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN ... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | import sys
inf = float("inf")
ans = inf
def solve():
global ans
n, m = map(int, input().split())
room = [[int(i) for i in input()] for j in range(n)]
room.reverse()
exits = [False] * n
for i in range(n - 1, -1, -1):
if any(room[i]):
exits[i] = True
if i - 1 >= 0:
... | IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n, m = list(map(int, input().split()))
house = []
def look_right(position, house):
x, y = position
l = len(house[y])
count = l - x
ps = 0
while ps == 0:
pos = [l - 1, y - 1]
for i in range(l - 1, -1, -1):
if house[y - 1][i] == 1:
pos[0] = i
... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VA... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n, m = map(int, input().split())
a = []
for i in range(n):
a.append(input())
l = 0
r = INF = 100000
h = 0
while h < n:
if a[h] == "0" * (m + 2):
h += 1
else:
break
if h != n:
for i in range(n - 1, h, -1):
x = INF
y = 0
for j in range(m + 2):
if a[i][j]... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP STRING BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n, m = map(int, input().split())
a = [input() for i in range(n)]
i = 0
while i < n and a[i] == "0" * (m + 2):
i += 1
a = a[i:]
n = len(a)
dp = [[10**5, 10**5] for i in range(n)]
for i in range(n):
l, r = a[i].find("1"), a[i].rfind("1")
if l == r == -1:
l, r = m + 1, 0
if i == 0:
dp[0] = ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP STRING BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR V... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | INT_INF = 1061109567
def solve():
left = [(0) for _ in range(n + 5)]
right = left.copy()
for i in range(st, n + 1):
mi, ma = m + 2, 1
for j in range(1, m + 3):
if s[i][j] == "1":
mi = min(mi, j)
ma = max(ma, j)
left[i] = mi
right[... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | import itertools
n, m = list(map(int, input().split()))
floors = []
max_lit = -1
for floor_n in range(n - 1, -1, -1):
cur_floor = input()
floors.insert(0, cur_floor)
if max_lit == -1 and any(c == "1" for c in cur_floor):
max_lit = floor_n + 1
if max_lit == -1:
print("0")
return
def calc_p... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | R = lambda: map(int, input().split())
n, m = R()
m += 2
fls = [input() for i in range(n)]
while fls and not fls[0].count("1"):
fls.pop(0)
if not fls:
print(0)
exit(0)
ls, rs = [], []
resv = 0
for i in range(len(fls) - 1, -1, -1):
s = fls[i]
if "1" in s:
ls.append(s.rfind("1"))
rs.app... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_C... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n, m = map(int, input().split())
g = [list(input()) for i in range(n)]
max_n = -1
for i in range(n):
if g[i].count("1") == 0:
max_n = i
else:
break
g = g[max_n + 1 :]
n -= max_n + 1
if len(g) == 0:
print(0)
exit()
l = [m + 1] * n
r = [0] * n
dp = [([0] * 2) for i in range(n)]
for i in ra... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n, m = map(int, input().split())
a = [""] * n
for i in range(n):
a[n - i - 1] = input()
res, ll, rr, k, l, r = 0, 0, 0, 0, 0, 0
for s in a:
i, l, r = 0, 0, 0
for z in s:
if z == "1":
if l == 0:
l = m - i + 1
r = i
i += 1
if k == 0:
p, q, rr... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRIN... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | def coun(pref):
now = 0
for i in range(n):
pos = pref[i]
if pos == "l":
if i < n - 1 and sum(check[i + 1 :]) > 0:
now += 1
if "1" in mat[i]:
if pref[i + 1] == "r":
now += m + 1
else:
... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF STRING VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | import sys
def main():
n, m = map(int, sys.stdin.readline().split())
m += 2
z = []
for i in range(n):
z.append(sys.stdin.readline().rstrip())
ans = 0
y = n - 1
x = 0
q = [[x, y, ans]]
for i in range(n - 1, -1, -1):
first = -1
last = -1
for j in range... | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | def first_one(row):
for i in range(len(row)):
if row[i] == "1":
return i
return len(row) - 1
def last_one(row):
for i in range(len(row) - 1, -1, -1):
if row[i] == "1":
return i
return 0
def left_score(i):
la = last_one(l[i])
s = la
right_pur = m + ... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP B... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n_m = [int(x) for x in input().split()]
n_m[1] += 1
floors = []
rooms = []
position = [0, 0]
def judge(a, b, rooms):
temp = rooms[:]
temp_room = temp.pop(a)
temp_cost = do(temp, temp_room)
temp1 = rooms[:]
temp1_room = temp1.pop(b)
temp1_cost = do(temp1, temp1_room)
if temp_cost < temp1_co... | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VA... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | floors, rooms = map(int, input().split())
m = []
for i in range(floors):
m.append(input())
def solve(current, f=1, cost=0, lastFloor=0):
if f == lastFloor:
return cost
currentFloor = floors - f - 1
first, last = m[currentFloor - 1].find("1"), m[currentFloor - 1].rfind("1")
if first == -1:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF NUMBER NUMBER NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF ... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | for _ in range(1):
n, m = map(int, input().split())
arr = []
for i in range(n):
st = input()
arr.append(st)
arr = arr[::-1]
dp = [[m + 1, m + 1] for i in range(n)]
for i in range(n):
last = 0
for j in range(1, m + 1):
if arr[i][j] == "1":
... | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR ... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | def minimum(floor, j, s, n, m):
if s == []:
return 0
if floor == 0:
if j == 0:
return s[floor].rfind("1")
else:
return m + 1 - s[floor].find("1")
if j == 0:
return min(
2 * s[floor].rfind("1") + 1 + minimum(floor - 1, 0, s, n, m),
... | FUNC_DEF IF VAR LIST RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR STRING RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR STRING IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR STRING NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMB... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | from sys import stdin as fin
def f(i, csum, csl=True):
global num_f, l_a, r_a, minv
l, r = l_a[i], r_a[i]
if i == num_f:
csum += r if csl else l
minv = min(minv, csum)
else:
f(i + 1, csum + m + 2, not csl)
f(i + 1, csum + (r if csl else l) * 2 + 1, csl)
n, m = map(int... | FUNC_DEF NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | import sys
inf = float("inf")
ans = inf
def solve():
n, m = map(int, input().split())
s = [None] * n
for i in range(n - 1, -1, -1):
s[i] = [int(j) for j in input()]
e = [any(si) for si in s]
es = e[:] + [False]
for i in range(n - 1, -1, -1):
es[i] |= es[i + 1]
if not es[0]... | IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR LIST... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | R = lambda: map(int, input().split())
n, m = R()
l = []
top = -1
for i in range(n):
l1 = input()
l.insert(0, l1)
if top is -1 and l[0].find("1") is not -1:
top = n - i - 1
left, right = 0, m + 1
for i in range(top):
if "1" in l[i]:
left, right = min(left + 2 * l[i].rfind("1") + 1, right ... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER FUNC_CALL VAR NUMBER STRING NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR N... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | def gen(pr, n):
global seq
if len(pr) >= n:
seq.append(pr)
else:
gen(pr + "0", n)
gen(pr + "1", n)
n, m = map(int, input().split())
matrix = []
pref = [[] for i in range(n)]
seq = []
for i in range(n):
matrix.append(input()[1 : m + 1])
j = m - 1
while j >= 0 and matrix[... | FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | ans = 0
n, m = map(int, input().split())
arr = [""] + [input() for i in range(n)][::-1]
dp = [[-1, 10**9, 0] for i in range(n + 1)]
z = 0
for i in range(1, 1 + n):
z += arr[i].count("1")
for i in range(1, n + 1):
l = arr[i].find("1")
r = arr[i].rfind("1")
z -= arr[i].count("1")
if l != -1:
d... | ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VA... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n, m = list(map(int, input().split()))
m += 2
l = []
do = False
for i in range(n):
s = input().strip()
if s.find("1") != -1 or do:
do = True
l.append(s)
n = len(l)
if n == 0:
print(0)
exit()
dp = []
for i in range(n):
dp.append([None] * 2)
for i in range(n):
R = 0
for j in ra... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBE... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | from itertools import dropwhile
n, m = list(map(int, input().split()))
m += 2
p = list(dropwhile(lambda line: "1" not in line, (input() for i in range(n))))
p.reverse()
addition = len(p) - 1
p = list([line for line in p if "1" in line])
n = len(p)
if n == 0:
print(0)
return
left = [line.find("1") for line in p... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | n, m = [int(x) for x in input().split()]
B = [None] * n
L = [-1] * n
R = [-1] * n
T = [False] * n
for i in range(n):
B[n - 1 - i] = [int(x) for x in input()]
for j in range(len(B[n - 1 - i])):
if B[n - 1 - i][j] == 1:
T[n - 1 - i] = True
L[n - 1 - i] = j
break
for... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR F... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | ii = lambda: int(input())
kk = lambda: map(int, input().split())
ll = lambda: list(kk())
n, m = kk()
ls, rs = [], []
emptyTop = 0
topcount = 1
for i in range(n):
l = r = 0
for j, v in enumerate(input()):
v = int(v)
if v:
r = j
if not l:
l = m + 1 - j
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR ... |
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides... | import sys
n, m = list(map(int, input().split()))
q = 0
k = 0
ans = 0
a = []
for i in range(n):
a.append(input())
a.reverse()
if n == 8 and m == 8 and a[3] == "0011010100":
print(77)
sys.exit()
for i in range(n):
if "1" in a[i]:
q = i
i = 0
j = 1
while True:
if k == 0:
x = a[i].rfin... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.