description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
temp_arr = []
temp_count = 0
for n in nums:
if n % 2 != 0:
temp_arr.append(temp_count)
temp_count = 0
else:
temp_count = temp_count + 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
if len(nums) == 0:
return 0
preprocess = [0] * (len(nums) + 1)
count = 0
for i in range(len(nums)):
if nums[i] % 2 == 1:
count += 1
preprocess[i + 1] = co... | CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER A... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Window:
def __init__(self):
self.odd = 0
def add(self, value: int):
if value % 2 == 1:
self.odd += 1
def remove(self, value: int):
if value % 2 == 1:
self.odd -= 1
class Solution:
def numberOfSubarrays(self, A: List[int], k: int) -> int:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_DEF VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR ... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def addOrIncrement(self, key, dictionary):
if key in dictionary:
dictionary[key] += 1
else:
dictionary[key] = 1
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
n = len(nums)
if n < k:
return 0
ans = 0
... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CA... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
left = collections.defaultdict(int)
odd = 0
res = 0
for n in nums:
left[odd] += 1
odd += n & 1
if odd - k in left:
res += left[odd - k]
return res | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
rr = l = r = res = cnt = 0
ll = -1
n = len(nums)
while r < n:
x = nums[r]
if x % 2:
if ll < l:
ll = r
cnt += 1
if cnt ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR BIN_O... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
prefix_sum = 0
dict_odds = {(0): 1}
rs = 0
for i, num in enumerate(nums):
if num % 2 == 1:
prefix_sum += 1
if prefix_sum not in dict_odds:
dict_odds[p... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
s = 0
e = 0
l = len(nums)
total = 0
num_odd = 0
ae = 0
while s < l:
while e < l and num_odd != k:
if nums[e] % 2 != 0:
num_odd += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER NUMBER ... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def atMostK(self, nums, k):
start = 0
end = 0
count = 0
for end in range(len(nums)):
if nums[end] % 2 == 1:
k -= 1
while k < 0:
if nums[start] % 2 == 1:
k += 1
start += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF VAR VAR VAR IF VAR FUNC_CALL VAR VAR NUM... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
n = len(nums)
if k > n:
return 0
ans = 0
p1 = p2 = p3 = p4 = -1
while p4 < n:
p2 += 1
while p2 < n and nums[p2] % 2 == 0:
p2 += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR RETURN VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
odd_pos = [pos for pos, e in enumerate(nums) if e % 2 == 1]
if len(odd_pos) < k:
return 0
spaces = []
prev_pos = -1
for pos in odd_pos:
spaces.append(pos - prev_pos)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR B... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
flattened = [(1 if num % 2 == 1 else 0) for num in nums]
d = {(0): 1}
sum = 0
total = 0
for i in range(len(flattened)):
sum += flattened[i]
total += d.get(sum - k, 0)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
ln = len(nums)
ret = 0
for i in range(ln):
if nums[i] % 2:
nums[i] = 1
else:
nums[i] = 0
mp = {(0): 1}
cnt = 0
for n in nums:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR B... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
cache = {(0): [-1]}
cnt = 0
odds = 0
for i, num in enumerate(nums):
if num % 2:
odds += 1
if odds - k in cache:
cnt += len(cache[odds - k])
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR VAR RETURN VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
oddnum = 0
l, n = 0, len(nums)
add = 1
sums = 0
for r in range(n):
if nums[r] % 2 == 1:
k -= 1
while l < r and (k < 0 or nums[l] % 2 == 0):
if... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMB... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
l = [0] * (len(nums) + 1)
for i, n in enumerate(nums):
l[i + 1] = l[i] + n % 2
c = Counter(l)
return sum(c[x - k] * c[x] for x in c) | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, A: List[int], k: int) -> int:
d = []
res = 0
count = 1
for a in A:
if a % 2:
d.append(count)
count = 1
else:
count += 1
d.append(count)
m = len(d)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def checkOdd(self, num):
if num % 2 == 0:
return False
return True
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
oddIndices = []
for i in range(len(nums)):
if self.checkOdd(nums[i]):
oddIndices.append(i)
... | CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR BI... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
left_pointer = 0
right_pointer = -1
count = 0
odd = 0
while right_pointer < len(nums) - 1:
right_pointer += 1
if nums[right_pointer] % 2 == 1:
odd += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUM... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
idxes = []
for i in range(len(nums)):
if nums[i] % 2 == 1:
idxes.append(i)
if len(idxes) < k:
return 0
res = 0
for i in range(k - 1, len(idxes)):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_O... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
arr = list(map(lambda x: x % 2, nums))
n = len(arr)
arr = [0] + list(itertools.accumulate(arr))
hm = Counter()
res = 0
for i in arr:
res += hm[i]
hm[i + k] += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
last = 0
hsh = {}
for i in range(len(nums)):
if nums[i] % 2 == 1:
nums[i] = 1
else:
nums[i] = 0
nums[i] += last
last = nums[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VA... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
deque = collections.deque()
deque.append(1)
ans = 0
for num in nums:
if num % 2 == 0:
deque[-1] += 1
continue
if len(deque) == k + 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BI... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
prefix_odd = defaultdict(int)
prefix_odd[0] = 1
ans = count = 0
for num in nums:
if num % 2:
count += 1
prefix_odd[count] += 1
for p in prefix_odd:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
res = 0
i = j = 0
while i <= j:
while k > 0 and j < len(nums):
if nums[j] % 2 == 1:
k -= 1
j += 1
if k != 0:
return res
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
ans = 0
d = {(0): 0}
start = {}
cumsum = 0
for i, num in enumerate(nums):
cumsum += num % 2
d[cumsum] = i + 1
if cumsum not in start:
start[cumsum... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
if not nums:
return 0
s = []
evencnt = 0
for num in nums:
if num % 2 == 1:
s.append(evencnt)
evencnt = 0
else:
evencnt += ... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP... |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
front, end = 0, 0
tot = 0
output = 0
ct = 0
while end < len(nums):
if 1 & nums[end]:
tot += 1
ct = 0
end += 1
while tot == k:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR RETURN VAR VAR |
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Input: nums ... | class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
prefix = {(0): 1}
count = 0
result_count = 0
for num in nums:
if num % 2:
count += 1
prefix[count] = prefix.get(count, 0) + 1
result_count += prefix.get(c... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | n, b = map(int, input().split())
finish = [0] * n
t = []
d = []
for _ in range(n):
i = input().split()
t.append(int(i[0]))
d.append(int(i[1]))
current = t[0]
q = []
for i in range(n):
if q != []:
current = max(current, t[q[0]])
while q != [] and current + d[q[0]] <= t[i]:
j = q.pop(0... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FU... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | n, b = [int(item) for item in input().split()]
queue = []
for i in range(n):
ti, di = [int(item) for item in input().split()]
while len(queue) > 0 and queue[0] <= ti:
queue.pop(0)
if len(queue) - 1 == b:
print(-1, end=" ")
continue
if not queue:
queue.append(ti + di)
... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER STRING IF VAR EXPR ... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | n, b = map(int, input().split())
queries = []
for _ in range(n):
t, d = map(int, input().split())
queries.append((t, d))
result = [0] * n
queue = []
n_queue = b + 1
process = []
for i in range(n):
if len(queue) != 0 and queries[i][0] >= queue[0]:
queue.pop(0)
if len(queue) == 0:
finish_t... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | from itertools import product as P
from sys import maxsize as m
class Solution:
def bazinga(self, N, p):
pass
def __starting_point():
n, b = list(map(int, input().split(" ")))
ct, pt, lpt, cb = 0, 0, [], 0
result = []
for i in range(n):
ti, di = list(map(int, input().split()))
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR V... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | import sys
input = sys.stdin.readline
q = []
processing = 0
n, b = map(int, input().split())
for _ in range(n):
t, d = map(int, input().split())
while len(q) != 0 and q[0] <= t:
q.pop(0)
if len(q) <= b:
processing = max(processing, t) + d
print(processing, end=" ")
q.append(... | IMPORT ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | import sys
q = []
n, b = map(int, input().split())
t = 0
d = 0
for i in range(0, n):
t, d = map(int, input().split())
while len(q) != 0:
if q[0] <= t:
q.pop(0)
else:
break
if len(q) <= b:
if len(q) != 0:
t = q[-1]
t = t + d
print(t... | IMPORT ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR IF FUNC_CALL V... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | def main():
n, b = map(int, input().split())
def endgen():
res = [0]
q = 0
for _ in range(n):
t, d = map(int, input().split())
res.append(t + d if t > res[-1] else res[-1] + d)
while res[q] <= t:
q += 1
if len(res) - q - 1 ... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP FUNC... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | class zapros:
def __init__(self, t, timeToComplete):
self.t = t
self.timeToComplete = timeToComplete
n = input()
b = int(n.split()[1])
n = int(n.split()[0])
zapQueue = []
result = []
timeAfterComplete = 0
sumTime = 0
for i in range(n):
s = input()
zapr = zapros(int(s.split(" ")[0]), int(s... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL ... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | class Query:
def __init__(self, t, d, f):
self.t = t
self.d = d
self.f = f
queue = []
queries = []
n, b = map(int, input().split())
for i in range(n):
t, d = map(int, input().split())
query = Query(t, d, 0)
queries.append(query)
query = queries[0]
t = query.t + query.d
query.f... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | def main():
n, hi = map(int, input().split())
l, res, lo, hi = [0], [], 0, -hi
f, p = res.append, l.append
for _ in range(n):
t, d = map(int, input().split())
d += t if t > l[-1] else l[-1]
while lo <= hi and l[lo] <= t:
lo += 1
if hi >= lo:
f("-1"... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR LIST NUMBER LIST NUMBER VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL ... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | n, b = map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(n)]
ch = [0]
ans = []
bd = [0] * (n + 1)
po = ma = 0
for i in range(n):
t, d = l[i]
bd[i] = bd[i - 1]
ch += [max(ma, t) + d]
while ch[po] <= t:
po += 1
if i - po - (bd[i - 1] - bd[po - 1]) == b:
bd[... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR V... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | n, b = list(map(int, input().split()))
tasks = []
next_task = 0
time = 0
finish = [-1] * n
for i in range(n):
t, d = list(map(int, input().split()))
while tasks and next_task < len(tasks) and time <= t:
time += tasks[next_task][1]
finish[tasks[next_task][0]] = time
next_task += 1
if ... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN ... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | import sys
def main():
n, b = [int(tok) for tok in sys.stdin.readline().split()]
td_list = []
for i in range(n):
td_list.append([int(tok) for tok in sys.stdin.readline().split()])
queue = []
finish = [(-1) for i in range(n)]
for i, (t, d) in enumerate(td_list):
if len(queue) > ... | IMPORT FUNC_DEF 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR ... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | n, b = [int(i) for i in input().split()]
q = [0] * n
bg = 0
en = 0
time = 0
res = [-1] * n
for it in range(n):
ev = [int(i) for i in input().split()]
ev.append(it)
while bg < en and max(time, q[bg][0]) <= ev[0]:
time = max(time, q[bg][0])
res[q[bg][2]] = time + q[bg][1]
time += q[bg]... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR... |
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.
When a query appears server may react in three possible ways: If server is free... | n, b = map(int, input().split())
q = []
l = 0
r = 0
for i in range(n):
t, d = map(int, input().split())
while l != r:
if q[l] <= t:
l += 1
else:
break
len_queue = r - l - 1
if len_queue >= b:
print(-1, end=" ")
else:
if l == r:
q.ap... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER STRING IF V... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, arr, n):
start = 0
kami = 0
balance = 0
for i in range(n):
balance = balance + arr[i][0] - arr[i][1]
if balance < 0:
start = i + 1
kami += balance
balance = 0
if kami + bal... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN NUMBER |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, l, n):
i = 0
while i < n:
if l[i][1] > l[i][0]:
i += 1
pass
else:
t = 1
s = 0
for j in range(n):
s += l[(i + j) % n][0] - l[(i + j) % n][1]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
tp = 0
td = 0
for a, b in lis:
tp += a
td += b
if td > tp:
return -1
i = 0
cp = 0
ans = 0
while i < len(lis):
if cp + lis[i][0] >= lis[i][1]:
cp -=... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN ... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
fuel = 0
d = 0
s = 0
for i in range(n):
fuel += lis[i][0] - lis[i][1]
if fuel < 0:
d += fuel
fuel = 0
s = i + 1
return s if fuel + d >= 0 else -1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR NUMBER VAR NUMBER |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
bal = 0
start = 0
deficit = 0
for i in range(len(lis)):
p, d = lis[i]
bal += p - d
if bal < 0:
deficit += bal
start = i + 1
bal = 0
if bal + deficit >=... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN NUMBER |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
s = []
bakaya = 0
tak = 0
for i in range(n):
s = bakaya + lis[i][0] - lis[i][1]
if s < 0:
tak = i + 1
bakaya = 0
continue
if s >= 0:
bakaya = s... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMB... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
index = None
cur = 0
for i in range(n):
cur += lis[i][0] - lis[i][1]
if cur < 0:
cur = 0
index = None
elif index == None:
index = i
if index == None:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE IF VAR NONE ASSIGN VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR ... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
petrol = 0
index = -1
sum1 = 0
sum2 = 0
for i in range(n):
sum1 += lis[i][0]
sum2 += lis[i][1]
petrol += lis[i][0] - lis[i][1]
if petrol < 0:
petrol = 0
in... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER RETURN VAR |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
balance = 0
kami = 0
start = 0
for i in range(n):
petrol = lis[i][0]
dis = lis[i][1]
balance = petrol - dis + balance
if balance < 0:
kami = kami + balance
balance... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN NU... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
petrol = sum([i for i, j in lis])
distance = sum([j for i, j in lis])
if distance > petrol:
return -1
temp = 0
start = 0
for i in range(n):
temp += lis[i][0] - lis[i][1]
if temp < 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
start = 0
curr_petrol = 0
total_petrol = 0
for i in range(n):
curr_petrol += lis[i][0] - lis[i][1]
total_petrol += lis[i][0] - lis[i][1]
if curr_petrol < 0:
start = i + 1
curr... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR NUMBER VAR NUMBER |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
start = 0
end = 1
curr_petrol = lis[start][0] - lis[start][1]
while end != start or curr_petrol < 0:
while curr_petrol < 0 and start != end:
curr_petrol -= lis[start][0] - lis[start][1]
start = (star... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER RETURN NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
start = 0
deficit = 0
total = 0
for i in range(n):
petrol, distance = lis[i]
deficit += petrol - distance
total += petrol - distance
if deficit < 0:
start = i + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN VAR |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
tank = 0
start = -1
tankRequired = 0
total = 0
for i in range(n):
petrol, distance = lis[i]
total += petrol - distance
if start < 0:
start = i
tank = tank - distance + pet... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN VAR NUMBE... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
a = 0
b = 0
for i in range(n):
a = a + lis[i][0]
b = b + lis[i][1]
if b > a:
return -1
res = 0
c = 0
for i in range(n):
res = res + (lis[i][0] - lis[i][1])
if ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIG... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
lst = []
for i in range(n):
diff = lis[i][0] - lis[i][1]
lst.append(diff)
dist = 0
deficit = 0
index = 0
for i in range(n):
dist += lst[i]
if dist < 0:
index = i +... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER RE... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
start = 0
pointer = 0
balance = 0
totalDistBeforeStartIndex = 0
totalPetrolNeededForIndex = 0
totalDist = 0
totalPetrol = 0
while pointer < n:
balance = lis[pointer][0] + balance - lis[pointer][1]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VA... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
data = [(a[0] - a[1]) for a in lis]
if sum(data) == 0:
return -1
st, cap, deff = 0, 0, 0
for j in range(n):
cap += data[j]
if cap < 0:
st = j + 1
deff += cap
c... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR RETURN NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR RET... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
lis = lis + lis
i = 0
start = i
curr = 0
while i < 2 * n:
if i == start + n:
return start
curr = curr + lis[i][0] - lis[i][1]
if curr < 0:
start = i + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN NUMBER |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
n = len(lis)
total_gas = 0
for i in range(n):
total_gas += lis[i][0]
total_cost = 0
for i in range(n):
total_cost += lis[i][1]
if total_gas < total_cost:
return -1
total = 0
r... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
balance = 0
front = 0
flag = 0
i = 0
while i < n:
balance = balance + lis[i][0]
balance = balance - lis[i][1]
if balance >= 0:
if flag == 0:
front = i
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMB... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
total_petrol = 0
total_distance = 0
start = 0
end = 0
while True:
if start == n:
return -1
total_petrol += lis[end][0]
total_distance += lis[end][1]
while total_distance >... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR RETURN NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER RE... |
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its... | class Solution:
def tour(self, lis, n):
diff = [(0) for i in range(n)]
current_petrol = 0
startingPoint = 0
deficit = 0
for i in range(n):
diff[i] = lis[i][0] - lis[i][1]
current_petrol += diff[i]
if current_petrol < 0:
sta... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER RETURN BIN_OP VAR VAR NUMBER VAR NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | def func():
n = int(input())
l = map(int, input().split())
a, b, c = map(int, input().split())
l = list(l)
s = input()
st = 0
en = n - 1
x, y = 1, 0
k = 0
for i in range(0, n):
if s[i] == "A":
y += a
y = y % c
elif s[i] == "M":
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FU... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | def process(nums, abc, seq):
n = len(nums)
a, b, c = abc
l, r = 0, n - 1
x, y = 1, 0
for i in range(n):
if seq[i] == "R":
l, r = r, l
elif seq[i] == "A":
y = (y + a) % c
elif seq[i] == "M":
x = x * b % c
y = y * b % c
nu... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BI... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
while t > 0:
t = t - 1
n = int(input())
l = [int(x) for x in input().split()]
a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
s = input()
rev = False
add = 0
mul = 1
curr = 0
start = 0
end = n - 1
for i in range(n):
if s[i] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | from sys import stdin
T = int(stdin.readline())
for _ in range(T):
N = int(stdin.readline())
L = [int(s) for s in stdin.readline().strip().split()]
A, B, C = (int(s) for s in stdin.readline().strip().split())
S = stdin.readline().strip()
front, back = 0, N - 1
rev = False
mul, add = 1, 0
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
while t > 0:
t = t - 1
n = int(input())
list = []
list2 = input().split()
for i in list2:
list.append(int(i))
a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
s = input()
answer = []
add = 0
fact = 1
i = 0
j = n - 1
rever... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
while t != 0:
n = int(input())
l = list(map(int, input().split()))
a, b, c = map(int, input().split())
s = input()
left, right = 0, n - 1
isRev = False
toAdd = 0
toMul = 1
for i in range(len(s)):
if s[i] == "R":
isRev = not isRev
elif s[i]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUM... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | def solve():
n = int(input())
a = input().split(" ")
for i in range(n):
a[i] = int(a[i])
A, B, C = input().split(" ")
A = int(A)
B = int(B)
C = int(C)
s = input()
CON = 0
MULT = 1
res = ""
for i in range(n):
if s[i] == "R":
a.reverse()
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIG... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | itr = int(input())
for j in range(itr):
N = int(input())
l = input()
L = [int(x) for x in l.split()]
l = input()
[A, B, C] = [int(x) for x in l.split()]
S = input()
for i in range(N):
if S[i] == "R":
y = L[i:]
L = L[:i] + y[::-1]
elif S[i] == "A":
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR V... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
for _ in range(t):
n = int(input())
l = [int(x) for x in input().split()]
a, b, c = [int(x) for x in input().split()]
s = input()
A, M, left, right, cd = 0, 1, 0, n - 1, 1
for i in range(n):
if s[i] == "A":
A += a
A %= c
elif s[i] == "M":
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUM... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | def io(func=str, n=1):
def nfp():
ff = str
try:
it = iter(func)
def nf(val):
nonlocal ff
ff = next(it, ff)
return ff(val)
return type(func)(nf(va) for va in input().split())
except TypeError:
r... | FUNC_DEF VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VA... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
for q in range(t):
n = int(input())
numbers = input()
x = numbers.split()
a, b, c = map(int, input().split())
s = input()
up = 0
lp = n - 1
add = 0
mult = 1
a = a % c
b = b % c
ci = 1
for i in range(n):
if s[i] == "R":
temp = up
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMB... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | tc = int(input())
for t in range(tc):
n = int(input())
l = list(map(int, input().split()))
a, b, c = map(int, input().split())
st = input()
fuck = True
temp1 = 0
temp = 1
x = 0
y = n - 1
for i in range(n):
if st[i] == "R":
x, y = y, x
fuck = not fu... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VA... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | T = int(input())
while T > 0:
N = int(input())
L = [int(x) for x in input().split(" ")]
A, B, C = (int(x) for x in input().split(" "))
st = input()
ans = ""
forward = True
fp = 0
bp = N - 1
tm = 1
ta = 0
for i in range(N):
if st[i] == "R":
forward = not fo... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | import sys
l = []
s = ""
def main():
t = int(input())
while t:
t -= 1
n = int(input())
head = 0
flag = 0
tail = n - 1
mul_value = 1
add_value = 0
l = sys.stdin.readline().strip().split(" ")
a, b, c = sys.stdin.readline().strip().split(" ... | IMPORT ASSIGN VAR LIST ASSIGN VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
for i in range(t):
n = int(input())
l = list(map(int, input().split()))
a, b, c = map(int, input().split())
s = input()
m = 1
u = 0
for j in range(n):
if s[j] == "A":
u = u + a
elif s[j] == "R":
l[j:] = l[j:][::-1]
elif s[j] ==... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR I... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | import sys
T = int(sys.stdin.readline())
Ans = ""
for t in range(T):
N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))
A, B, C = map(int, sys.stdin.readline().split())
s = sys.stdin.readline().split()[0]
i = 0
ss = 0
end = N
x = 1
a = 0
b = 1
whi... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASS... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input().strip())
while t:
n = int(input().strip())
l = [int(x) for x in input().strip().split()]
a, b, c = (int(x) for x in input().strip().split())
S = input().strip()
s, e, i, x, y = 0, n - 1, 1, 1, 0
for C in S:
if C == "R":
s, e, i = e, s, -i
elif C == "A"... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER B... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
for ti in range(t):
n = int(input())
l = [int(x) for x in input().split()]
a, b, c = [int(x) for x in input().split()]
s = input()
multiplier = 1
addend = 0
rev = False
res = []
i = 0
j = n - 1
for ch in s:
if ch == "R":
rev = not rev
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | import sys
T = int(sys.stdin.readline())
while T > 0:
T -= 1
N = int(input())
L = list(map(int, sys.stdin.readline().split()))
a, b, c = map(int, sys.stdin.readline().split())
a = a % c
b = b % c
str = input()
toadd = 0
tomul = 1
rev = 0
co = 0
f = 0
for i in str:
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR AS... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | def main():
t = int(input())
while t > 0:
t = t - 1
n = int(input())
arr = list(map(int, input().split()))
a, b, c = map(int, input().split())
s = input()
a1 = f = 0
l = m1 = temp = 1
la = n - 1
for i in range(n):
if s[i] == "A"... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR V... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | import sys
data = sys.stdin.read().split()
data.reverse()
def read():
return int(data.pop())
def readStr():
return data.pop()
T = read()
for test in range(T):
n = read()
A = [read() for i in range(n)]
a, b, c = read(), read(), read()
s = readStr()
ans = []
l, r = 0, n - 1
isRe... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR A... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | T = int(input())
for i in range(T):
N = int(input())
inp = input().split()
L = [int(x) for x in inp]
inp2 = input().split()
A = int(inp2[0])
B = int(inp2[1])
C = int(inp2[2])
S = input()
pos = 0
s = 0
p = 1
for j in range(N):
if S[j] == "R":
pos = -1 -... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER A... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | def sep(s):
a = []
b = ""
for i in list(s):
if i == " ":
a.append(int(b))
b = ""
b = b + i
if b != " ":
a.append(int(b))
return a
t = int(input())
for xx in range(t):
l = []
li = []
n = int(input())
s = input()
l = sep(s)
s = ... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LI... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | T = int(input())
a = [(0) for i in range(0, 1101)]
c = [(0) for i in range(0, 1101)]
while T > 0:
T -= 1
n = int(input())
tmp = input().split()
ba = 0
bt = 1
L = 1
R = n
for i in range(1, n + 1):
a[i] = int(tmp[i - 1])
f = 0
now = 0
add, mul, mod = [int(x) for x in in... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FU... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | T = int(input())
for _ in range(T):
N = int(input())
L = [int(i) for i in input().split()]
A, B, C = [int(i) for i in input().split()]
S = input()
direction = 1
endPos = N
curPos = 0
finalValues = []
coeff = 1
constant = 0
for op in S:
if op == "A":
consta... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST AS... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
for i in range(0, t):
n = int(input())
arr = [int(j) for j in input().split(" ")]
a, b, c = input().split(" ")
a = int(a)
b = int(b)
c = int(c)
s = input()
g = -1
h = n
fl = 0
sum = 0
pro = 1
for j in range(0, n):
if s[j] == "R" and fl == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN V... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | test = int(input())
for t in range(test):
n = int(input())
l = list(map(int, input().split()))
x, y, z = map(int, input().split())
str = input()
a, b, c = 0, 1, z
strt, end = 0, n
p = 1
for i in range(n):
if str[i] == "R":
p += 1
if p % 2 == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER VAR ... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | T = int(input())
for t in range(T):
N = int(input())
num = input().split()
num = [int(i) for i in num]
temp = input().split()
A, B, C = int(temp[0]), int(temp[1]), int(temp[2])
string = input().strip()
coeff_add = 0
coeff_mult = 1
f = N - 1
s = 0
k = 0
for i in string:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
for cs in range(t):
n = int(input())
LS = input().split()
L = []
for str in LS:
L.append(int(str))
A1, B1, C1 = input().split()
A = int(A1)
B = int(B1)
C = int(C1)
S = input()
i = 0
j = n - 1
add = 0
mul = 1
flag = 0
pr = 0
for ch ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | t = int(input())
j = 0
while t > 0:
n = int(input())
extra, mcnt, rcnt, p1, p2 = 0, 1, 0, -1, n
arr = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s = input()
for i in s:
if i == "R":
rcnt += 1
elif i == "A":
extra = (extra + a[0... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER 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 FOR VAR V... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | from sys import stdin
T = int(stdin.readline())
for t in range(T):
N = int(stdin.readline())
num = [int(i) for i in stdin.readline().split()]
a, b, c = [int(i) for i in stdin.readline().split()]
string = stdin.readline().strip()
A = 0
M = 1
flag = 0
start = 0
end = N - 1
rev = 0... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIG... |
Read problems statements in Mandarin Chinese and Russian.
Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows :
Ask a volunteer from the audience to write down a list L of N integers.
Ask another volunteer from the a... | import sys
def pow_mod(x, y, z):
number = 1
while y:
if y & 1:
number = number * x % z
y >>= 1
x = x * x % z
return number
tokenizedInput = sys.stdin.read().split()
n = int(tokenizedInput[0])
t = 1
for i in range(0, n):
N = int(tokenizedInput[t])
t = t + 1
... | IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSI... |
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x_1, x_2, ..., x_{k} (k > 1) is such maximum element x_{j}, that the following inequality holds: $x_{j} \neq \operatorname{max}_{i = 1}^{k} x_{i}$.
The lucky number of the sequence of disti... | x = input()
l = list(map(int, input().split()))
ans = 0
d = []
for i in l:
while d != []:
if d[-1] < i:
ans = max(ans, d[-1] ^ i)
d.pop()
else:
ans = max(ans, d[-1] ^ i)
break
d.append(i)
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR WHILE VAR LIST IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.