code stringlengths 51 912 | input stringlengths 11 330 | output stringlengths 0 266 | prompt_token_length int64 59 615 | execution_time float64 0.04 6.03k | prompt stringlengths 255 1.16k |
|---|---|---|---|---|---|
def function(s: str, t: str) -> int:
ans = 0
m, n = len(s), len(t)
f = [[0] * (n + 1) for _ in range(m + 1)]
g = [[0] * (n + 1) for _ in range(m + 1)]
for i, a in enumerate(s, 1):
for j, b in enumerate(t, 1):
if a == b:
f[i][j] = f[i - 1][j - 1] + 1
for i in r... | function('oxnmyxlvucfkywqyffqyklvdokpyhyfszzfmhnskownefxeltkxunxuydcvtwzidwlirkxyapodulbgqjxzxqehkfsfeovkelvw', 'dixywajefisjztemofdplmvwmljspkpcxnxmlsluphvsdjrwydzjminqhsaecynmsmxdsczwkzhprcrplotnqaucfkgexgqy') | 9866 | 382 | 1,517.317868 |
Code:
def function(s: str, t: str) -> int:
ans = 0
m, n = len(s), len(t)
f = [[0] * (n + 1) for _ in range(m + 1)]
g = [[0] * (n + 1) for _ in range(m + 1)]
for i, a in enumerate(s, 1):
for j, b in enumerate(t, 1):
if a == b:
f[i][j] = f[i - 1][j - 1] + 1
for... |
def function(n: int) -> int:
f = [1] * 5
for _ in range(n - 1):
s = 0
for j in range(5):
s += f[j]
f[j] = s
return sum(f) | function(20) | 10626 | 105 | 5.46994 |
Code:
def function(n: int) -> int:
f = [1] * 5
for _ in range(n - 1):
s = 0
for j in range(5):
s += f[j]
f[j] = s
return sum(f)
Evaluate this code with the following inputs :
function(20)
Please evaluate the code with the given inputs and provide the expected outpu... |
def function(n: int) -> int:
if n < 2:
return n
nums = [0] * (n + 1)
nums[1] = 1
for i in range(2, n + 1):
nums[i] = nums[i >> 1] if i % 2 == 0 else nums[i >> 1] + nums[(i >> 1) + 1]
return max(nums) | function(100) | 21 | 142 | 8.625389 |
Code:
def function(n: int) -> int:
if n < 2:
return n
nums = [0] * (n + 1)
nums[1] = 1
for i in range(2, n + 1):
nums[i] = nums[i >> 1] if i % 2 == 0 else nums[i >> 1] + nums[(i >> 1) + 1]
return max(nums)
Evaluate this code with the following inputs :
function(100)
Please evaluat... |
def function(forbidden: List[int], a: int, b: int, x: int) -> int:
s = set(forbidden)
q = deque([(0, 1)])
vis = {(0, 1)}
ans = 0
while q:
for _ in range(len(q)):
i, k = q.popleft()
if i == x:
return ans
nxt = [(i + a, 1)]
if k &... | function([268, 634, 474, 276, 913, 394, 201, 853, 788, 670], 1797, 1396, 273) | -1 | 257 | 19.210621 |
Code:
def function(forbidden: List[int], a: int, b: int, x: int) -> int:
s = set(forbidden)
q = deque([(0, 1)])
vis = {(0, 1)}
ans = 0
while q:
for _ in range(len(q)):
i, k = q.popleft()
if i == x:
return ans
nxt = [(i + a, 1)]
... |
def function(n: int, k: int) -> str:
ans = ['a'] * n
i, d = n - 1, k - n
while d > 25:
ans[i] = 'z'
d -= 25
i -= 1
ans[i] = chr(ord(ans[i]) + d)
return ''.join(ans) | function(10, 219) | ajzzzzzzzz | 129 | 0.606756 |
Code:
def function(n: int, k: int) -> str:
ans = ['a'] * n
i, d = n - 1, k - n
while d > 25:
ans[i] = 'z'
d -= 25
i -= 1
ans[i] = chr(ord(ans[i]) + d)
return ''.join(ans)
Evaluate this code with the following inputs :
function(10, 219)
Please evaluate the code with the giv... |
def function(tasks: List[List[int]]) -> int:
ans = cur = 0
for a, m in sorted(tasks, key=lambda x: x[0] - x[1]):
if cur < m:
ans += m - cur
cur = m
cur -= a
return ans | function([[9959, 5455], [3051, 2922], [7313, 6962], [6645, 4286], [2564, 1078], [7799, 1461], [1864, 7421], [6372, 2747], [4196, 8616], [4113, 3873]]) | 47538 | 189 | 2.059803 |
Code:
def function(tasks: List[List[int]]) -> int:
ans = cur = 0
for a, m in sorted(tasks, key=lambda x: x[0] - x[1]):
if cur < m:
ans += m - cur
cur = m
cur -= a
return ans
Evaluate this code with the following inputs :
function([[9959, 5455], [3051, 2922], [7313, ... |
def function(nums: List[int], k: int) -> List[int]:
stk = []
n = len(nums)
for i, v in enumerate(nums):
while stk and stk[-1] > v and len(stk) + n - i > k:
stk.pop()
if len(stk) < k:
stk.append(v)
return stk | function([6, 36, 88, 46, 16, 66, 53, 64, 24, 28], 9) | [6, 36, 46, 16, 66, 53, 64, 24, 28] | 152 | 1.227222 |
Code:
def function(nums: List[int], k: int) -> List[int]:
stk = []
n = len(nums)
for i, v in enumerate(nums):
while stk and stk[-1] > v and len(stk) + n - i > k:
stk.pop()
if len(stk) < k:
stk.append(v)
return stk
Evaluate this code with the following inputs :
f... |
def function(nums: List[int], k: int) -> int:
nums.sort()
l, r, ans = 0, len(nums) - 1, 0
while l < r:
s = nums[l] + nums[r]
if s == k:
ans += 1
l, r = l + 1, r - 1
elif s > k:
r -= 1
else:
l += 1
return ans | function([19, 20, 26, 33, 50, 54, 72, 77, 80, 100], 73) | 1 | 180 | 0.641258 |
Code:
def function(nums: List[int], k: int) -> int:
nums.sort()
l, r, ans = 0, len(nums) - 1, 0
while l < r:
s = nums[l] + nums[r]
if s == k:
ans += 1
l, r = l + 1, r - 1
elif s > k:
r -= 1
else:
l += 1
return ans
Evaluate... |
def function(allowed: str, words: List[str]) -> int:
s = set(allowed)
return sum(all(c in s for c in w) for w in words) | function(['y', 'h', 'v', 'l', 'u', 'a', 'k', 'i', 'p', 'c', 'x', 'j', 'g', 'w', 's', 'f', 't', 'd', 'm', 'z', 'r', 'e', 'o', 'b'], ['lzty', 'wjdyrxvqf', 'aijunlx', 'kzdhvf', 'ken', 'lvun', 'ydnzgrpc', 'msnqp', 'hfpomka', 'wdpfxkbvgn', 'ywmd']) | 4 | 211 | 6.996996 |
Code:
def function(allowed: str, words: List[str]) -> int:
s = set(allowed)
return sum(all(c in s for c in w) for w in words)
Evaluate this code with the following inputs :
function(['y', 'h', 'v', 'l', 'u', 'a', 'k', 'i', 'p', 'c', 'x', 'j', 'g', 'w', 's', 'f', 't', 'd', 'm', 'z', 'r', 'e', 'o', 'b'], ['lzty... |
def function(n: str) -> int:
return int(max(n)) | function('100') | 1 | 59 | 0.240291 |
Code:
def function(n: str) -> int:
return int(max(n))
Evaluate this code with the following inputs :
function('100')
Please evaluate the code with the given inputs and provide the expected output in \boxed{} format. Do not output or excecute code.
|
def function(nums: List[int], k: int) -> int:
n = len(nums)
f = [0] * n
q = deque([0])
for i in range(n):
if i - q[0] > k:
q.popleft()
f[i] = nums[i] + f[q[0]]
while q and f[q[-1]] <= f[i]:
q.pop()
q.append(i)
return f[-1] | function([-3051, -1723, -6281, -3465, 3972, -9602, 4453, -6445, 7890, -2606], 43019) | 10658 | 186 | 2.602956 |
Code:
def function(nums: List[int], k: int) -> int:
n = len(nums)
f = [0] * n
q = deque([0])
for i in range(n):
if i - q[0] > k:
q.popleft()
f[i] = nums[i] + f[q[0]]
while q and f[q[-1]] <= f[i]:
q.pop()
q.append(i)
return f[-1]
Evaluate this... |
def function(nums: List[int], k: int) -> List[int]:
i = nums.index(max(nums[: len(nums) - k + 1]))
return nums[i : i + k] | function([58, 27, 31, 16, 73, 70, 3, 52, 100, 61], 10) | [58, 27, 31, 16, 73, 70, 3, 52, 100, 61] | 115 | 0.35177 |
Code:
def function(nums: List[int], k: int) -> List[int]:
i = nums.index(max(nums[: len(nums) - k + 1]))
return nums[i : i + k]
Evaluate this code with the following inputs :
function([58, 27, 31, 16, 73, 70, 3, 52, 100, 61], 10)
Please evaluate the code with the given inputs and provide the expected output ... |
def function(boxTypes: List[List[int]], truckSize: int) -> int:
ans = 0
for a, b in sorted(boxTypes, key=lambda x: -x[1]):
ans += b * min(truckSize, a)
truckSize -= a
if truckSize <= 0:
break
return ans | function([[8, 84], [7, 73], [11, 45], [5, 89], [3, 48], [10, 59]], 937) | 2857 | 155 | 1.949426 |
Code:
def function(boxTypes: List[List[int]], truckSize: int) -> int:
ans = 0
for a, b in sorted(boxTypes, key=lambda x: -x[1]):
ans += b * min(truckSize, a)
truckSize -= a
if truckSize <= 0:
break
return ans
Evaluate this code with the following inputs :
function([[8, ... |
def function(s: str, x: int, y: int) -> int:
if x < y:
return self.maximumGain(s[::-1], y, x)
ans = 0
stk1, stk2 = [], []
for c in s:
if c != 'b':
stk1.append(c)
else:
if stk1 and stk1[-1] == 'a':
stk1.pop()
ans += x
... | function('lyopujjtvku', 2413, 1622) | 0 | 228 | 1.12177 |
Code:
def function(s: str, x: int, y: int) -> int:
if x < y:
return self.maximumGain(s[::-1], y, x)
ans = 0
stk1, stk2 = [], []
for c in s:
if c != 'b':
stk1.append(c)
else:
if stk1 and stk1[-1] == 'a':
stk1.pop()
ans += x
... |
def function(encoded: List[int], first: int) -> List[int]:
ans = [first]
for e in encoded:
ans.append(ans[-1] ^ e)
return ans | function([24, 76, 88, 57, 96, 70, 47, 100, 22, 71], 56) | [56, 32, 108, 52, 13, 109, 43, 4, 96, 118, 49] | 115 | 0.629071 |
Code:
def function(encoded: List[int], first: int) -> List[int]:
ans = [first]
for e in encoded:
ans.append(ans[-1] ^ e)
return ans
Evaluate this code with the following inputs :
function([24, 76, 88, 57, 96, 70, 47, 100, 22, 71], 56)
Please evaluate the code with the given inputs and provide the... |
def function(encoded: List[int]) -> List[int]:
n = len(encoded) + 1
a = b = 0
for i in range(0, n - 1, 2):
a ^= encoded[i]
for i in range(1, n + 1):
b ^= i
perm = [0] * n
perm[-1] = a ^ b
for i in range(n - 2, -1, -1):
perm[i] = encoded[i] ^ perm[i + 1]
return per... | function([26, 54, 33, 24, 75, 19, 42, 78, 47, 89]) | [42, 48, 6, 39, 63, 116, 103, 77, 3, 44, 117] | 194 | 1.482787 |
Code:
def function(encoded: List[int]) -> List[int]:
n = len(encoded) + 1
a = b = 0
for i in range(0, n - 1, 2):
a ^= encoded[i]
for i in range(1, n + 1):
b ^= i
perm = [0] * n
perm[-1] = a ^ b
for i in range(n - 2, -1, -1):
perm[i] = encoded[i] ^ perm[i + 1]
ret... |
def function(time: str) -> str:
t = list(time)
if t[0] == '?':
t[0] = '1' if '4' <= t[1] <= '9' else '2'
if t[1] == '?':
t[1] = '3' if t[0] == '2' else '9'
if t[3] == '?':
t[3] = '5'
if t[4] == '?':
t[4] = '9'
return ''.join(t) | function('?3:?3') | 23:53 | 169 | 0.329192 |
Code:
def function(time: str) -> str:
t = list(time)
if t[0] == '?':
t[0] = '1' if '4' <= t[1] <= '9' else '2'
if t[1] == '?':
t[1] = '3' if t[0] == '2' else '9'
if t[3] == '?':
t[3] = '5'
if t[4] == '?':
t[4] = '9'
return ''.join(t)
Evaluate this code with the ... |
def function(n: int) -> int:
s, k = 0, 1
while s + k * (k + 1) // 2 <= n:
s += k * (k + 1) // 2
k += 1
k -= 1
ans = k * (k + 1) // 2
k = 1
while s < n:
ans += 1
s += k
k += 1
return ans | function(459320720) | 982324 | 159 | 243.497878 |
Code:
def function(n: int) -> int:
s, k = 0, 1
while s + k * (k + 1) // 2 <= n:
s += k * (k + 1) // 2
k += 1
k -= 1
ans = k * (k + 1) // 2
k = 1
while s < n:
ans += 1
s += k
k += 1
return ans
Evaluate this code with the following inputs :
function(45... |
def function(nums: List[int]) -> int:
f = g = 0
ans = 0
for x in nums:
f = max(f, 0) + x
g = min(g, 0) + x
ans = max(ans, f, abs(g))
return ans | function([-7381, 5555, 1327, -3051, -3886, 3043, -2903, -8948, -8782, 9291]) | 25026 | 150 | 3.831665 |
Code:
def function(nums: List[int]) -> int:
f = g = 0
ans = 0
for x in nums:
f = max(f, 0) + x
g = min(g, 0) + x
ans = max(ans, f, abs(g))
return ans
Evaluate this code with the following inputs :
function([-7381, 5555, 1327, -3051, -3886, 3043, -2903, -8948, -8782, 9291])
Ple... |
def function(s: str) -> int:
i, j = 0, len(s) - 1
while i < j and s[i] == s[j]:
while i + 1 < j and s[i] == s[i + 1]:
i += 1
while i < j - 1 and s[j - 1] == s[j]:
j -= 1
i, j = i + 1, j - 1
return max(0, j - i + 1) | function('cabcbacbcc') | 7 | 162 | 0.48125 |
Code:
def function(s: str) -> int:
i, j = 0, len(s) - 1
while i < j and s[i] == s[j]:
while i + 1 < j and s[i] == s[i + 1]:
i += 1
while i < j - 1 and s[j - 1] == s[j]:
j -= 1
i, j = i + 1, j - 1
return max(0, j - i + 1)
Evaluate this code with the following... |
def function(a: int, b: int, c: int) -> int:
a, b, c = sorted([a, b, c])
if a + b < c:
return a + b
return (a + b + c) >> 1 | function(100, 47, 92) | 119 | 109 | 0.259044 |
Code:
def function(a: int, b: int, c: int) -> int:
a, b, c = sorted([a, b, c])
if a + b < c:
return a + b
return (a + b + c) >> 1
Evaluate this code with the following inputs :
function(100, 47, 92)
Please evaluate the code with the given inputs and provide the expected output in \boxed{} format.... |
def function(word1: str, word2: str) -> str:
i = j = 0
ans = []
while i < len(word1) and j < len(word2):
if word1[i:] > word2[j:]:
ans.append(word1[i])
i += 1
else:
ans.append(word2[j])
j += 1
ans.append(word1[i:])
ans.append(word2[j:])... | function('zevwwmxcxz', 'azszhgnjzq') | zevwwmxcxzazszhgnjzq | 160 | 2.185782 |
Code:
def function(word1: str, word2: str) -> str:
i = j = 0
ans = []
while i < len(word1) and j < len(word2):
if word1[i:] > word2[j:]:
ans.append(word1[i])
i += 1
else:
ans.append(word2[j])
j += 1
ans.append(word1[i:])
ans.append(wor... |
def function(s: str) -> str:
n = len(s)
ans = ''
for i in range(n):
lower = upper = 0
for j in range(i, n):
if s[j].islower():
lower |= 1 << (ord(s[j]) - ord('a'))
else:
upper |= 1 << (ord(s[j]) - ord('A'))
if lower == upper... | function('ukakxjnSAHogjZJMCDeIMFyvFfIPnlHfKkOeyegukZaxCskjQxootzsYfzbhGIfOMDyzYUqIxMUGdaKvhHVvpdTOjAhPQJMgGxkI') | vhHVv | 230 | 798.729667 |
Code:
def function(s: str) -> str:
n = len(s)
ans = ''
for i in range(n):
lower = upper = 0
for j in range(i, n):
if s[j].islower():
lower |= 1 << (ord(s[j]) - ord('a'))
else:
upper |= 1 << (ord(s[j]) - ord('A'))
if lower =... |
def function(word1: str, word2: str) -> int:
s = word1 + word2
n = len(s)
f = [[0] * n for _ in range(n)]
for i in range(n):
f[i][i] = 1
ans = 0
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
if s[i] == s[j]:
f[i][j] = f[i + 1][j - 1] + 2
... | function('lmaiuhfiamg', 'rxsaxfwluqg') | 9 | 237 | 51.416187 |
Code:
def function(word1: str, word2: str) -> int:
s = word1 + word2
n = len(s)
f = [[0] * n for _ in range(n)]
for i in range(n):
f[i][i] = 1
ans = 0
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
if s[i] == s[j]:
f[i][j] = f[i + 1][j - 1] ... |
def function(features: List[str], responses: List[str]) -> List[str]:
cnt = Counter()
for s in responses:
for w in set(s.split()):
cnt[w] += 1
return sorted(features, key=lambda w: -cnt[w]) | function(['n', 'f', 'p', 'd', 'p', 'c', 'a', 'r', 'e'], ['n a p e c n r f', 'n a n d n f a', 'd p p d', 'p f f p n d r', 'e a p a a r', 'p n n n f c a n e', 'a p c p f r d r p', 'p r n f r p f a r p', 'p p p f d p e d', 'n p f e d p r p']) | ['p', 'p', 'f', 'n', 'd', 'a', 'r', 'e', 'c'] | 220 | 12.353979 |
Code:
def function(features: List[str], responses: List[str]) -> List[str]:
cnt = Counter()
for s in responses:
for w in set(s.split()):
cnt[w] += 1
return sorted(features, key=lambda w: -cnt[w])
Evaluate this code with the following inputs :
function(['n', 'f', 'p', 'd', 'p', 'c', 'a'... |
def function(sensor1: List[int], sensor2: List[int]) -> int:
i, n = 0, len(sensor1)
while i < n - 1:
if sensor1[i] != sensor2[i]:
break
i += 1
while i < n - 1:
if sensor1[i + 1] != sensor2[i]:
return 1
if sensor1[i] != sensor2[i + 1]:
retur... | function([38, 95, 33, 12, 6, 49, 68, 23, 82, 25], [79, 81, 11, 31, 83, 97, 86, 62, 85, 55]) | 1 | 217 | 0.220103 |
Code:
def function(sensor1: List[int], sensor2: List[int]) -> int:
i, n = 0, len(sensor1)
while i < n - 1:
if sensor1[i] != sensor2[i]:
break
i += 1
while i < n - 1:
if sensor1[i + 1] != sensor2[i]:
return 1
if sensor1[i] != sensor2[i + 1]:
... |
def function(costs: List[int], coins: int) -> int:
costs.sort()
for i, c in enumerate(costs):
if coins < c:
return i
coins -= c
return len(costs) | function([11, 21, 24, 34, 35, 42, 68, 71, 79, 85], 146) | 5 | 124 | 0.437939 |
Code:
def function(costs: List[int], coins: int) -> int:
costs.sort()
for i, c in enumerate(costs):
if coins < c:
return i
coins -= c
return len(costs)
Evaluate this code with the following inputs :
function([11, 21, 24, 34, 35, 42, 68, 71, 79, 85], 146)
Please evaluate the co... |
def function(nums: List[int], k: int) -> int:
nums.sort()
l, r, n = 0, 1, len(nums)
ans, window = 1, 0
while r < n:
window += (nums[r] - nums[r - 1]) * (r - l)
while window > k:
window -= nums[r] - nums[l]
l += 1
r += 1
ans = max(ans, r - l)
re... | function([13, 46, 48, 60, 66, 74, 92, 93, 95, 100], 65) | 5 | 187 | 2.115688 |
Code:
def function(nums: List[int], k: int) -> int:
nums.sort()
l, r, n = 0, 1, len(nums)
ans, window = 1, 0
while r < n:
window += (nums[r] - nums[r - 1]) * (r - l)
while window > k:
window -= nums[r] - nums[l]
l += 1
r += 1
ans = max(ans, r - l)... |
def function(word: str) -> int:
arr = []
n = len(word)
i = 0
while i < n:
j = i
while j < n and word[j] == word[i]:
j += 1
arr.append((word[i], j - i))
i = j
ans = 0
for i in range(len(arr) - 4):
a, b, c, d, e = arr[i : i + 5]
if a[0] +... | function('eeueuuuaeo') | 0 | 221 | 2.482978 |
Code:
def function(word: str) -> int:
arr = []
n = len(word)
i = 0
while i < n:
j = i
while j < n and word[j] == word[i]:
j += 1
arr.append((word[i], j - i))
i = j
ans = 0
for i in range(len(arr) - 4):
a, b, c, d, e = arr[i : i + 5]
if... |
def function(arr: List[int]) -> int:
arr.sort()
arr[0] = 1
for i in range(1, len(arr)):
d = max(0, arr[i] - arr[i - 1] - 1)
arr[i] -= d
return max(arr) | function([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | 10 | 138 | 1.936035 |
Code:
def function(arr: List[int]) -> int:
arr.sort()
arr[0] = 1
for i in range(1, len(arr)):
d = max(0, arr[i] - arr[i - 1] - 1)
arr[i] -= d
return max(arr)
Evaluate this code with the following inputs :
function([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Please evaluate the code with the give... |
def function(nums: List[int], k: int) -> List[int]:
cnt = Counter(nums[:k])
ans = [len(cnt)]
for i in range(k, len(nums)):
cnt[nums[i]] += 1
cnt[nums[i - k]] -= 1
if cnt[nums[i - k]] == 0:
cnt.pop(nums[i - k])
ans.append(len(cnt))
return ans | function([22, 61, 79, 82, 100, 66, 70, 26, 98, 18], 10) | [10] | 167 | 1.385464 |
Code:
def function(nums: List[int], k: int) -> List[int]:
cnt = Counter(nums[:k])
ans = [len(cnt)]
for i in range(k, len(nums)):
cnt[nums[i]] += 1
cnt[nums[i - k]] -= 1
if cnt[nums[i - k]] == 0:
cnt.pop(nums[i - k])
ans.append(len(cnt))
return ans
Evaluate t... |
def function(nums1: List[int], nums2: List[int]) -> int:
m, n = len(nums1), len(nums2)
ans = i = j = 0
while i < m:
while j < n and nums1[i] <= nums2[j]:
j += 1
ans = max(ans, j - i - 1)
i += 1
return ans | function([63, 78, 76, 99, 100, 55, 79, 19, 52, 29], [58, 39, 36, 87, 28, 5, 69, 3, 80, 75]) | 0 | 191 | 2.003487 |
Code:
def function(nums1: List[int], nums2: List[int]) -> int:
m, n = len(nums1), len(nums2)
ans = i = j = 0
while i < m:
while j < n and nums1[i] <= nums2[j]:
j += 1
ans = max(ans, j - i - 1)
i += 1
return ans
Evaluate this code with the following inputs :
function... |
def function(colors: str, edges: List[List[int]]) -> int:
n = len(colors)
indeg = [0] * n
g = defaultdict(list)
for a, b in edges:
g[a].append(b)
indeg[b] += 1
q = deque()
dp = [[0] * 26 for _ in range(n)]
for i, v in enumerate(indeg):
if v == 0:
q.append(... | function('vutzfiyte', [[1, 1], [8, 3], [8, 8], [3, 4], [8, 8], [0, 5], [0, 5], [0, 5], [5, 4], [7, 5], [3, 7]]) | -1 | 364 | 27.198241 |
Code:
def function(colors: str, edges: List[List[int]]) -> int:
n = len(colors)
indeg = [0] * n
g = defaultdict(list)
for a, b in edges:
g[a].append(b)
indeg[b] += 1
q = deque()
dp = [[0] * 26 for _ in range(n)]
for i, v in enumerate(indeg):
if v == 0:
q.... |
def function(n: int, k: int) -> int:
mod = 10**9 + 7
f = [1] + [0] * k
for i in range(1, n + 1):
for j in range(k, 0, -1):
f[j] = (f[j] * (i - 1) + f[j - 1]) % mod
f[0] = 0
return f[k] | function(10, 7) | 9450 | 150 | 7.17471 |
Code:
def function(n: int, k: int) -> int:
mod = 10**9 + 7
f = [1] + [0] * k
for i in range(1, n + 1):
for j in range(k, 0, -1):
f[j] = (f[j] * (i - 1) + f[j - 1]) % mod
f[0] = 0
return f[k]
Evaluate this code with the following inputs :
function(10, 7)
Please evaluate the... |
def function(nums1: List[int], nums2: List[int]) -> int:
nums1.sort()
nums2.sort()
n, res = len(nums1), 0
for i in range(n):
res += nums1[i] * nums2[n - i - 1]
return res | function([11, 22, 28, 29, 34, 51, 59, 74, 82, 100], [9, 19, 47, 54, 60, 67, 88, 92, 98, 100]) | 22844 | 168 | 1.078077 |
Code:
def function(nums1: List[int], nums2: List[int]) -> int:
nums1.sort()
nums2.sort()
n, res = len(nums1), 0
for i in range(n):
res += nums1[i] * nums2[n - i - 1]
return res
Evaluate this code with the following inputs :
function([11, 22, 28, 29, 34, 51, 59, 74, 82, 100], [9, 19, 47, 54... |
def function(s: str) -> int:
count, n = 0, len(s)
for i in range(n - 2):
count += s[i] != s[i + 1] and s[i] != s[i + 2] and s[i + 1] != s[i + 2]
return count | function('uqvebyoqyczdlmgybfwsmsmrjwgxlcsqjyrccirpqhkyndmvgtrexmqhukjzbmcidmtvpitezrhjjjomtplnaepasovwymteyqp') | 90 | 168 | 18.616948 |
Code:
def function(s: str) -> int:
count, n = 0, len(s)
for i in range(n - 2):
count += s[i] != s[i + 1] and s[i] != s[i + 2] and s[i + 1] != s[i + 2]
return count
Evaluate this code with the following inputs :
function('uqvebyoqyczdlmgybfwsmsmrjwgxlcsqjyrccirpqhkyndmvgtrexmqhukjzbmcidmtvpitezrhjj... |
def function(nums: List[int]) -> int:
nums.sort()
n = len(nums)
return max(x + nums[n - i - 1] for i, x in enumerate(nums[: n >> 1])) | function([14, 16, 17, 24, 36, 44, 58, 71, 78, 79]) | 94 | 117 | 0.951128 |
Code:
def function(nums: List[int]) -> int:
nums.sort()
n = len(nums)
return max(x + nums[n - i - 1] for i, x in enumerate(nums[: n >> 1]))
Evaluate this code with the following inputs :
function([14, 16, 17, 24, 36, 44, 58, 71, 78, 79])
Please evaluate the code with the given inputs and provide the expe... |
def function(n: str, x: int) -> str:
if n[0] != '-':
for i, c in enumerate(n):
if int(c) < x:
return n[:i] + str(x) + n[i:]
return n + str(x)
else:
for i, c in enumerate(n[1:]):
if int(c) > x:
return n[: i + 1] + str(x) + n[i + 1 :]... | function('9946892928', 3) | 99468932928 | 160 | 1.142038 |
Code:
def function(n: str, x: int) -> str:
if n[0] != '-':
for i, c in enumerate(n):
if int(c) < x:
return n[:i] + str(x) + n[i:]
return n + str(x)
else:
for i, c in enumerate(n[1:]):
if int(c) > x:
return n[: i + 1] + str(x) + n[i... |
def function(nums: List[int]) -> int:
nums.sort()
ans = cnt = 0
for i, v in enumerate(nums[1:]):
if v != nums[i]:
cnt += 1
ans += cnt
return ans | function([200, 201, 215, 250, 340, 372, 685, 697, 703, 987]) | 45 | 127 | 0.789712 |
Code:
def function(nums: List[int]) -> int:
nums.sort()
ans = cnt = 0
for i, v in enumerate(nums[1:]):
if v != nums[i]:
cnt += 1
ans += cnt
return ans
Evaluate this code with the following inputs :
function([200, 201, 215, 250, 340, 372, 685, 697, 703, 987])
Please evaluat... |
def function(ribbons: List[int], k: int) -> int:
left, right = 0, max(ribbons)
while left < right:
mid = (left + right + 1) >> 1
cnt = sum(x // mid for x in ribbons)
if cnt >= k:
left = mid
else:
right = mid - 1
return left | function([84, 38, 30, 75, 81, 17, 73, 97, 51, 16], 96) | 5 | 163 | 5.426472 |
Code:
def function(ribbons: List[int], k: int) -> int:
left, right = 0, max(ribbons)
while left < right:
mid = (left + right + 1) >> 1
cnt = sum(x // mid for x in ribbons)
if cnt >= k:
left = mid
else:
right = mid - 1
return left
Evaluate this code w... |
def function(chalk: List[int], k: int) -> int:
s = sum(chalk)
k %= s
for i, x in enumerate(chalk):
if k < x:
return i
k -= x | function([84, 21, 39, 45, 76, 37, 98, 68, 10, 50], 948218953) | 2 | 125 | 0.402524 |
Code:
def function(chalk: List[int], k: int) -> int:
s = sum(chalk)
k %= s
for i, x in enumerate(chalk):
if k < x:
return i
k -= x
Evaluate this code with the following inputs :
function([84, 21, 39, 45, 76, 37, 98, 68, 10, 50], 948218953)
Please evaluate the code with the giv... |
def function(num: str) -> str:
for i in range(len(num) - 1, -1, -1):
if (int(num[i]) & 1) == 1:
return num[: i + 1]
return '' | function('3826166635') | 3826166635 | 101 | 0.34534 |
Code:
def function(num: str) -> str:
for i in range(len(num) - 1, -1, -1):
if (int(num[i]) & 1) == 1:
return num[: i + 1]
return ''
Evaluate this code with the following inputs :
function('3826166635')
Please evaluate the code with the given inputs and provide the expected output in \boxe... |
def function(nums: List[int]) -> int:
f = g = 0
for x in nums:
f, g = max(g - x, f), max(f + x, g)
return max(f, g) | function([89, 55, 41, 63, 69, 58, 50, 39, 81, 54]) | 159 | 121 | 2.500458 |
Code:
def function(nums: List[int]) -> int:
f = g = 0
for x in nums:
f, g = max(g - x, f), max(f + x, g)
return max(f, g)
Evaluate this code with the following inputs :
function([89, 55, 41, 63, 69, 58, 50, 39, 81, 54])
Please evaluate the code with the given inputs and provide the expected outpu... |
def function(dist: List[int], speed: List[int]) -> int:
times = sorted((d - 1) // s for d, s in zip(dist, speed))
for i, t in enumerate(times):
if t < i:
return i
return len(times) | function([83, 5, 57, 63, 78, 58, 85, 93, 55, 11], [100, 76, 18, 61, 42, 96, 43, 22, 60, 58]) | 1 | 162 | 1.417591 |
Code:
def function(dist: List[int], speed: List[int]) -> int:
times = sorted((d - 1) // s for d, s in zip(dist, speed))
for i, t in enumerate(times):
if t < i:
return i
return len(times)
Evaluate this code with the following inputs :
function([83, 5, 57, 63, 78, 58, 85, 93, 55, 11], [1... |
def function(num: str, change: List[int]) -> str:
s = list(num)
for i, c in enumerate(s):
if change[int(c)] > int(c):
while i < len(s) and int(s[i]) <= change[int(s[i])]:
s[i] = str(change[int(s[i])])
i += 1
break
return ''.join(s) | function('86871', [2, 7, 5, 9, 7, 1, 6, 9, 1, 7]) | 86897 | 160 | 1.935207 |
Code:
def function(num: str, change: List[int]) -> str:
s = list(num)
for i, c in enumerate(s):
if change[int(c)] > int(c):
while i < len(s) and int(s[i]) <= change[int(s[i])]:
s[i] = str(change[int(s[i])])
i += 1
break
return ''.join(s)
Eval... |
def function(milestones: List[int]) -> int:
mx, s = max(milestones), sum(milestones)
rest = s - mx
return rest * 2 + 1 if mx > rest + 1 else s | function([142286520, 320043938, 84748453, 329353808, 790010703, 476064108, 558678992, 117575386, 51988395, 121295425]) | 2992045728 | 144 | 0.449867 |
Code:
def function(milestones: List[int]) -> int:
mx, s = max(milestones), sum(milestones)
rest = s - mx
return rest * 2 + 1 if mx > rest + 1 else s
Evaluate this code with the following inputs :
function([142286520, 320043938, 84748453, 329353808, 790010703, 476064108, 558678992, 117575386, 51988395, 121... |
def function(neededApples: int) -> int:
l, r = 1, 100000
while l < r:
mid = (l + r) >> 1
if 2 * mid * (mid + 1) * (2 * mid + 1) >= neededApples:
r = mid
else:
l = mid + 1
return l * 8 | function(865612822944748) | 480296 | 140 | 3.058972 |
Code:
def function(neededApples: int) -> int:
l, r = 1, 100000
while l < r:
mid = (l + r) >> 1
if 2 * mid * (mid + 1) * (2 * mid + 1) >= neededApples:
r = mid
else:
l = mid + 1
return l * 8
Evaluate this code with the following inputs :
function(865612822944... |
def function(nums: List[int]) -> int:
mod = 10**9 + 7
n = len(nums)
f = [0] * 3
f[0] = nums[0] == 0
for i in range(1, n):
if nums[i] == 0:
f[0] = (2 * f[0] + 1) % mod
elif nums[i] == 1:
f[1] = (f[0] + 2 * f[1]) % mod
else:
f[2] = (f[1] + 2 ... | function([1, 2, 0, 1, 1, 1, 0, 0, 2, 0]) | 7 | 223 | 1.006399 |
Code:
def function(nums: List[int]) -> int:
mod = 10**9 + 7
n = len(nums)
f = [0] * 3
f[0] = nums[0] == 0
for i in range(1, n):
if nums[i] == 0:
f[0] = (2 * f[0] + 1) % mod
elif nums[i] == 1:
f[1] = (f[0] + 2 * f[1]) % mod
else:
f[2] = (f[... |
def function(s: str) -> int:
x = 0
for c in s:
if c == "[":
x += 1
elif x:
x -= 1
return (x + 1) >> 1 | function('[[[[[]]]]]') | 0 | 103 | 0.385566 |
Code:
def function(s: str) -> int:
x = 0
for c in s:
if c == "[":
x += 1
elif x:
x -= 1
return (x + 1) >> 1
Evaluate this code with the following inputs :
function('[[[[[]]]]]')
Please evaluate the code with the given inputs and provide the expected output in \boxe... |
def function(nums: List[int]) -> List[int]:
nums.sort()
n = len(nums)
m = (n + 1) >> 1
ans = []
for i in range(m):
ans.append(nums[i])
if i + m < n:
ans.append(nums[i + m])
return ans | function([16, 19, 43, 54, 70, 80, 81, 83, 89, 100]) | [16, 80, 19, 81, 43, 83, 54, 89, 70, 100] | 142 | 0.642046 |
Code:
def function(nums: List[int]) -> List[int]:
nums.sort()
n = len(nums)
m = (n + 1) >> 1
ans = []
for i in range(m):
ans.append(nums[i])
if i + m < n:
ans.append(nums[i + m])
return ans
Evaluate this code with the following inputs :
function([16, 19, 43, 54, 70,... |
def function(word: str) -> int:
ans = prev = 0
for c in word:
curr = ord(c) - ord('a')
t = abs(prev - curr)
t = min(t, 26 - t)
ans += t + 1
prev = curr
return ans | function("omunwmuetukuurnarcotezatqzxldiwgxdfbeeppnawdqqjgjbipgyiylfpwrvbtzmwfqcidfstdmbbsbdzlwuauxvioyvfnelyl") | 821 | 165 | 20.837437 |
Code:
def function(word: str) -> int:
ans = prev = 0
for c in word:
curr = ord(c) - ord('a')
t = abs(prev - curr)
t = min(t, 26 - t)
ans += t + 1
prev = curr
return ans
Evaluate this code with the following inputs :
function("omunwmuetukuurnarcotezatqzxldiwgxdfbeepp... |
def function(mat: List[List[int]], target: int) -> int:
f = {0}
for row in mat:
f = set(a + b for a in f for b in row)
return min(abs(v - target) for v in f) | function([[51, 62, 67, 19, 14, 42], [29, 69, 3, 42, 19, 15], [13, 48, 49, 12, 10, 31], [59, 65, 44, 53, 22, 32], [71, 27, 28, 62, 58, 33], [3, 17, 71, 70, 59, 38]], 235) | 0 | 208 | 183.564697 |
Code:
def function(mat: List[List[int]], target: int) -> int:
f = {0}
for row in mat:
f = set(a + b for a in f for b in row)
return min(abs(v - target) for v in f)
Evaluate this code with the following inputs :
function([[51, 62, 67, 19, 14, 42], [29, 69, 3, 42, 19, 15], [13, 48, 49, 12, 10, 31], ... |
def function(nums: List[int], k: int) -> int:
nums.sort()
return min(nums[i + k - 1] - nums[i] for i in range(len(nums) - k + 1)) | function([12, 16, 17, 18, 20, 35, 63, 89, 91, 100], 6) | 23 | 120 | 0.904938 |
Code:
def function(nums: List[int], k: int) -> int:
nums.sort()
return min(nums[i + k - 1] - nums[i] for i in range(len(nums) - k + 1))
Evaluate this code with the following inputs :
function([12, 16, 17, 18, 20, 35, 63, 89, 91, 100], 6)
Please evaluate the code with the given inputs and provide the expected... |
def function(binary: str) -> int:
f = g = 0
ans = 0
mod = 10**9 + 7
for c in binary:
if c == "0":
g = (g + f) % mod
ans = 1
else:
f = (f + g + 1) % mod
ans = (ans + f + g) % mod
return ans | function("11110101001") | 143 | 145 | 0.648857 |
Code:
def function(binary: str) -> int:
f = g = 0
ans = 0
mod = 10**9 + 7
for c in binary:
if c == "0":
g = (g + f) % mod
ans = 1
else:
f = (f + g + 1) % mod
ans = (ans + f + g) % mod
return ans
Evaluate this code with the following inputs :
... |
def function(team: List[int], dist: int) -> int:
ans = j = 0
n = len(team)
for i, x in enumerate(team):
if x:
while j < n and (team[j] or i - j > dist):
j += 1
if j < n and abs(i - j) <= dist:
ans += 1
j += 1
return ans | function([0, 1, 1, 0, 1, 0, 1, 1, 0, 0], 5) | 5 | 168 | 1.05729 |
Code:
def function(team: List[int], dist: int) -> int:
ans = j = 0
n = len(team)
for i, x in enumerate(team):
if x:
while j < n and (team[j] or i - j > dist):
j += 1
if j < n and abs(i - j) <= dist:
ans += 1
j += 1
return a... |
def function(land: List[List[int]]) -> List[List[int]]:
m, n = len(land), len(land[0])
ans = []
for i in range(m):
for j in range(n):
if (
land[i][j] == 0
or (j > 0 and land[i][j - 1] == 1)
or (i > 0 and land[i - 1][j] == 1)
):
... | function([[0, 0, 1, 0, 0, 1, 1, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 1], [1, 0, 0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1, 1, 1], [0, 1, 1, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 1, 0, 1], [0, 0, 0, 0, 1, 1, 1, ... | [[0, 2, 0, 2], [0, 5, 2, 5], [0, 8, 0, 9], [1, 0, 1, 1], [2, 4, 6, 5], [2, 7, 2, 9], [3, 0, 3, 0], [3, 3, 7, 3], [4, 2, 4, 4], [4, 6, 4, 6], [5, 9, 9, 9], [6, 0, 6, 0], [6, 2, 8, 2], [6, 7, 8, 7], [7, 1, 7, 3], [8, 0, 8, 0], [8, 4, 9, 6], [8, 6, 9, 6], [9, 8, 9, 9]] | 525 | 11.903866 |
Code:
def function(land: List[List[int]]) -> List[List[int]]:
m, n = len(land), len(land[0])
ans = []
for i in range(m):
for j in range(n):
if (
land[i][j] == 0
or (j > 0 and land[i][j - 1] == 1)
or (i > 0 and land[i - 1][j] == 1)
... |
def function(nums: List[int]) -> int:
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
cnt = Counter(nums)
mod = 10**9 + 7
n = len(primes)
f = [0] * (1 << n)
f[0] = pow(2, cnt[1])
for x in range(2, 31):
if cnt[x] == 0 or x % 4 == 0 or x % 9 == 0 or x % 25 == 0:
continue
... | function([4, 25, 20, 12, 18, 30, 6, 24, 23, 10]) | 7 | 315 | 289.495988 |
Code:
def function(nums: List[int]) -> int:
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
cnt = Counter(nums)
mod = 10**9 + 7
n = len(primes)
f = [0] * (1 << n)
f[0] = pow(2, cnt[1])
for x in range(2, 31):
if cnt[x] == 0 or x % 4 == 0 or x % 9 == 0 or x % 25 == 0:
contin... |
def function(word: str, ch: str) -> str:
i = word.find(ch)
return word if i == -1 else word[i::-1] + word[i + 1 :] | function('ekahxdkbhf', 'i') | ekahxdkbhf | 94 | 0.139428 |
Code:
def function(word: str, ch: str) -> str:
i = word.find(ch)
return word if i == -1 else word[i::-1] + word[i + 1 :]
Evaluate this code with the following inputs :
function('ekahxdkbhf', 'i')
Please evaluate the code with the given inputs and provide the expected output in \boxed{} format. Do not output ... |
def function(s: str) -> int:
n = len(s)
p = [True] * (1 << n)
for k in range(1, 1 << n):
i, j = 0, n - 1
while i < j:
while i < j and (k >> i & 1) == 0:
i += 1
while i < j and (k >> j & 1) == 0:
j -= 1
if i < j and s[i] != s... | function('kodzbtaqznfz') | 3 | 289 | 3,136.810914 |
Code:
def function(s: str) -> int:
n = len(s)
p = [True] * (1 << n)
for k in range(1, 1 << n):
i, j = 0, n - 1
while i < j:
while i < j and (k >> i & 1) == 0:
i += 1
while i < j and (k >> j & 1) == 0:
j -= 1
if i < j and s[... |
def function(changed: List[int]) -> List[int]:
n = len(changed)
if n & 1:
return []
cnt = Counter(changed)
changed.sort()
ans = []
for x in changed:
if cnt[x] == 0:
continue
if cnt[x * 2] <= 0:
return []
ans.append(x)
cnt[x] -= 1
... | function([25, 31, 36, 45, 58, 67, 72, 81, 89, 93]) | [] | 186 | 1.496662 |
Code:
def function(changed: List[int]) -> List[int]:
n = len(changed)
if n & 1:
return []
cnt = Counter(changed)
changed.sort()
ans = []
for x in changed:
if cnt[x] == 0:
continue
if cnt[x * 2] <= 0:
return []
ans.append(x)
cnt[x] ... |
def function(nums: List[int]) -> int:
n = len(nums)
nums = sorted(set(nums))
ans, j = n, 0
for i, v in enumerate(nums):
while j < len(nums) and nums[j] - v <= n - 1:
j += 1
ans = min(ans, n - (j - i))
return ans | function([72, 65, 31, 86, 48, 15, 13, 61, 92, 47]) | 8 | 155 | 3.024543 |
Code:
def function(nums: List[int]) -> int:
n = len(nums)
nums = sorted(set(nums))
ans, j = n, 0
for i, v in enumerate(nums):
while j < len(nums) and nums[j] - v <= n - 1:
j += 1
ans = min(ans, n - (j - i))
return ans
Evaluate this code with the following inputs :
funct... |
def function(buildings: List[List[int]]) -> List[List[int]]:
height = defaultdict(int)
cnt = defaultdict(int)
for s, e, h in buildings:
cnt[s] += 1
cnt[e] -= 1
height[s] += h
height[e] -= h
ans = []
i = h = n = 0
for j in sorted(cnt.keys()):
if n:
... | function([[3, 11, 8], [10, 14, 1], [9, 18, 2], [10, 14, 10], [7, 13, 8]]) | [[3, 9, 8], [9, 10, 6], [10, 13, 5], [13, 14, 4], [14, 18, 2]] | 253 | 5.292606 |
Code:
def function(buildings: List[List[int]]) -> List[List[int]]:
height = defaultdict(int)
cnt = defaultdict(int)
for s, e, h in buildings:
cnt[s] += 1
cnt[e] -= 1
height[s] += h
height[e] -= h
ans = []
i = h = n = 0
for j in sorted(cnt.keys()):
if n:
... |
def function(n: int, relations: List[List[int]], time: List[int]) -> int:
g = defaultdict(list)
indeg = [0] * n
for a, b in relations:
g[a - 1].append(b - 1)
indeg[b - 1] += 1
q = deque()
f = [0] * n
ans = 0
for i, (v, t) in enumerate(zip(indeg, time)):
if v == 0:
... | function(n = 11, relations = [[2, 3], [7, 9], [6, 11], [10, 11], [7, 8], [4, 10], [7, 11], [3, 1], [7, 4], [6, 11]], time = [2, 10, 6, 11, 7, 7, 4, 2, 5, 9, 4]) | 28 | 347 | 8.287524 |
Code:
def function(n: int, relations: List[List[int]], time: List[int]) -> int:
g = defaultdict(list)
indeg = [0] * n
for a, b in relations:
g[a - 1].append(b - 1)
indeg[b - 1] += 1
q = deque()
f = [0] * n
ans = 0
for i, (v, t) in enumerate(zip(indeg, time)):
if v ==... |
def function(nums: List[int], k: int) -> List[int]:
s = 0
ans = [-1] * len(nums)
for i, v in enumerate(nums):
s += v
if i >= k * 2:
ans[i - k] = s // (k * 2 + 1)
s -= nums[i - k * 2]
return ans | function([67, 47, 18, 35, 60, 100, 82, 21, 25, 70], 88) | [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] | 161 | 0.709623 |
Code:
def function(nums: List[int], k: int) -> List[int]:
s = 0
ans = [-1] * len(nums)
for i, v in enumerate(nums):
s += v
if i >= k * 2:
ans[i - k] = s // (k * 2 + 1)
s -= nums[i - k * 2]
return ans
Evaluate this code with the following inputs :
function([67, 4... |
def function(security: List[int], time: int) -> List[int]:
n = len(security)
if n <= time * 2:
return []
left, right = [0] * n, [0] * n
for i in range(1, n):
if security[i] <= security[i - 1]:
left[i] = left[i - 1] + 1
for i in range(n - 2, -1, -1):
if security[i]... | function([95, 23, 48, 70, 82, 18, 13, 86, 100, 84], 128) | [] | 227 | 0.175421 |
Code:
def function(security: List[int], time: int) -> List[int]:
n = len(security)
if n <= time * 2:
return []
left, right = [0] * n, [0] * n
for i in range(1, n):
if security[i] <= security[i - 1]:
left[i] = left[i - 1] + 1
for i in range(n - 2, -1, -1):
if secu... |
def function(fruits: List[List[int]], startPos: int, k: int) -> int:
ans = i = s = 0
for j, (pj, fj) in enumerate(fruits):
s += fj
while (
i <= j
and pj
- fruits[i][0]
+ min(abs(startPos - fruits[i][0]), abs(startPos - fruits[j][0]))
> ... | function([[3, 10], [8, 2], [10, 7], [4, 7], [9, 5], [8, 2], [5, 2], [5, 10], [10, 2], [0, 6]], 9, 9) | 53 | 228 | 3.898831 |
Code:
def function(fruits: List[List[int]], startPos: int, k: int) -> int:
ans = i = s = 0
for j, (pj, fj) in enumerate(fruits):
s += fj
while (
i <= j
and pj
- fruits[i][0]
+ min(abs(startPos - fruits[i][0]), abs(startPos - fruits[j][0]))
... |
def function(words: List[str]) -> str:
return next((w for w in words if w == w[::-1]), "") | function(['qfrpxmiwha', 'tbzznp', 'qmebdklma', 'fi', 'iukvhnst', 'bcefmevdg', 'rcpjrqk', 'enmzwunhoc', 'xjztvcoq']) | 127 | 1.136738 |
Code:
def function(words: List[str]) -> str:
return next((w for w in words if w == w[::-1]), "")
Evaluate this code with the following inputs :
function(['qfrpxmiwha', 'tbzznp', 'qmebdklma', 'fi', 'iukvhnst', 'bcefmevdg', 'rcpjrqk', 'enmzwunhoc', 'xjztvcoq'])
Please evaluate the code with the given inputs and pr... | |
def function(prices: List[int]) -> int:
ans = 0
i, n = 0, len(prices)
while i < n:
j = i + 1
while j < n and prices[j - 1] - prices[j] == 1:
j += 1
cnt = j - i
ans += (1 + cnt) * cnt // 2
i = j
return ans | function([96, 72, 66, 75, 25, 83, 31, 94, 51, 48, 92]) | 11 | 173 | 1.345978 |
Code:
def function(prices: List[int]) -> int:
ans = 0
i, n = 0, len(prices)
while i < n:
j = i + 1
while j < n and prices[j - 1] - prices[j] == 1:
j += 1
cnt = j - i
ans += (1 + cnt) * cnt // 2
i = j
return ans
Evaluate this code with the following i... |
def function(nums: List[int]) -> List[int]:
nums.sort()
n = len(nums)
for i in range(1, n):
d = nums[i] - nums[0]
if d == 0 or d % 2 == 1:
continue
vis = [False] * n
vis[i] = True
ans = [(nums[0] + nums[i]) >> 1]
l, r = 1, i + 1
while r < n... | function([11, 15, 20, 25, 38, 50, 57, 59, 60, 63, 69, 70, 76, 81, 84, 86, 90, 92, 93, 96]) | [] | 324 | 4.640594 |
Code:
def function(nums: List[int]) -> List[int]:
nums.sort()
n = len(nums)
for i in range(1, n):
d = nums[i] - nums[0]
if d == 0 or d % 2 == 1:
continue
vis = [False] * n
vis[i] = True
ans = [(nums[0] + nums[i]) >> 1]
l, r = 1, i + 1
whil... |
def function(words: List[str]) -> int:
cnt = Counter(words)
ans = x = 0
for k, v in cnt.items():
if k[0] == k[1]:
x += v & 1
ans += v // 2 * 2 * 2
else:
ans += min(v, cnt[k[::-1]]) * 2
ans += 2 if x else 0
return ans | function(['rf', 'xa', 'mu', 'cu', 'dx', 'rw', 'ha', 'ik', 'nt', 'xr']) | 0 | 170 | 4.984667 |
Code:
def function(words: List[str]) -> int:
cnt = Counter(words)
ans = x = 0
for k, v in cnt.items():
if k[0] == k[1]:
x += v & 1
ans += v // 2 * 2 * 2
else:
ans += min(v, cnt[k[::-1]]) * 2
ans += 2 if x else 0
return ans
Evaluate this code with... |
def function(plantTime: List[int], growTime: List[int]) -> int:
ans = t = 0
for pt, gt in sorted(zip(plantTime, growTime), key=lambda x: -x[1]):
t += pt
ans = max(ans, t + gt)
return ans | function([4, 5, 7, 8, 2, 3, 9, 10, 6, 1], [2, 8, 5, 7, 4, 3, 1, 6, 9, 10]) | 56 | 170 | 2.767225 |
Code:
def function(plantTime: List[int], growTime: List[int]) -> int:
ans = t = 0
for pt, gt in sorted(zip(plantTime, growTime), key=lambda x: -x[1]):
t += pt
ans = max(ans, t + gt)
return ans
Evaluate this code with the following inputs :
function([4, 5, 7, 8, 2, 3, 9, 10, 6, 1], [2, 8, 5... |
def function(target: int, maxDoubles: int) -> int:
ans = 0
while maxDoubles and target > 1:
ans += 1
if target % 2 == 1:
target -= 1
else:
maxDoubles -= 1
target >>= 1
ans += target - 1
return ans | function(858861642, 100) | 40 | 132 | 3.291353 |
Code:
def function(target: int, maxDoubles: int) -> int:
ans = 0
while maxDoubles and target > 1:
ans += 1
if target % 2 == 1:
target -= 1
else:
maxDoubles -= 1
target >>= 1
ans += target - 1
return ans
Evaluate this code with the following i... |
def function(n: int, batteries: List[int]) -> int:
l, r = 0, sum(batteries)
while l < r:
mid = (l + r + 1) >> 1
if sum(min(x, mid) for x in batteries) >= n * mid:
l = mid
else:
r = mid - 1
return l | function(11, [21, 83, 51, 72, 55, 64, 63, 41, 100, 12, 22]) | 12 | 163 | 15.553613 |
Code:
def function(n: int, batteries: List[int]) -> int:
l, r = 0, sum(batteries)
while l < r:
mid = (l + r + 1) >> 1
if sum(min(x, mid) for x in batteries) >= n * mid:
l = mid
else:
r = mid - 1
return l
Evaluate this code with the following inputs :
functio... |
def function(nums: List[int], original: int) -> int:
s = set(nums)
while original in s:
original <<= 1
return original | function([36, 57, 66, 67, 96, 64, 13, 86, 43, 34], 687) | 687 | 110 | 0.299332 |
Code:
def function(nums: List[int], original: int) -> int:
s = set(nums)
while original in s:
original <<= 1
return original
Evaluate this code with the following inputs :
function([36, 57, 66, 67, 96, 64, 13, 86, 43, 34], 687)
Please evaluate the code with the given inputs and provide the expect... |
def function(num: int) -> int:
nums = []
while num:
nums.append(num % 10)
num //= 10
nums.sort()
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3] | function(8537) | 95 | 105 | 0.371918 |
Code:
def function(num: int) -> int:
nums = []
while num:
nums.append(num % 10)
num //= 10
nums.sort()
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3]
Evaluate this code with the following inputs :
function(8537)
Please evaluate the code with the given inputs and provide the expec... |
def function(num: int) -> int:
if num == 0:
return 0
cnt = [0] * 10
neg = num < 0
num = abs(num)
while num:
num, v = divmod(num, 10)
cnt[v] += 1
ans = ""
if neg:
for i in range(9, -1, -1):
if cnt[i]:
ans += str(i) * cnt[i]
r... | function(-766346080263622) | -876666643322200 | 227 | 2.911725 |
Code:
def function(num: int) -> int:
if num == 0:
return 0
cnt = [0] * 10
neg = num < 0
num = abs(num)
while num:
num, v = divmod(num, 10)
cnt[v] += 1
ans = ""
if neg:
for i in range(9, -1, -1):
if cnt[i]:
ans += str(i) * cnt[i]
... |
def function(beans: List[int]) -> int:
beans.sort()
ans = s = sum(beans)
n = len(beans)
for i, v in enumerate(beans):
ans = min(ans, s - v * (n - i))
return ans | function([20, 26, 30, 41, 61, 67, 84, 86, 88, 100]) | 237 | 131 | 1.905409 |
Code:
def function(beans: List[int]) -> int:
beans.sort()
ans = s = sum(beans)
n = len(beans)
for i, v in enumerate(beans):
ans = min(ans, s - v * (n - i))
return ans
Evaluate this code with the following inputs :
function([20, 26, 30, 41, 61, 67, 84, 86, 88, 100])
Please evaluate the cod... |
def function(finalSum: int) -> List[int]:
if finalSum % 2:
return []
i = 2
ans = []
while i <= finalSum:
ans.append(i)
finalSum -= i
i += 2
ans[-1] += finalSum
return ans | function(100) | [2, 4, 6, 8, 10, 12, 14, 16, 28] | 113 | 0.504037 |
Code:
def function(finalSum: int) -> List[int]:
if finalSum % 2:
return []
i = 2
ans = []
while i <= finalSum:
ans.append(i)
finalSum -= i
i += 2
ans[-1] += finalSum
return ans
Evaluate this code with the following inputs :
function(100)
Please evaluate the cod... |
def function(s: str, repeatLimit: int) -> str:
cnt = [0] * 26
for c in s:
cnt[ord(c) - ord('a')] += 1
ans = []
for i in range(25, -1, -1):
j = i - 1
while 1:
for _ in range(min(repeatLimit, cnt[i])):
cnt[i] -= 1
ans.append(chr(ord('a') ... | function("nngxtscvkqaezwaxeppxotsuzaccsejucieldmwllaqsvndoscsysrsuaddwotfyjvcbrgmbxjrspkcsxkhrfdwyyqreknnlwpks", 90) | zzyyyyxxxxxwwwwwvvvuuutttsssssssssssrrrrrqqqppppooonnnnnmmllllkkkkkjjjihggffeeeeedddddcccccccbbaaaaa | 275 | 21.885511 |
Code:
def function(s: str, repeatLimit: int) -> str:
cnt = [0] * 26
for c in s:
cnt[ord(c) - ord('a')] += 1
ans = []
for i in range(25, -1, -1):
j = i - 1
while 1:
for _ in range(min(repeatLimit, cnt[i])):
cnt[i] -= 1
ans.append(chr(or... |
def function(s: str) -> int:
cs = list(s)
ans, n = 0, len(s)
i, j = 0, n - 1
while i < j:
even = False
for k in range(j, i, -1):
if cs[i] == cs[k]:
even = True
while k < j:
cs[k], cs[k + 1] = cs[k + 1], cs[k]
... | function("gomqxpvjkp") | 12 | 196 | 2.963617 |
Code:
def function(s: str) -> int:
cs = list(s)
ans, n = 0, len(s)
i, j = 0, n - 1
while i < j:
even = False
for k in range(j, i, -1):
if cs[i] == cs[k]:
even = True
while k < j:
cs[k], cs[k + 1] = cs[k + 1], cs[k]
... |
def function(nums: List[int], k: int) -> int:
if k == 0:
return nums[0]
n = len(nums)
if n == 1:
if k % 2:
return -1
return nums[0]
ans = max(nums[: k - 1], default=-1)
if k < n:
ans = max(ans, nums[k])
return ans | function([61, 76, 71, 69, 20, 93, 36, 75, 46, 62], 50) | 93 | 166 | 0.553804 |
Code:
def function(nums: List[int], k: int) -> int:
if k == 0:
return nums[0]
n = len(nums)
if n == 1:
if k % 2:
return -1
return nums[0]
ans = max(nums[: k - 1], default=-1)
if k < n:
ans = max(ans, nums[k])
return ans
Evaluate this code with the fo... |
def function(text: str, pattern: str) -> int:
ans = 0
cnt = Counter()
for c in text:
if c == pattern[1]:
ans += cnt[pattern[0]]
cnt[c] += 1
ans += max(cnt[pattern[0]], cnt[pattern[1]])
return ans | function("qusnhldokk", "uv") | 1 | 126 | 3.067423 |
Code:
def function(text: str, pattern: str) -> int:
ans = 0
cnt = Counter()
for c in text:
if c == pattern[1]:
ans += cnt[pattern[0]]
cnt[c] += 1
ans += max(cnt[pattern[0]], cnt[pattern[1]])
return ans
Evaluate this code with the following inputs :
function("qusnhldokk"... |
def function(damage: List[int], armor: int) -> int:
return sum(damage) - min(max(damage), armor) + 1 | function([19, 51, 11, 34, 100, 22, 27, 60, 89, 29], 69) | 374 | 107 | 0.508093 |
Code:
def function(damage: List[int], armor: int) -> int:
return sum(damage) - min(max(damage), armor) + 1
Evaluate this code with the following inputs :
function([19, 51, 11, 34, 100, 22, 27, 60, 89, 29], 69)
Please evaluate the code with the given inputs and provide the expected output in \boxed{} format. Do n... |
def function(nums: List[int]) -> int:
n = len(nums)
i = ans = 0
while i < n - 1:
if nums[i] == nums[i + 1]:
ans += 1
i += 1
else:
i += 2
ans += (n - ans) % 2
return ans | function([85, 22, 23, 25, 4, 100, 50, 64, 41, 53]) | 0 | 153 | 0.402812 |
Code:
def function(nums: List[int]) -> int:
n = len(nums)
i = ans = 0
while i < n - 1:
if nums[i] == nums[i + 1]:
ans += 1
i += 1
else:
i += 2
ans += (n - ans) % 2
return ans
Evaluate this code with the following inputs :
function([85, 22, 23, 25... |
def function(start: int, goal: int) -> int:
t = start ^ goal
ans = 0
while t:
ans += t & 1
t >>= 1
return ans | function(428352171, 809639476) | 17 | 99 | 1.695912 |
Code:
def function(start: int, goal: int) -> int:
t = start ^ goal
ans = 0
while t:
ans += t & 1
t >>= 1
return ans
Evaluate this code with the following inputs :
function(428352171, 809639476)
Please evaluate the code with the given inputs and provide the expected output in \boxed{} ... |
def function(s: str) -> int:
n = len(s)
cnt0 = s.count("0")
cnt1 = n - cnt0
c0 = c1 = 0
ans = 0
for c in s:
if c == "0":
ans += c1 * (cnt1 - c1)
c0 += 1
else:
ans += c0 * (cnt0 - c0)
c1 += 1
return ans | function("0110101000") | 34 | 156 | 0.706789 |
Code:
def function(s: str) -> int:
n = len(s)
cnt0 = s.count("0")
cnt1 = n - cnt0
c0 = c1 = 0
ans = 0
for c in s:
if c == "0":
ans += c1 * (cnt1 - c1)
c0 += 1
else:
ans += c0 * (cnt0 - c0)
c1 += 1
return ans
Evaluate this code... |
def function(current: str, correct: str) -> int:
a = int(current[:2]) * 60 + int(current[3:])
b = int(correct[:2]) * 60 + int(correct[3:])
ans, d = 0, b - a
for i in [60, 15, 5, 1]:
ans += d // i
d %= i
return ans | function('13:45', '22:45') | 9 | 142 | 0.978453 |
Code:
def function(current: str, correct: str) -> int:
a = int(current[:2]) * 60 + int(current[3:])
b = int(correct[:2]) * 60 + int(correct[3:])
ans, d = 0, b - a
for i in [60, 15, 5, 1]:
ans += d // i
d %= i
return ans
Evaluate this code with the following inputs :
function('13:45... |
def function(num: int) -> int:
cnt = Counter()
x = num
while x:
x, v = divmod(x, 10)
cnt[v] += 1
x = num
ans = 0
t = 1
while x:
x, v = divmod(x, 10)
for y in range(10):
if ((v ^ y) & 1) == 0 and cnt[y]:
ans += y * t
... | function(417456353) | 675454331 | 176 | 9.486296 |
Code:
def function(num: int) -> int:
cnt = Counter()
x = num
while x:
x, v = divmod(x, 10)
cnt[v] += 1
x = num
ans = 0
t = 1
while x:
x, v = divmod(x, 10)
for y in range(10):
if ((v ^ y) & 1) == 0 and cnt[y]:
ans += y * t
... |
def function(s: str) -> int:
ans = t = 0
pos = [-1] * 26
for i, c in enumerate(s):
c = ord(c) - ord('a')
t += i - pos[c]
ans += t
pos[c] = i
return ans | function('ortipshejs') | 214 | 118 | 1.198915 |
Code:
def function(s: str) -> int:
ans = t = 0
pos = [-1] * 26
for i, c in enumerate(s):
c = ord(c) - ord('a')
t += i - pos[c]
ans += t
pos[c] = i
return ans
Evaluate this code with the following inputs :
function('ortipshejs')
Please evaluate the code with the given i... |
def function(num: int, k: int) -> int:
ans = 0
s = str(num)
for i in range(len(s) - k + 1):
t = int(s[i : i + k])
if t and num % t == 0:
ans += 1
return ans | function(222759711, 8) | 0 | 120 | 0.645996 |
Code:
def function(num: int, k: int) -> int:
ans = 0
s = str(num)
for i in range(len(s) - k + 1):
t = int(s[i : i + k])
if t and num % t == 0:
ans += 1
return ans
Evaluate this code with the following inputs :
function(222759711, 8)
Please evaluate the code with the given ... |
def function(present: List[int], future: List[int], budget: int) -> int:
f = [0] * (budget + 1)
for a, b in zip(present, future):
for j in range(budget, a - 1, -1):
f[j] = max(f[j], f[j - a] + b - a)
return f[-1] | function([71, 37, 1, 87, 27, 57, 9, 4, 77, 61], [77, 39, 17, 83, 78, 93, 23, 14, 66], 597) | 135 | 187 | 736.766044 |
Code:
def function(present: List[int], future: List[int], budget: int) -> int:
f = [0] * (budget + 1)
for a, b in zip(present, future):
for j in range(budget, a - 1, -1):
f[j] = max(f[j], f[j - a] + b - a)
return f[-1]
Evaluate this code with the following inputs :
function([71, 37, 1,... |
def function(nums: List[int], k: int) -> int:
nums.sort()
ans, a = 1, nums[0]
for b in nums:
if b - a > k:
a = b
ans += 1
return ans | function([3, 14, 30, 62, 65, 74, 81, 91, 92, 100], 46) | 2 | 133 | 0.418305 |
Code:
def function(nums: List[int], k: int) -> int:
nums.sort()
ans, a = 1, nums[0]
for b in nums:
if b - a > k:
a = b
ans += 1
return ans
Evaluate this code with the following inputs :
function([3, 14, 30, 62, 65, 74, 81, 91, 92, 100], 46)
Please evaluate the code wit... |
def function(nums: List[int], k: int) -> int:
ans = s = j = 0
for i, v in enumerate(nums):
s += v
while s * (i - j + 1) >= k:
s -= nums[j]
j += 1
ans += i - j + 1
return ans | function([53, 41, 21, 95, 78, 44, 63, 54, 87, 20], 897749083951292) | 55 | 157 | 1.153229 |
Code:
def function(nums: List[int], k: int) -> int:
ans = s = j = 0
for i, v in enumerate(nums):
s += v
while s * (i - j + 1) >= k:
s -= nums[j]
j += 1
ans += i - j + 1
return ans
Evaluate this code with the following inputs :
function([53, 41, 21, 95, 78, 4... |
def function(ideas: List[str]) -> int:
s = set(ideas)
f = [[0] * 26 for _ in range(26)]
for v in ideas:
i = ord(v[0]) - ord('a')
t = list(v)
for j in range(26):
t[0] = chr(ord('a') + j)
if ''.join(t) not in s:
f[i][j] += 1
ans = 0
for v... | function(['g', 'c', 'u', 'u', 'e', 'm', 'o', 'd', 'j', 'y']) | 0 | 247 | 62.958814 |
Code:
def function(ideas: List[str]) -> int:
s = set(ideas)
f = [[0] * 26 for _ in range(26)]
for v in ideas:
i = ord(v[0]) - ord('a')
t = list(v)
for j in range(26):
t[0] = chr(ord('a') + j)
if ''.join(t) not in s:
f[i][j] += 1
ans = 0
... |
def function(num: int, k: int) -> int:
if num == 0:
return 0
for i in range(1, num + 1):
if (t := num - k * i) >= 0 and t % 10 == 0:
return i
return -1 | function(2668, 10) | -1 | 118 | 142.70419 |
Code:
def function(num: int, k: int) -> int:
if num == 0:
return 0
for i in range(1, num + 1):
if (t := num - k * i) >= 0 and t % 10 == 0:
return i
return -1
Evaluate this code with the following inputs :
function(2668, 10)
Please evaluate the code with the given inputs and pr... |
def function(s: str, k: int) -> int:
ans = v = 0
for c in s[::-1]:
if c == "0":
ans += 1
elif ans < 30 and (v | 1 << ans) <= k:
v |= 1 << ans
ans += 1
return ans | function('0100101011', 834497269) | 10 | 130 | 0.797443 |
Code:
def function(s: str, k: int) -> int:
ans = v = 0
for c in s[::-1]:
if c == "0":
ans += 1
elif ans < 30 and (v | 1 << ans) <= k:
v |= 1 << ans
ans += 1
return ans
Evaluate this code with the following inputs :
function('0100101011', 834497269)
Plea... |
def function(n: int) -> int:
mod = 10**9 + 7
f = [1] * n
g = [1] * n
for i in range(1, n):
f[i] = g[i - 1]
g[i] = (f[i - 1] + g[i - 1]) % mod
v = f[-1] + g[-1]
return v * v % mod | function(3158) | 812112002 | 146 | 431.909465 |
Code:
def function(n: int) -> int:
mod = 10**9 + 7
f = [1] * n
g = [1] * n
for i in range(1, n):
f[i] = g[i - 1]
g[i] = (f[i - 1] + g[i - 1]) % mod
v = f[-1] + g[-1]
return v * v % mod
Evaluate this code with the following inputs :
function(3158)
Please evaluate the code with ... |
def function(jobs: List[int], workers: List[int]) -> int:
jobs.sort()
workers.sort()
return max((a + b - 1) // b for a, b in zip(jobs, workers)) | function([22, 24, 35, 40, 53, 56, 72, 86, 97, 99], [25, 29, 37, 38, 56, 72, 73, 81, 83, 97]) | 2 | 149 | 1.394468 |
Code:
def function(jobs: List[int], workers: List[int]) -> int:
jobs.sort()
workers.sort()
return max((a + b - 1) // b for a, b in zip(jobs, workers))
Evaluate this code with the following inputs :
function([22, 24, 35, 40, 53, 56, 72, 86, 97, 99], [25, 29, 37, 38, 56, 72, 73, 81, 83, 97])
Please evaluat... |
def function(n: int, delay: int, forget: int) -> int:
m = (n << 1) + 10
d = [0] * m
cnt = [0] * m
cnt[1] = 1
for i in range(1, n + 1):
if cnt[i]:
d[i] += cnt[i]
d[i + forget] -= cnt[i]
nxt = i + delay
while nxt < i + forget:
cnt... | function(44, 34, 42) | 8 | 197 | 6.755928 |
Code:
def function(n: int, delay: int, forget: int) -> int:
m = (n << 1) + 10
d = [0] * m
cnt = [0] * m
cnt[1] = 1
for i in range(1, n + 1):
if cnt[i]:
d[i] += cnt[i]
d[i + forget] -= cnt[i]
nxt = i + delay
while nxt < i + forget:
... |
def function(amount: List[int]) -> int:
amount.sort()
if amount[0] + amount[1] <= amount[2]:
return amount[2]
return (sum(amount) + 1) // 2 | function([37, 43, 100]) | 100 | 100 | 0.140511 |
Code:
def function(amount: List[int]) -> int:
amount.sort()
if amount[0] + amount[1] <= amount[2]:
return amount[2]
return (sum(amount) + 1) // 2
Evaluate this code with the following inputs :
function([37, 43, 100])
Please evaluate the code with the given inputs and provide the expected output i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.