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(nums: List[int]) -> int: i = j = 0 for k, v in enumerate(nums): if v < nums[i] or (v == nums[i] and k < i): i = k if v >= nums[j] or (v == nums[j] and k > j): j = k return 0 if i == j else i + len(nums) - 1 - j - (i > j)
function([95, 80, 58, 43, 99, 88, 100, 76, 47, 57])
6
171
0.905375
Code: def function(nums: List[int]) -> int: i = j = 0 for k, v in enumerate(nums): if v < nums[i] or (v == nums[i] and k < i): i = k if v >= nums[j] or (v == nums[j] and k > j): j = k return 0 if i == j else i + len(nums) - 1 - j - (i > j) Evaluate this code with th...
def function(nums: List[int]) -> int: d = defaultdict(int) ans = -1 for v in nums: x, y = 0, v while y: x += y % 10 y //= 10 if x in d: ans = max(ans, d[x] + v) d[x] = max(d[x], v) return ans
function([25, 32, 100, 15, 87, 93, 66, 19, 33, 6])
159
160
4.1343
Code: def function(nums: List[int]) -> int: d = defaultdict(int) ans = -1 for v in nums: x, y = 0, v while y: x += y % 10 y //= 10 if x in d: ans = max(ans, d[x] + v) d[x] = max(d[x], v) return ans Evaluate this code with the followin...
def function(nums: List[int], k: int) -> int: s = set(nums) ans = 0 cnt = Counter() for v in s: cnt[v.bit_count()] += 1 for v in s: t = v.bit_count() for i, x in cnt.items(): if t + i >= k: ans += x return ans
function([39, 88, 13, 44, 42, 93, 62, 3, 25, 7], 3)
100
160
5.698098
Code: def function(nums: List[int], k: int) -> int: s = set(nums) ans = 0 cnt = Counter() for v in s: cnt[v.bit_count()] += 1 for v in s: t = v.bit_count() for i, x in cnt.items(): if t + i >= k: ans += x return ans Evaluate this code with th...
def function(books: List[int]) -> int: nums = [v - i for i, v in enumerate(books)] n = len(nums) left = [-1] * n stk = [] for i, v in enumerate(nums): while stk and nums[stk[-1]] >= v: stk.pop() if stk: left[i] = stk[-1] stk.append(i) ans = 0 d...
function([70, 49, 38, 43, 51, 95, 40, 69, 20, 28])
328
267
5.872731
Code: def function(books: List[int]) -> int: nums = [v - i for i, v in enumerate(books)] n = len(nums) left = [-1] * n stk = [] for i, v in enumerate(nums): while stk and nums[stk[-1]] >= v: stk.pop() if stk: left[i] = stk[-1] stk.append(i) ans = ...
def function(nums: List[int]) -> int: ans = 0 n = len(nums) mx = nums[-1] for i in range(n - 2, -1, -1): if nums[i] <= mx: mx = nums[i] continue k = (nums[i] + mx - 1) // mx ans += k - 1 mx = nums[i] // k return ans
function([48, 54, 45, 7, 70, 29, 37, 33, 100, 77])
28
170
1.020221
Code: def function(nums: List[int]) -> int: ans = 0 n = len(nums) mx = nums[-1] for i in range(n - 2, -1, -1): if nums[i] <= mx: mx = nums[i] continue k = (nums[i] + mx - 1) // mx ans += k - 1 mx = nums[i] // k return ans Evaluate this code w...
def function(nums: List[int], diff: int) -> int: vis = set(nums) return sum(x + diff in vis and x + diff * 2 in vis for x in nums)
function([28, 98, 105, 116, 119, 122, 134, 147, 157, 185], 39)
0
116
1.032078
Code: def function(nums: List[int], diff: int) -> int: vis = set(nums) return sum(x + diff in vis and x + diff * 2 in vis for x in nums) Evaluate this code with the following inputs : function([28, 98, 105, 116, 119, 122, 134, 147, 157, 185], 39) Please evaluate the code with the given inputs and provide the...
def function(s: str) -> int: ans = cnt = 0 for c in s: if c == '0': cnt += 1 elif cnt: ans = max(ans + 1, cnt) return ans
function('0011110101')
7
102
0.992928
Code: def function(s: str) -> int: ans = cnt = 0 for c in s: if c == '0': cnt += 1 elif cnt: ans = max(ans + 1, cnt) return ans Evaluate this code with the following inputs : function('0011110101') Please evaluate the code with the given inputs and provide the expe...
def function(nums: List[int]) -> int: ans = i = 0 while i < len(nums): j = i + 1 while j < len(nums) and nums[j] > nums[j - 1]: j += 1 cnt = j - i ans += (1 + cnt) * cnt // 2 i = j return ans
function([570453, 924067, 434425, 865573, 983328, 135168, 858831, 916460, 518728, 883401])
18
168
0.902005
Code: def function(nums: List[int]) -> int: ans = i = 0 while i < len(nums): j = i + 1 while j < len(nums) and nums[j] > nums[j - 1]: j += 1 cnt = j - i ans += (1 + cnt) * cnt // 2 i = j return ans Evaluate this code with the following inputs : function(...
def function(nums: List[int]) -> int: ans = j = mask = 0 for i, x in enumerate(nums): while mask & x: mask ^= nums[j] j += 1 ans = max(ans, i - j + 1) mask |= x return ans
function([15, 39, 49, 31, 44, 27, 98, 12, 45, 81])
2
140
2.540656
Code: def function(nums: List[int]) -> int: ans = j = mask = 0 for i, x in enumerate(nums): while mask & x: mask ^= nums[j] j += 1 ans = max(ans, i - j + 1) mask |= x return ans Evaluate this code with the following inputs : function([15, 39, 49, 31, 44, 27,...
def function(players: List[int], trainers: List[int]) -> int: players.sort() trainers.sort() ans = j = 0 for p in players: while j < len(trainers) and trainers[j] < p: j += 1 if j < len(trainers): ans += 1 j += 1 return ans
function([1, 14, 21, 22, 26, 31, 39, 50, 65, 84], [10, 11, 33, 35, 53, 61, 63, 64, 77, 84])
9
183
1.112727
Code: def function(players: List[int], trainers: List[int]) -> int: players.sort() trainers.sort() ans = j = 0 for p in players: while j < len(trainers) and trainers[j] < p: j += 1 if j < len(trainers): ans += 1 j += 1 return ans Evaluate this co...
def function(nums: List[int]) -> List[int]: n = len(nums) ans = [1] * n f = [-1] * 32 for i in range(n - 1, -1, -1): t = 1 for j in range(32): if (nums[i] >> j) & 1: f[j] = i elif f[j] != -1: t = max(t, f[j] - i + 1) ans[i] ...
function([258122523, 947559881, 594127553, 530388848, 444595937, 985704451, 543785022, 140429510, 123214629, 450090815])
[7, 6, 5, 4, 5, 5, 4, 3, 2, 1]
212
38.848826
Code: def function(nums: List[int]) -> List[int]: n = len(nums) ans = [1] * n f = [-1] * 32 for i in range(n - 1, -1, -1): t = 1 for j in range(32): if (nums[i] >> j) & 1: f[j] = i elif f[j] != -1: t = max(t, f[j] - i + 1) ...
def function(transactions: List[List[int]]) -> int: s = sum(max(0, a - b) for a, b in transactions) ans = 0 for a, b in transactions: if a > b: ans = max(ans, s + b) else: ans = max(ans, s + a) return ans
function([[35, 26], [78, 56], [58, 35], [95, 52], [100, 92], [16, 50], [44, 59], [38, 68], [34, 98], [99, 24]])
272
179
3.406821
Code: def function(transactions: List[List[int]]) -> int: s = sum(max(0, a - b) for a, b in transactions) ans = 0 for a, b in transactions: if a > b: ans = max(ans, s + b) else: ans = max(ans, s + a) return ans Evaluate this code with the following inputs : func...
def function(names: List[str], heights: List[int]) -> List[str]: idx = list(range(len(heights))) idx.sort(key=lambda i: -heights[i]) return [names[i] for i in idx]
function(['WYXpHcGtvwohXd', 'JythZxUqmOMSTnUnIHV', 'lsrXMiKbyaDXsOjXBj', 'kRakxisxRjJLQCPLG', 'Ia', 'OKnAFGjznzZUZsy', 'trIAXjVkkmb', 'mFBfE', 'mVNivuxbXgKsPBK', 'vQBn'], [82945, 14183, 13415, 63589, 64214, 64066, 75329, 85397, 85021, 85049])
['mFBfE', 'vQBn', 'mVNivuxbXgKsPBK', 'WYXpHcGtvwohXd', 'trIAXjVkkmb', 'Ia', 'OKnAFGjznzZUZsy', 'kRakxisxRjJLQCPLG', 'JythZxUqmOMSTnUnIHV', 'lsrXMiKbyaDXsOjXBj']
234
1.655794
Code: def function(names: List[str], heights: List[int]) -> List[str]: idx = list(range(len(heights))) idx.sort(key=lambda i: -heights[i]) return [names[i] for i in idx] Evaluate this code with the following inputs : function(['WYXpHcGtvwohXd', 'JythZxUqmOMSTnUnIHV', 'lsrXMiKbyaDXsOjXBj', 'kRakxisxRjJLQCP...
def function(nums: List[int]) -> int: mx = max(nums) ans = cnt = 0 for v in nums: if v == mx: cnt += 1 ans = max(ans, cnt) else: cnt = 0 return ans
function([8, 2, 5, 4, 7])
1
119
0.439462
Code: def function(nums: List[int]) -> int: mx = max(nums) ans = cnt = 0 for v in nums: if v == mx: cnt += 1 ans = max(ans, cnt) else: cnt = 0 return ans Evaluate this code with the following inputs : function([8, 2, 5, 4, 7]) Please evaluate the co...
def function(nums: List[int], k: int) -> List[int]: n = len(nums) decr = [1] * (n + 1) incr = [1] * (n + 1) for i in range(2, n - 1): if nums[i - 1] <= nums[i - 2]: decr[i] = decr[i - 1] + 1 for i in range(n - 3, -1, -1): if nums[i + 1] <= nums[i + 2]: incr[i]...
function([969663, 325090, 196421, 222212, 645420, 448733, 281184, 966350, 387507, 502911], 3)
[]
251
1.937521
Code: def function(nums: List[int], k: int) -> List[int]: n = len(nums) decr = [1] * (n + 1) incr = [1] * (n + 1) for i in range(2, n - 1): if nums[i - 1] <= nums[i - 2]: decr[i] = decr[i - 1] + 1 for i in range(n - 3, -1, -1): if nums[i + 1] <= nums[i + 2]: ...
def function(nums: List[int]) -> int: i, j = 0, len(nums) - 1 a, b = nums[i], nums[j] ans = 0 while i < j: if a < b: i += 1 a += nums[i] ans += 1 elif b < a: j -= 1 b += nums[j] ans += 1 else: i, ...
function([927859, 221784, 899960, 836422, 120462, 811947, 278419, 347300, 791746, 316892])
9
210
0.717237
Code: def function(nums: List[int]) -> int: i, j = 0, len(nums) - 1 a, b = nums[i], nums[j] ans = 0 while i < j: if a < b: i += 1 a += nums[i] ans += 1 elif b < a: j -= 1 b += nums[j] ans += 1 else: ...
def function(nums1: List[int], nums2: List[int]) -> int: ans = 0 if len(nums2) & 1: for v in nums1: ans ^= v if len(nums1) & 1: for v in nums2: ans ^= v return ans
function([58, 90, 44, 65, 91, 19, 100, 96, 55, 66], [33, 20, 80, 41, 42, 87, 62, 45, 73, 72])
0
172
0.183387
Code: def function(nums1: List[int], nums2: List[int]) -> int: ans = 0 if len(nums2) & 1: for v in nums1: ans ^= v if len(nums1) & 1: for v in nums2: ans ^= v return ans Evaluate this code with the following inputs : function([58, 90, 44, 65, 91, 19, 100, 96, 55...
def function(s: str) -> str: cnt = Counter(s) ans = [] stk = [] mi = 'a' for c in s: cnt[c] -= 1 while mi < 'z' and cnt[mi] == 0: mi = chr(ord(mi) + 1) stk.append(c) while stk and stk[-1] <= mi: ans.append(stk.pop()) return ''.join(ans)
function('slambmvozis')
abiszovmmls
148
8.960103
Code: def function(s: str) -> str: cnt = Counter(s) ans = [] stk = [] mi = 'a' for c in s: cnt[c] -= 1 while mi < 'z' and cnt[mi] == 0: mi = chr(ord(mi) + 1) stk.append(c) while stk and stk[-1] <= mi: ans.append(stk.pop()) return ''.join(a...
def function(nums: List[int]) -> int: s = set(nums) return max((x for x in s if -x in s), default=-1)
function([-744, 41, -500, -789, 476, -178, -974, -600, 281, -266])
-1
106
1.122831
Code: def function(nums: List[int]) -> int: s = set(nums) return max((x for x in s if -x in s), default=-1) Evaluate this code with the following inputs : function([-744, 41, -500, -789, 476, -178, -974, -600, 281, -266]) Please evaluate the code with the given inputs and provide the expected output in \boxe...
def function(nums: List[int], target: List[int]) -> int: nums.sort(key=lambda x: (x & 1, x)) target.sort(key=lambda x: (x & 1, x)) return sum(abs(a - b) for a, b in zip(nums, target)) // 4
function([48, 52, 54, 60, 70, 86, 61, 67, 69, 77], [22, 28, 68, 74, 9, 23, 29, 67, 85, 97])
67
168
3.142413
Code: def function(nums: List[int], target: List[int]) -> int: nums.sort(key=lambda x: (x & 1, x)) target.sort(key=lambda x: (x & 1, x)) return sum(abs(a - b) for a, b in zip(nums, target)) // 4 Evaluate this code with the following inputs : function([48, 52, 54, 60, 70, 86, 61, 67, 69, 77], [22, 28, 68, ...
def function(nums: List[int], k: int) -> int: cnt = Counter(nums[:k]) s = sum(nums[:k]) ans = s if len(cnt) == k else 0 for i in range(k, len(nums)): cnt[nums[i]] += 1 s += nums[i] cnt[nums[i - k]] -= 1 s -= nums[i - k] if cnt[nums[i - k]] == 0: del cn...
function([88, 82, 10, 64, 30, 46, 51, 22, 15, 25], 10)
433
206
1.570378
Code: def function(nums: List[int], k: int) -> int: cnt = Counter(nums[:k]) s = sum(nums[:k]) ans = s if len(cnt) == k else 0 for i in range(k, len(nums)): cnt[nums[i]] += 1 s += nums[i] cnt[nums[i - k]] -= 1 s -= nums[i - k] if cnt[nums[i - k]] == 0: ...
def function(message: str, limit: int) -> List[str]: n = len(message) sa = 0 for k in range(1, n + 1): sa += len(str(k)) sb = len(str(k)) * k sc = 3 * k if limit * k - (sa + sb + sc) >= n: ans = [] i = 0 for j in range(1, k + 1): ...
function('ygaxdyfevpqwlijabvdegsmojdatdq', 21)
['ygaxdyfevpqwlija<1/2>', 'bvdegsmojdatdq<2/2>']
212
1.414836
Code: def function(message: str, limit: int) -> List[str]: n = len(message) sa = 0 for k in range(1, n + 1): sa += len(str(k)) sb = len(str(k)) * k sc = 3 * k if limit * k - (sa + sb + sc) >= n: ans = [] i = 0 for j in range(1, k + 1): ...
def function(s: str, k: int, minLength: int) -> int: primes = '2357' if s[0] not in primes or s[-1] in primes: return 0 mod = 10**9 + 7 n = len(s) f = [[0] * (k + 1) for _ in range(n + 1)] g = [[0] * (k + 1) for _ in range(n + 1)] f[0][0] = g[0][0] = 1 for i, c in enumerate(s, 1)...
function('6338684824', 4, 10)
0
284
0.103427
Code: def function(s: str, k: int, minLength: int) -> int: primes = '2357' if s[0] not in primes or s[-1] in primes: return 0 mod = 10**9 + 7 n = len(s) f = [[0] * (k + 1) for _ in range(n + 1)] g = [[0] * (k + 1) for _ in range(n + 1)] f[0][0] = g[0][0] = 1 for i, c in enumerat...
def function(s: str) -> int: mod = 10**9 + 7 n = len(s) pre = [[[0] * 10 for _ in range(10)] for _ in range(n + 2)] suf = [[[0] * 10 for _ in range(10)] for _ in range(n + 2)] t = list(map(int, s)) c = [0] * 10 for i, v in enumerate(t, 1): for j in range(10): for k in ran...
function('1326660856')
0
380
285.770983
Code: def function(s: str) -> int: mod = 10**9 + 7 n = len(s) pre = [[[0] * 10 for _ in range(10)] for _ in range(n + 2)] suf = [[[0] * 10 for _ in range(10)] for _ in range(n + 2)] t = list(map(int, s)) c = [0] * 10 for i, v in enumerate(t, 1): for j in range(10): for k...
def function(s: str, t: str) -> int: m, n = len(s), len(t) i = 0 for j in range(n): while i < m and s[i] != t[j]: i += 1 if i == m: return n - j i += 1 return 0
function('bnqbo', 'cljlg')
5
130
0.51333
Code: def function(s: str, t: str) -> int: m, n = len(s), len(t) i = 0 for j in range(n): while i < m and s[i] != t[j]: i += 1 if i == m: return n - j i += 1 return 0 Evaluate this code with the following inputs : function('bnqbo', 'cljlg') Please evalu...
def function(skill: List[int]) -> int: skill.sort() t = skill[0] + skill[-1] i, j = 0, len(skill) - 1 ans = 0 while i < j: if skill[i] + skill[j] != t: return -1 ans += skill[i] * skill[j] i, j = i + 1, j - 1 return ans
function([524, 592, 897])
470028
149
0.290124
Code: def function(skill: List[int]) -> int: skill.sort() t = skill[0] + skill[-1] i, j = 0, len(skill) - 1 ans = 0 while i < j: if skill[i] + skill[j] != t: return -1 ans += skill[i] * skill[j] i, j = i + 1, j - 1 return ans Evaluate this code with the foll...
def function(nums: List[int]) -> int: ans, last = 0, -1 for i, v in enumerate(nums): if v % 2 == 0: last = i ans += last + 1 return ans
function([83, 12, 22, 38, 28, 100, 81, 62, 42, 96])
53
128
0.777536
Code: def function(nums: List[int]) -> int: ans, last = 0, -1 for i, v in enumerate(nums): if v % 2 == 0: last = i ans += last + 1 return ans Evaluate this code with the following inputs : function([83, 12, 22, 38, 28, 100, 81, 62, 42, 96]) Please evaluate the code with the gi...
def function(vals: List[int], edges: List[List[int]], k: int) -> int: g = defaultdict(list) for a, b in edges: if vals[b] > 0: g[a].append(vals[b]) if vals[a] > 0: g[b].append(vals[a]) for bs in g.values(): bs.sort(reverse=True) return max(v + sum(g[i][:k]...
function([3556, 1921, -9678, -3184, 7133, 2331], [[2, 1], [3, 0], [4, 0], [4, 4], [4, 2], [0, 1], [1, 2], [3, 5], [2, 3], [2, 3], [0, 4], [0, 2], [0, 2], [1, 1]], 5)
28511
252
4.800277
Code: def function(vals: List[int], edges: List[List[int]], k: int) -> int: g = defaultdict(list) for a, b in edges: if vals[b] > 0: g[a].append(vals[b]) if vals[a] > 0: g[b].append(vals[a]) for bs in g.values(): bs.sort(reverse=True) return max(v + sum(g...
def function(nums: List[int]) -> int: s = set(nums) ans = -1 for v in nums: t = 0 while v in s: v *= v t += 1 if t > 1: ans = max(ans, t) return ans
function([20, 69, 62, 15, 87, 16, 12, 21, 11, 26])
-1
141
1.049404
Code: def function(nums: List[int]) -> int: s = set(nums) ans = -1 for v in nums: t = 0 while v in s: v *= v t += 1 if t > 1: ans = max(ans, t) return ans Evaluate this code with the following inputs : function([20, 69, 62, 15, 87, 16, 12, 21...
def function(s: str, k: int) -> int: cnt = Counter(s) if any(cnt[c] < k for c in "abc"): return -1 ans = j = 0 for i, c in enumerate(s): cnt[c] -= 1 while cnt[c] < k: cnt[s[j]] += 1 j += 1 ans = max(ans, i - j + 1) return len(s) - ans
function('cccccccccc', 2)
-1
156
1.763675
Code: def function(s: str, k: int) -> int: cnt = Counter(s) if any(cnt[c] < k for c in "abc"): return -1 ans = j = 0 for i, c in enumerate(s): cnt[c] -= 1 while cnt[c] < k: cnt[s[j]] += 1 j += 1 ans = max(ans, i - j + 1) return len(s) - ans E...
def function(nums: List[int], k: int) -> int: if sum(nums) < k * 2: return 0 mod = 10**9 + 7 n = len(nums) f = [[0] * k for _ in range(n + 1)] f[0][0] = 1 ans = 1 for i in range(1, n + 1): ans = ans * 2 % mod for j in range(k): f[i][j] = f[i - 1][j] ...
function([47, 79, 54, 1, 16, 86, 94, 80, 65, 90], 1000)
0
261
0.245807
Code: def function(nums: List[int], k: int) -> int: if sum(nums) < k * 2: return 0 mod = 10**9 + 7 n = len(nums) f = [[0] * k for _ in range(n + 1)] f[0][0] = 1 ans = 1 for i in range(1, n + 1): ans = ans * 2 % mod for j in range(k): f[i][j] = f[i - 1][j]...
def function(nums: List[int], k: int) -> int: cnt = Counter() ans = cur = 0 i = 0 for x in nums: cur += cnt[x] cnt[x] += 1 while cur - cnt[nums[i]] + 1 >= k: cnt[nums[i]] -= 1 cur -= cnt[nums[i]] i += 1 if cur >= k: ans += i...
function([47, 82, 91, 98, 23, 21, 43, 46, 30, 67], 92)
0
184
4.596704
Code: def function(nums: List[int], k: int) -> int: cnt = Counter() ans = cur = 0 i = 0 for x in nums: cur += cnt[x] cnt[x] += 1 while cur - cnt[nums[i]] + 1 >= k: cnt[nums[i]] -= 1 cur -= cnt[nums[i]] i += 1 if cur >= k: a...
def function(nums1: List[int], nums2: List[int]) -> int: i = j = 0 m, n = len(nums1), len(nums2) while i < m and j < n: if nums1[i] == nums2[j]: return nums1[i] if nums1[i] < nums2[j]: i += 1 else: j += 1 return -1
function([18489481, 106966013, 284919207, 340405663, 349902054, 361752456, 417858221, 633120667, 808649969, 928410937], [97474851, 150797442, 227739674, 339752748, 365939169, 603882727, 699337739, 883241758, 912375874, 983594459])
-1
237
1.411527
Code: def function(nums1: List[int], nums2: List[int]) -> int: i = j = 0 m, n = len(nums1), len(nums2) while i < m and j < n: if nums1[i] == nums2[j]: return nums1[i] if nums1[i] < nums2[j]: i += 1 else: j += 1 return -1 Evaluate this code wi...
def function(items: List[List[int]], capacity: int) -> float: ans = 0 for p, w in sorted(items, key=lambda x: x[1] / x[0]): v = min(w, capacity) ans += v / w * p capacity -= v return -1 if capacity else ans
function([[101, 57], [73, 72], [44, 25], [51, 27], [50, 24]], 86)
163.01754385964912
148
1.766251
Code: def function(items: List[List[int]], capacity: int) -> float: ans = 0 for p, w in sorted(items, key=lambda x: x[1] / x[0]): v = min(w, capacity) ans += v / w * p capacity -= v return -1 if capacity else ans Evaluate this code with the following inputs : function([[101, 57], [...
def function(nums: List[int]) -> int: ans = 0 i, j = 0, len(nums) - 1 while i < j: ans += int(str(nums[i]) + str(nums[j])) i, j = i + 1, j - 1 if i == j: ans += nums[i] return ans
function([50, 77, 6, 72, 84, 36, 67, 12, 100, 28])
98443
152
1.533851
Code: def function(nums: List[int]) -> int: ans = 0 i, j = 0, len(nums) - 1 while i < j: ans += int(str(nums[i]) + str(nums[j])) i, j = i + 1, j - 1 if i == j: ans += nums[i] return ans Evaluate this code with the following inputs : function([50, 77, 6, 72, 84, 36, 67, 12, ...
def function(s: str, queries: List[List[int]]) -> List[List[int]]: d = {} n = len(s) for i in range(n): x = 0 for j in range(32): if i + j >= n: break x = x << 1 | int(s[i + j]) if x not in d: d[x] = [i, i + j] i...
function('100111101', [[96, 367], [388, 309], [468, 460], [78, 185], [13, 80], [34, 402], [511, 463], [312, 203], [189, 373], [378, 247]])
[[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]
230
10.448438
Code: def function(s: str, queries: List[List[int]]) -> List[List[int]]: d = {} n = len(s) for i in range(n): x = 0 for j in range(32): if i + j >= n: break x = x << 1 | int(s[i + j]) if x not in d: d[x] = [i, i + j] ...
def function(num: int) -> int: s = str(num) mi = int(s.replace(s[0], '0')) for c in s: if c != '9': return int(s.replace(c, '9')) - mi return num - mi
function(92172134)
97007000
106
0.537535
Code: def function(num: int) -> int: s = str(num) mi = int(s.replace(s[0], '0')) for c in s: if c != '9': return int(s.replace(c, '9')) - mi return num - mi Evaluate this code with the following inputs : function(92172134) Please evaluate the code with the given inputs and provide...
def function(nums: List[int]) -> int: nums.sort() return min(nums[-1] - nums[2], nums[-2] - nums[1], nums[-3] - nums[0])
function([187116484, 195513863, 224763496, 387484944, 427336228, 465507140, 628214485, 635177885, 801864107, 818132423])
448061401
135
0.37955
Code: def function(nums: List[int]) -> int: nums.sort() return min(nums[-1] - nums[2], nums[-2] - nums[1], nums[-3] - nums[0]) Evaluate this code with the following inputs : function([187116484, 195513863, 224763496, 387484944, 427336228, 465507140, 628214485, 635177885, 801864107, 818132423]) Please evaluat...
def function(n: int) -> int: ans = cnt = 0 while n: if n & 1: cnt += 1 elif cnt: ans += 1 cnt = 0 if cnt == 1 else 1 n >>= 1 if cnt == 1: ans += 1 elif cnt > 1: ans += 2 return ans
function(97001)
7
139
1.130228
Code: def function(n: int) -> int: ans = cnt = 0 while n: if n & 1: cnt += 1 elif cnt: ans += 1 cnt = 0 if cnt == 1 else 1 n >>= 1 if cnt == 1: ans += 1 elif cnt > 1: ans += 2 return ans Evaluate this code with the followi...
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([18, 12, 15, 20, 22, 28, 11, 26, 13, 3])
23
309
446.784248
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(nums: List[int]) -> int: nums.sort() n = len(nums) i, j = 0, (n + 1) // 2 ans = 0 while j < n: while j < n and nums[i] * 2 > nums[j]: j += 1 if j < n: ans += 2 i, j = i + 1, j + 1 return ans
function([20, 30, 35, 47, 54, 57, 60, 72, 83, 100])
8
174
0.581143
Code: def function(nums: List[int]) -> int: nums.sort() n = len(nums) i, j = 0, (n + 1) // 2 ans = 0 while j < n: while j < n and nums[i] * 2 > nums[j]: j += 1 if j < n: ans += 2 i, j = i + 1, j + 1 return ans Evaluate this code with the followin...
def function(num: int) -> int: cnt = Counter() n = 0 while num: cnt[num % 10] += 1 num //= 10 n += 1 ans = [0] * 2 j = 0 for i in range(n): while cnt[j] == 0: j += 1 cnt[j] -= 1 ans[i & 1] = ans[i & 1] * 10 + j return sum(ans)
function(588915033)
4947
164
5.981142
Code: def function(num: int) -> int: cnt = Counter() n = 0 while num: cnt[num % 10] += 1 num //= 10 n += 1 ans = [0] * 2 j = 0 for i in range(n): while cnt[j] == 0: j += 1 cnt[j] -= 1 ans[i & 1] = ans[i & 1] * 10 + j return sum(ans...
def function(target: int, types: List[List[int]]) -> int: n = len(types) mod = 10**9 + 7 f = [[0] * (target + 1) for _ in range(n + 1)] f[0][0] = 1 for i in range(1, n + 1): count, marks = types[i - 1] for j in range(target + 1): for k in range(count + 1): ...
function(28, [[1, 3], [1, 2], [4, 4], [3, 5], [3, 5], [4, 1]])
60
233
82.138617
Code: def function(target: int, types: List[List[int]]) -> int: n = len(types) mod = 10**9 + 7 f = [[0] * (target + 1) for _ in range(n + 1)] f[0][0] = 1 for i in range(1, n + 1): count, marks = types[i - 1] for j in range(target + 1): for k in range(count + 1): ...
def function(nums: List[int]) -> int: cnt = Counter({0: 1}) ans = mask = 0 for x in nums: mask ^= x ans += cnt[mask] cnt[mask] += 1 return ans
function([100, 94, 7, 12, 62, 46, 45, 49, 91, 24])
1
128
4.283152
Code: def function(nums: List[int]) -> int: cnt = Counter({0: 1}) ans = mask = 0 for x in nums: mask ^= x ans += cnt[mask] cnt[mask] += 1 return ans Evaluate this code with the following inputs : function([100, 94, 7, 12, 62, 46, 45, 49, 91, 24]) Please evaluate the code with ...
def function(tasks: List[List[int]]) -> int: tasks.sort(key=lambda x: x[1]) vis = [0] * 2010 ans = 0 for start, end, duration in tasks: duration -= sum(vis[start : end + 1]) i = end while i >= start and duration > 0: if not vis[i]: duration -= 1 ...
function([[1, 6, 3], [4, 8, 3], [8, 9, 2], [3, 9, 6], [5, 9, 5], [9, 10, 1], [10, 10, 1], [1, 10, 8], [10, 10, 1], [2, 10, 4]])
8
244
7.483097
Code: def function(tasks: List[List[int]]) -> int: tasks.sort(key=lambda x: x[1]) vis = [0] * 2010 ans = 0 for start, end, duration in tasks: duration -= sum(vis[start : end + 1]) i = end while i >= start and duration > 0: if not vis[i]: duration -= 1...
def function(money: int, children: int) -> int: if money < children: return -1 if money > 8 * children: return children - 1 if money == 8 * children - 4: return children - 2 # money-8x >= children-x, x <= (money-children)/7 return (money - children) // 7
function(137, 15)
14
137
0.076656
Code: def function(money: int, children: int) -> int: if money < children: return -1 if money > 8 * children: return children - 1 if money == 8 * children - 4: return children - 2 # money-8x >= children-x, x <= (money-children)/7 return (money - children) // 7 Evaluate this...
def function(nums: List[int]) -> int: nums.sort() i = 0 for x in nums: i += x > nums[i] return i
function([19, 25, 28, 41, 45, 47, 55, 72, 74, 82])
9
109
0.60373
Code: def function(nums: List[int]) -> int: nums.sort() i = 0 for x in nums: i += x > nums[i] return i Evaluate this code with the following inputs : function([19, 25, 28, 41, 45, 47, 55, 72, 74, 82]) Please evaluate the code with the given inputs and provide the expected output in \boxed{} f...
def function(n: int) -> List[int]: mask = 0x5555 even = (n & mask).bit_count() odd = (n & ~mask).bit_count() return [even, odd]
function(384)
[1, 1]
93
0.154728
Code: def function(n: int) -> List[int]: mask = 0x5555 even = (n & mask).bit_count() odd = (n & ~mask).bit_count() return [even, odd] Evaluate this code with the following inputs : function(384) Please evaluate the code with the given inputs and provide the expected output in \boxed{} format. Do not ...
def function(nums: List[int], value: int) -> int: cnt = Counter(x % value for x in nums) for i in range(len(nums) + 1): if cnt[i % value] == 0: return i cnt[i % value] -= 1
function([-660076092, -909617321, -486756154, 269185544, -300327016, -818756399, -725063860, -277297233, -174368247, 414924382], 56514)
0
158
2.548321
Code: def function(nums: List[int], value: int) -> int: cnt = Counter(x % value for x in nums) for i in range(len(nums) + 1): if cnt[i % value] == 0: return i cnt[i % value] -= 1 Evaluate this code with the following inputs : function([-660076092, -909617321, -486756154, 269185544,...
def function(nums: List[int], k: int) -> int: nums.sort() g = defaultdict(list) for x in nums: g[x % k].append(x) ans = 1 for arr in g.values(): m = len(arr) f = [0] * (m + 1) f[0] = 1 f[1] = 2 for i in range(2, m + 1): if arr[i - 1] - arr[...
function([38, 41, 45, 57, 65, 79, 81, 91, 106, 128, 133, 156, 174, 175, 201, 221, 227, 235, 282, 288, 296, 338, 353, 357, 360, 368, 369, 395, 417, 480, 482, 491, 513, 552, 585, 597, 631, 721, 765, 818, 821, 842, 871, 887, 901, 925, 942, 949, 963, 966, 977], 202)
1688849860263936
363
20.003792
Code: def function(nums: List[int], k: int) -> int: nums.sort() g = defaultdict(list) for x in nums: g[x % k].append(x) ans = 1 for arr in g.values(): m = len(arr) f = [0] * (m + 1) f[0] = 1 f[1] = 2 for i in range(2, m + 1): if arr[i - 1]...
def function(word: str) -> int: s = 'abc' ans, n = 0, len(word) i = j = 0 while j < n: if word[j] != s[i]: ans += 1 else: j += 1 i = (i + 1) % 3 if word[-1] != 'c': ans += 1 if word[-1] == 'b' else 2 return ans
function('abacaaabbcbacaabaaccaacaabbccbcbabbbbacbabbacacbb')
50
172
8.209694
Code: def function(word: str) -> int: s = 'abc' ans, n = 0, len(word) i = j = 0 while j < n: if word[j] != s[i]: ans += 1 else: j += 1 i = (i + 1) % 3 if word[-1] != 'c': ans += 1 if word[-1] == 'b' else 2 return ans Evaluate this code wi...
def function(nums: List[int], k: int) -> int: x = max(nums) return k * x + k * (k - 1) // 2
function([51, 77, 61, 99, 65, 71, 82, 48, 64, 53], 77)
10549
112
0.348918
Code: def function(nums: List[int], k: int) -> int: x = max(nums) return k * x + k * (k - 1) // 2 Evaluate this code with the following inputs : function([51, 77, 61, 99, 65, 71, 82, 48, 64, 53], 77) Please evaluate the code with the given inputs and provide the expected output in \boxed{} format. Do not out...
def function(nums: List[List[int]]) -> int: for row in nums: row.sort() return sum(map(max, zip(*nums)))
function([[16, 953], [228, 255, 510, 760, 812], [35, 95, 519, 641, 664, 758], [430, 456, 642, 756, 908, 958], [420, 488, 680, 791], [230, 274, 411, 466, 476, 515]])
1383
159
1.296758
Code: def function(nums: List[List[int]]) -> int: for row in nums: row.sort() return sum(map(max, zip(*nums))) Evaluate this code with the following inputs : function([[16, 953], [228, 255, 510, 760, 812], [35, 95, 519, 641, 664, 758], [430, 456, 642, 756, 908, 958], [420, 488, 680, 791], [230, 274, 4...
def function(s: str) -> str: cs = list(s) i, j = 0, len(s) - 1 while i < j: cs[i] = cs[j] = min(cs[i], cs[j]) i, j = i + 1, j - 1 return "".join(cs)
function("ciabdfxxqm")
ciabddbaic
121
1.104036
Code: def function(s: str) -> str: cs = list(s) i, j = 0, len(s) - 1 while i < j: cs[i] = cs[j] = min(cs[i], cs[j]) i, j = i + 1, j - 1 return "".join(cs) Evaluate this code with the following inputs : function("ciabdfxxqm") Please evaluate the code with the given inputs and provide t...
def function(nums: List[int]) -> int: nums.sort() n = len(nums) if n == 1: return nums[0] if nums[1] == nums[-1] == 0: return 0 ans, i = 1, 0 while i < n: if nums[i] < 0 and i + 1 < n and nums[i + 1] < 0: ans *= nums[i] * nums[i + 1] i += 2 ...
function([-7, -7, -6, -5, -4, -4, -3, -2, -1, -1, 2, 5, 6])
8467200
229
1.017994
Code: def function(nums: List[int]) -> int: nums.sort() n = len(nums) if n == 1: return nums[0] if nums[1] == nums[-1] == 0: return 0 ans, i = 1, 0 while i < n: if nums[i] < 0 and i + 1 < n and nums[i + 1] < 0: ans *= nums[i] * nums[i + 1] i += 2 ...
def function(s: str) -> int: ans, n = 0, len(s) for i in range(1, n): if s[i] != s[i - 1]: ans += min(i, n - i) return ans
function('1100100011')
13
103
1.108118
Code: def function(s: str) -> int: ans, n = 0, len(s) for i in range(1, n): if s[i] != s[i - 1]: ans += min(i, n - i) return ans Evaluate this code with the following inputs : function('1100100011') Please evaluate the code with the given inputs and provide the expected output in \box...
def function(mat: List[List[int]]) -> int: m, n = len(mat), len(mat[0]) g = defaultdict(list) for i in range(m): for j in range(n): g[mat[i][j]].append((i, j)) rowMax = [0] * m colMax = [0] * n ans = 0 for _, pos in sorted(g.items()): mx = [] for i, j in p...
function([[-21627, -41704, 26994, 27862, -43141], [62158, -12343, -39761, 49011, -77013], [-32964, 12471, -74384, 54920, 36309], [-82843, -9531, -73190, -83901, 1084], [-43425, -17887, 94765, 49017, 28806]])
10
317
25.831649
Code: def function(mat: List[List[int]]) -> int: m, n = len(mat), len(mat[0]) g = defaultdict(list) for i in range(m): for j in range(n): g[mat[i][j]].append((i, j)) rowMax = [0] * m colMax = [0] * n ans = 0 for _, pos in sorted(g.items()): mx = [] for i,...
def function(s: str) -> int: n = len(s) ans = cnt = j = 0 for i in range(n): if i and s[i] == s[i - 1]: cnt += 1 while cnt > 1: if s[j] == s[j + 1]: cnt -= 1 j += 1 ans = max(ans, i - j + 1) return ans
function("45181332491433195230507887626449090663927419830398")
20
160
12.996911
Code: def function(s: str) -> int: n = len(s) ans = cnt = j = 0 for i in range(n): if i and s[i] == s[i - 1]: cnt += 1 while cnt > 1: if s[j] == s[j + 1]: cnt -= 1 j += 1 ans = max(ans, i - j + 1) return ans Evaluate this code...
def function(s: str) -> str: n = len(s) i = 0 while i < n and s[i] == "a": i += 1 if i == n: return s[:-1] + "z" j = i while j < n and s[j] != "a": j += 1 return s[:i] + "".join(chr(ord(c) - 1) for c in s[i:j]) + s[j:]
function('etkfgbcned')
dsjefabmdc
156
3.362589
Code: def function(s: str) -> str: n = len(s) i = 0 while i < n and s[i] == "a": i += 1 if i == n: return s[:-1] + "z" j = i while j < n and s[j] != "a": j += 1 return s[:i] + "".join(chr(ord(c) - 1) for c in s[i:j]) + s[j:] Evaluate this code with the following inp...
def function(x: int, y: int, z: int) -> int: if x < y: return (x * 2 + z + 1) * 2 if x > y: return (y * 2 + z + 1) * 2 return (x + y + z) * 2
function(39, 27, 11)
132
126
0.163265
Code: def function(x: int, y: int, z: int) -> int: if x < y: return (x * 2 + z + 1) * 2 if x > y: return (y * 2 + z + 1) * 2 return (x + y + z) * 2 Evaluate this code with the following inputs : function(39, 27, 11) Please evaluate the code with the given inputs and provide the expected o...
def function(nums: List[int]) -> int: mod = 10**9 + 7 ans, j = 1, -1 for i, x in enumerate(nums): if x == 0: continue if j > -1: ans = ans * (i - j) % mod j = i return 0 if j == -1 else ans
function([0, 0, 1, 1, 1, 1, 1, 1, 1, 1])
1
159
0.774104
Code: def function(nums: List[int]) -> int: mod = 10**9 + 7 ans, j = 1, -1 for i, x in enumerate(nums): if x == 0: continue if j > -1: ans = ans * (i - j) % mod j = i return 0 if j == -1 else ans Evaluate this code with the following inputs : function([0...
def function(nums: List[int], threshold: int) -> int: ans, l, n = 0, 0, len(nums) while l < n: if nums[l] % 2 == 0 and nums[l] <= threshold: r = l + 1 while r < n and nums[r] % 2 != nums[r - 1] % 2 and nums[r] <= threshold: r += 1 ans = max(ans, r - l)...
function([52, 66, 54, 61, 92, 22, 49, 29, 91, 63], 85)
2
199
1.443476
Code: def function(nums: List[int], threshold: int) -> int: ans, l, n = 0, 0, len(nums) while l < n: if nums[l] % 2 == 0 and nums[l] <= threshold: r = l + 1 while r < n and nums[r] % 2 != nums[r - 1] % 2 and nums[r] <= threshold: r += 1 ans = max(ans,...
def function(nums: List[int], k: int) -> int: m = max(nums) + k * 2 + 2 d = [0] * m for x in nums: d[x] += 1 d[x + k * 2 + 1] -= 1 ans = s = 0 for x in d: s += x ans = max(ans, s) return ans
function([18, 62, 82, 94, 52, 41, 29, 66, 10, 51], 175)
10
173
51.674619
Code: def function(nums: List[int], k: int) -> int: m = max(nums) + k * 2 + 2 d = [0] * m for x in nums: d[x] += 1 d[x + k * 2 + 1] -= 1 ans = s = 0 for x in d: s += x ans = max(ans, s) return ans Evaluate this code with the following inputs : function([18, 62, ...
def function(s: str) -> str: vs = [c for c in s if c.lower() in "aeiou"] vs.sort() cs = list(s) j = 0 for i, c in enumerate(cs): if c.lower() in "aeiou": cs[i] = vs[j] j += 1 return "".join(cs)
function('sdPByBxQaY')
sdPByBxQaY
133
1.719969
Code: def function(s: str) -> str: vs = [c for c in s if c.lower() in "aeiou"] vs.sort() cs = list(s) j = 0 for i, c in enumerate(cs): if c.lower() in "aeiou": cs[i] = vs[j] j += 1 return "".join(cs) Evaluate this code with the following inputs : function('sdPBy...
def function(nums: List[int]) -> int: for i in range(len(nums) - 2, -1, -1): if nums[i] <= nums[i + 1]: nums[i] += nums[i + 1] return max(nums)
function([6120933, 5466181, 4825073, 4574942, 3882264, 3115591, 2642157, 2010345, 1036806, 877364])
6120933
146
0.727249
Code: def function(nums: List[int]) -> int: for i in range(len(nums) - 2, -1, -1): if nums[i] <= nums[i + 1]: nums[i] += nums[i + 1] return max(nums) Evaluate this code with the following inputs : function([6120933, 5466181, 4825073, 4574942, 3882264, 3115591, 2642157, 2010345, 1036806, 87...
def function(usageLimits: List[int]) -> int: usageLimits.sort() k = s = 0 for x in usageLimits: s += x if s > k: k += 1 s -= k return k
function([13, 31, 31, 52, 58, 69, 71, 97, 99, 101])
10
129
0.696291
Code: def function(usageLimits: List[int]) -> int: usageLimits.sort() k = s = 0 for x in usageLimits: s += x if s > k: k += 1 s -= k return k Evaluate this code with the following inputs : function([13, 31, 31, 52, 58, 69, 71, 97, 99, 101]) Please evaluate the ...
def function(nums1: List[int], nums2: List[int], x: int) -> int: n = len(nums1) f = [0] * (n + 1) for a, b in sorted(zip(nums1, nums2), key=lambda z: z[1]): for j in range(n, 0, -1): f[j] = max(f[j], f[j - 1] + a + b * j) s1 = sum(nums1) s2 = sum(nums2) for j in range(n + 1):...
function([953, 660, 649, 525, 902, 728, 744, 942, 694, 380], [977, 992, 510, 246, 837, 261, 931, 886, 943, 255], 264344)
0
254
20.875985
Code: def function(nums1: List[int], nums2: List[int], x: int) -> int: n = len(nums1) f = [0] * (n + 1) for a, b in sorted(zip(nums1, nums2), key=lambda z: z[1]): for j in range(n, 0, -1): f[j] = max(f[j], f[j - 1] + a + b * j) s1 = sum(nums1) s2 = sum(nums2) for j in range(...
def function(items: List[List[int]], k: int) -> int: items.sort(key=lambda x: -x[0]) tot = 0 vis = set() dup = [] for p, c in items[:k]: tot += p if c not in vis: vis.add(c) else: dup.append(p) ans = tot + len(vis) ** 2 for p, c in items[k:]: ...
function([[917892295, 87], [892809679, 35], [669051024, 92], [630188526, 50], [621954927, 95], [550326664, 100], [513949889, 100], [462292658, 25], [234371323, 43], [227554478, 26]], 8)
5258465711
266
2.492806
Code: def function(items: List[List[int]], k: int) -> int: items.sort(key=lambda x: -x[0]) tot = 0 vis = set() dup = [] for p, c in items[:k]: tot += p if c not in vis: vis.add(c) else: dup.append(p) ans = tot + len(vis) ** 2 for p, c in items...
def function(nums: List[int]) -> int: f = [0] * 3 for x in nums: g = [0] * 3 if x == 1: g[0] = f[0] g[1] = min(f[:2]) + 1 g[2] = min(f) + 1 elif x == 2: g[0] = f[0] + 1 g[1] = min(f[:2]) g[2] = min(f) + 1 els...
function([2, 2, 3, 3, 3, 2, 1, 1, 3, 3, 1, 1, 3, 2, 1, 1, 2, 3, 3, 1, 1, 2, 3, 1, 2, 1, 2, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 1, 2, 3, 1, 1, 2, 1, 3, 2, 3, 1, 1, 2, 3, 2, 3, 3, 1, 2, 2, 2, 3, 1, 1, 3, 1, 2, 2, 2, 1, 2, 2, 3, 1, 1, 2, 3, 3, 1, 1, 3, 3, 1, 1, 1, 1, 2, 3, 2, 2, 2, 1, 2, 2, 3, 2, 3])
56
515
43.576445
Code: def function(nums: List[int]) -> int: f = [0] * 3 for x in nums: g = [0] * 3 if x == 1: g[0] = f[0] g[1] = min(f[:2]) + 1 g[2] = min(f) + 1 elif x == 2: g[0] = f[0] + 1 g[1] = min(f[:2]) g[2] = min(f) + 1 ...
def function(n: int, k: int) -> int: s, i = 0, 1 vis = set() for _ in range(n): while i in vis: i += 1 vis.add(i) vis.add(k - i) s += i return s
function(22, 28)
357
116
3.022659
Code: def function(n: int, k: int) -> int: s, i = 0, 1 vis = set() for _ in range(n): while i in vis: i += 1 vis.add(i) vis.add(k - i) s += i return s Evaluate this code with the following inputs : function(22, 28) Please evaluate the code with the given in...
def function(nums: List[int], k: int) -> int: cnt = Counter() l = 0 mx = 0 for r, x in enumerate(nums): cnt[x] += 1 mx = max(mx, cnt[x]) if r - l + 1 - mx > k: cnt[nums[l]] -= 1 l += 1 return mx
function([5, 5, 2, 2, 4, 2, 5, 5, 2, 4], 10)
4
164
4.102281
Code: def function(nums: List[int], k: int) -> int: cnt = Counter() l = 0 mx = 0 for r, x in enumerate(nums): cnt[x] += 1 mx = max(mx, cnt[x]) if r - l + 1 - mx > k: cnt[nums[l]] -= 1 l += 1 return mx Evaluate this code with the following inputs : fu...
def function(nums: List[int], target: int) -> int: s = sum(nums) if s < target: return -1 cnt = [0] * 32 for x in nums: for i in range(32): if x >> i & 1: cnt[i] += 1 i = j = 0 ans = 0 while 1: while i < 32 and (target >> i & 1) == 0: ...
function([2], 4)
-1
261
0.141803
Code: def function(nums: List[int], target: int) -> int: s = sum(nums) if s < target: return -1 cnt = [0] * 32 for x in nums: for i in range(32): if x >> i & 1: cnt[i] += 1 i = j = 0 ans = 0 while 1: while i < 32 and (target >> i & 1) == 0...
def function(n: int) -> str: cnt = [0] * 10 for i in range(9, 1, -1): while n % i == 0: n //= i cnt[i] += 1 if n > 1: return "-1" ans = "".join(str(i) * cnt[i] for i in range(2, 10)) return ans if ans else "1"
function(519237592248596118)
-1
147
0.779626
Code: def function(n: int) -> str: cnt = [0] * 10 for i in range(9, 1, -1): while n % i == 0: n //= i cnt[i] += 1 if n > 1: return "-1" ans = "".join(str(i) * cnt[i] for i in range(2, 10)) return ans if ans else "1" Evaluate this code with the following inpu...
def function(coordinates: List[List[int]], k: int) -> int: cnt = Counter() ans = 0 for x2, y2 in coordinates: for a in range(k + 1): b = k - a x1, y1 = a ^ x2, b ^ y2 ans += cnt[(x1, y1)] cnt[(x2, y2)] += 1 return ans
function([[556797, 426461], [469639, 854424], [937442, 609139], [774729, 656956], [788807, 553667], [992594, 858147], [838923, 510627], [401798, 269207], [518805, 425604], [150519, 227965]], 86)
0
222
178.479467
Code: def function(coordinates: List[List[int]], k: int) -> int: cnt = Counter() ans = 0 for x2, y2 in coordinates: for a in range(k + 1): b = k - a x1, y1 = a ^ x2, b ^ y2 ans += cnt[(x1, y1)] cnt[(x2, y2)] += 1 return ans Evaluate this code with th...
def function(nums: List[int], k: int) -> int: return sum(x for i, x in enumerate(nums) if i.bit_count() == k)
function([17, 42, 92, 39, 19, 58, 28, 18, 14, 85],4)
0
107
0.827162
Code: def function(nums: List[int], k: int) -> int: return sum(x for i, x in enumerate(nums) if i.bit_count() == k) Evaluate this code with the following inputs : function([17, 42, 92, 39, 19, 58, 28, 18, 14, 85],4) Please evaluate the code with the given inputs and provide the expected output in \boxed{} format...
def function(nums: List[int]) -> int: nums.sort() n = len(nums) ans = 0 for i in range(n + 1): if i and nums[i - 1] >= i: continue if i < n and nums[i] <= i: continue return ans
function([12, 15, 28, 29, 32, 49, 51, 54, 56, 66, 82])
0
145
0.709603
Code: def function(nums: List[int]) -> int: nums.sort() n = len(nums) ans = 0 for i in range(n + 1): if i and nums[i - 1] >= i: continue if i < n and nums[i] <= i: continue return ans Evaluate this code with the following inputs : function([12, 15, 28, 29, 3...
def function(nums: List[int]) -> int: score, ans = -1, 1 for num in nums: score &= num if score == 0: score = -1 ans += 1 return 1 if ans == 1 else ans - 1
function([478601, 453806, 523198, 852511, 423936, 919163, 703855, 785978, 349360, 829691])
1
147
0.53362
Code: def function(nums: List[int]) -> int: score, ans = -1, 1 for num in nums: score &= num if score == 0: score = -1 ans += 1 return 1 if ans == 1 else ans - 1 Evaluate this code with the following inputs : function([478601, 453806, 523198, 852511, 423936, 919163,...
def function(nums: List[int], k: int) -> int: ans, y = 1, nums[0] for x in nums[1:]: if x == 0: return 1 if x * y <= k: y *= x else: y = x ans += 1 return ans
function([544943492, 791459944, 436730083, 422035570, 499791671, 998971109, 612426437, 284840667, 369122929, 164726576], 421824841)
10
173
0.719915
Code: def function(nums: List[int], k: int) -> int: ans, y = 1, nums[0] for x in nums[1:]: if x == 0: return 1 if x * y <= k: y *= x else: y = x ans += 1 return ans Evaluate this code with the following inputs : function([544943492, 7...
def function(s: str) -> int: n = len(s) ans = cnt = 0 for i in range(n - 1, -1, -1): if s[i] == '1': cnt += 1 ans += n - i - cnt return ans
function("0101100100")
15
114
0.634405
Code: def function(s: str) -> int: n = len(s) ans = cnt = 0 for i in range(n - 1, -1, -1): if s[i] == '1': cnt += 1 ans += n - i - cnt return ans Evaluate this code with the following inputs : function("0101100100") Please evaluate the code with the given inputs and pr...
def function(a: int, b: int, n: int) -> int: mod = 10**9 + 7 ax, bx = (a >> n) << n, (b >> n) << n for i in range(n - 1, -1, -1): x = a >> i & 1 y = b >> i & 1 if x == y: ax |= 1 << i bx |= 1 << i elif ax > bx: bx |= 1 << i else: ...
function(1044804860709206, 1029760728921526, 12)
13904422
200
3.248019
Code: def function(a: int, b: int, n: int) -> int: mod = 10**9 + 7 ax, bx = (a >> n) << n, (b >> n) << n for i in range(n - 1, -1, -1): x = a >> i & 1 y = b >> i & 1 if x == y: ax |= 1 << i bx |= 1 << i elif ax > bx: bx |= 1 << i e...
def function(nums: List[int], limit: int) -> List[int]: n = len(nums) arr = sorted(zip(nums, range(n))) ans = [0] * n i = 0 while i < n: j = i + 1 while j < n and arr[j][0] - arr[j - 1][0] <= limit: j += 1 idx = sorted(k for _, k in arr[i:j]) for k, (x, _)...
function([37, 56, 39, 76, 83, 100, 59, 77, 33, 26], 14)
[26, 56, 33, 76, 77, 100, 59, 83, 37, 39]
208
4.872206
Code: def function(nums: List[int], limit: int) -> List[int]: n = len(nums) arr = sorted(zip(nums, range(n))) ans = [0] * n i = 0 while i < n: j = i + 1 while j < n and arr[j][0] - arr[j - 1][0] <= limit: j += 1 idx = sorted(k for _, k in arr[i:j]) for k,...
def function(coins: List[int], target: int) -> int: coins.sort() s = 1 ans = i = 0 while s <= target: if i < len(coins) and coins[i] <= s: s += coins[i] i += 1 else: s <<= 1 ans += 1 return ans
function([10, 19, 27, 37, 38, 68, 71, 72, 74, 100], 6041)
8
160
1.422922
Code: def function(coins: List[int], target: int) -> int: coins.sort() s = 1 ans = i = 0 while s <= target: if i < len(coins) and coins[i] <= s: s += coins[i] i += 1 else: s <<= 1 ans += 1 return ans Evaluate this code with the follow...
def function(word: str) -> int: ans = 0 i, n = 1, len(word) while i < n: if abs(ord(word[i]) - ord(word[i - 1])) < 2: ans += 1 i += 2 else: i += 1 return ans
function('tszvbbuscawvlruklykgoemrkdasakzvmcsayjmzpgthyqofafmdxsxltkdabktadhjfvlcsaifnicqkhicavqffndquafmbdedsa')
8
171
11.057307
Code: def function(word: str) -> int: ans = 0 i, n = 1, len(word) while i < n: if abs(ord(word[i]) - ord(word[i - 1])) < 2: ans += 1 i += 2 else: i += 1 return ans Evaluate this code with the following inputs : function('tszvbbuscawvlruklykgoemrkdasa...
def function(nums: List[int], k: int) -> int: cnt = defaultdict(int) ans = j = 0 for i, x in enumerate(nums): cnt[x] += 1 while cnt[x] > k: cnt[nums[j]] -= 1 j += 1 ans = max(ans, i - j + 1) return ans
function([81, 76, 69, 21, 97, 50, 75, 92, 51, 17], 3)
10
160
3.337578
Code: def function(nums: List[int], k: int) -> int: cnt = defaultdict(int) ans = j = 0 for i, x in enumerate(nums): cnt[x] += 1 while cnt[x] > k: cnt[nums[j]] -= 1 j += 1 ans = max(ans, i - j + 1) return ans Evaluate this code with the following inputs :...
def function(nums: List[int], k: int) -> int: mx = max(nums) n = len(nums) ans = cnt = j = 0 for x in nums: while j < n and cnt < k: cnt += nums[j] == mx j += 1 if cnt < k: break ans += n - j + 1 cnt -= x == mx return ans
function([15, 12, 11, 59, 51, 49, 21, 73, 44, 97], 10)
0
171
0.965512
Code: def function(nums: List[int], k: int) -> int: mx = max(nums) n = len(nums) ans = cnt = j = 0 for x in nums: while j < n and cnt < k: cnt += nums[j] == mx j += 1 if cnt < k: break ans += n - j + 1 cnt -= x == mx return ans Ev...