|
Download tasks/program-execution-tracing/contexts/sample-00047.md from StringNLP/longharness: direct link, hf CLI and curl.
- Browser
- Download file 383 kB
-
https://huggingface.co/datasets/StringNLP/longharness/resolve/main/tasks/program-execution-tracing/contexts/sample-00047.md
- Command line
-
hf download hf://datasets/StringNLP/longharness/tasks/program-execution-tracing/contexts/sample-00047.md
-
curl -L -o sample-00047.md https://huggingface.co/datasets/StringNLP/longharness/resolve/main/tasks/program-execution-tracing/contexts/sample-00047.md
383 kB
001
def f1(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
startdegree = dict(indegree)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes) and len(finished) < 20:
available = sorted((node for node in nodes if indegree[node] == 0 and node not in finished))
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f1(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
002
def f2(left, right, excluded):
left = list(left)
def tidy(value):
return ' '.join(str(value).split()).upper()
excluded = {str(value).upper() for value in excluded}
a = {tidy(value) for value in left} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f2(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
003
def f3(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes) and len(finished) < 20:
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f3(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
004
def f4(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
combined = []
for key, count in left:
if key in prices and count > 0:
combined.append((key, count * prices[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f4([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
005
def f5(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
needs[b] += 1
initial = dict(needs)
handled = set()
listing = []
layers = []
while len(handled) < len(nodes):
available = sorted((node for node in nodes if needs[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
layers.append(current)
for node in current:
handled.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f5(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
006
def f6(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f6(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
007
def f7(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
needs[b] += 1
startdegree = dict(needs)
complete = set()
sequence = []
layers = []
while len(complete) < len(nodes):
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f7(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
008
def f8(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f8([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
009
def f9(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left[:20]:
if key in prices and count > 0:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f9([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
010
def f10(rows, keep, prices):
rows = list(rows)
selected = []
buckets = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep and value != 0:
charge = value * prices[group]
selected.append((code, charge))
buckets[group] = buckets.get(group, 0) + charge
sumvalue += charge
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': buckets, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f10([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
011
def f11(rows, keep, prices):
rows = list(rows)
kept = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * abs(prices[group])
kept.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
amount += cost
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': amount, 'groups': buckets, 'top': [code for code, cost in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f11([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
012
def f12(left, right, excluded):
left = list(left)
def normalize(value):
return ' '.join(str(value).split()).upper()
excluded = {normalize(value) for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f12(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
013
def f13(board):
board = list(board)
known = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in known:
continue
cells = []
work = [(row, col)]
known.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f13(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
014
def f14(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices and rate0 != 0:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f14([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
015
def f15(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
items = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in wordmap.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f15(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
016
def f16(rows, keep, prices):
rows = list(rows)
selected = []
groupmap = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
cost = value * prices[group]
selected.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': groupmap, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f16([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
017
def f17(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip().upper()[:12]
ignored = {str(value).upper() for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right if normalize(value) != ''} - ignored
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f17(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
018
def f18(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f18(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
019
def f19(board):
board = list(board)
found = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f19(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
020
def f20(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value != 0:
charge = value * abs(ratemap[group])
selected.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f20([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
021
def f21(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f21([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
022
def f22(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f22(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
023
def f23(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap:
segments.append([left, right])
else:
segments[-1][1] = right
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f23([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
024
def f24(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' \r').upper()
ignored = {normalize(value) for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right if normalize(value) != ''} - ignored
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f24(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
025
def f25(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(series) if value >= limit]
growth = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f25([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
026
def f26(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(min(64, len(values) - size + 1)):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f26([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
027
def f27(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
complete = set()
sequence = []
layers = []
while len(complete) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in routes[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f27(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
028
def f28(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
handled = set()
sequence = []
layers = []
while len(handled) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f28(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
029
def f29(rows, keep, prices):
rows = list(rows)
selected = []
groupmap = {}
grand = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * prices[group]
selected.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
grand += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': grand, 'groups': groupmap, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f29([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
030
def f30(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
ups = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f30([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
031
def f31(rows, keep, factors):
rows = list(rows)
kept = []
groupmap = {}
grand = 0
for code, group, state, value in rows:
if state in keep:
charge = value * factors[group]
kept.append((code, charge))
groupmap[group] = groupmap.get(group, 0) + charge
grand += charge
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': grand, 'groups': groupmap, 'top': [code for code, charge in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f31([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
032
def f32(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(totals) if value > limit]
increases = sum((1 for pos in range(1, len(totals)) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f32([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
033
def f33(board):
board = list(board)
found = set()
regions = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
pending = [(row, col)]
found.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
pending.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f33(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
034
def f34(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
indegree[b] += 1
initial = dict(indegree)
complete = set()
listing = []
layers = []
while len(complete) < len(nodes):
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
layers.append(current)
for node in current:
complete.add(node)
listing.append(node)
for node in current:
for nxt in routes[node]:
indegree[nxt] -= 1
returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f34(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
035
def f35(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
startdegree = dict(indegree)
handled = set()
sequence = []
layers = []
while len(handled) < len(nodes) and len(handled) < 20:
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in handled), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f35(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
036
def f36(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not result or left > result[-1][1] + gap % 5:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
gaps = []
for pos in range(1, len(result)):
left = result[pos][0]
gaps.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f36([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
037
def f37(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len({key for key, value in items})}
output = dict()
output.update(returnvalue)
return output
f37([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
038
def f38(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left >= combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(min(100, left - combined[pos - 1][1]))
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f38([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
039
def f39(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
finished = set()
listing = []
rounds = []
while len(finished) < len(nodes) and len(finished) < 20:
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
rounds.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f39(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
040
def f40(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = right
breaks = []
for pos in range(1, len(combined)):
left = combined[pos][0]
breaks.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f40([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
041
def f41(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(min(64, len(values) - size + 1)):
totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f41([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
042
def f42(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f42(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
043
def f43(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
sequence = []
groups = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
groups.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f43(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
044
def f44(left, right, excluded):
left = list(left)
def tidy(value):
return str(value).strip(' \r').upper()
excluded = {str(value).upper() for value in excluded}
a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f44(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
045
def f45(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left >= combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f45([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
046
def f46(left, right, ignored):
left = list(left)
def canon(value):
return str(value).strip(' \r').upper()
ignored = {str(value).strip() for value in ignored}
a = {canon(value) for value in left} - ignored
b = {canon(value) for value in right} - ignored
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f46(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
047
def f47(lines, stop):
lines = list(lines)
tallies = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in tallies.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f47(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
048
def f48(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
positions = [pos for pos, value in enumerate(windows) if value >= limit]
growth = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': positions, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f48([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
049
def f49(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
output = dict()
output.update(returnvalue)
return output
f49(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
050
def f50(left, right, banned):
left = list(left)
def tidy(value):
return str(value).strip().upper()
banned = {tidy(value) for value in banned}
a = {tidy(value) for value in left} - banned
b = {tidy(value) for value in right} - banned
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f50(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
051
def f51(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop or len(word) > 12:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f51(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
052
def f52(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f52(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
053
def f53(board):
board = list(board)
found = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
work = [(row, col)]
found.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
work.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f53(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
054
def f54(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f54(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
055
def f55(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
items = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in wordmap.items())))}
output = dict()
output.update(returnvalue)
return output
f55(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
056
def f56(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f56([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
057
def f57(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len({key for key, value in items})}
output = dict()
output.update(returnvalue)
return output
f57([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
058
def f58(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors:
factors[name0] = rate0
matched = []
for key, count in left:
if key in factors:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f58([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
059
def f59(left, right, ignored):
left = list(left)
def tidy(value):
return str(value).strip().upper()
ignored = {str(value).upper() for value in ignored}
a = {tidy(value) for value in left} - ignored
b = {tidy(value) for value in right} - ignored
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f59(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
060
def f60(rows, keep, prices):
rows = list(rows)
selected = []
buckets = {}
amount = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if state in keep and value >= 0:
score = value * prices[group]
selected.append((code, score))
buckets[group] = buckets.get(group, 0) + score
amount += score
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, score in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f60([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
061
def f61(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit and (limit >= 0 or pos > 0)]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f61([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
062
def f62(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted((pair for pair in spans if pair[0] <= pair[1])):
if not segments or left > segments[-1][1] + min(gap, 2):
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': min(100, max((right - left for left, right in segments)))}
output = dict()
output.update(returnvalue)
return output
f62([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
063
def f63(left, right, banned):
left = list(left)
def canon(value):
return str(value).strip(' \n').upper()
banned = {str(value).strip() for value in banned}
a = {canon(value) for value in left if canon(value) != canon(value) or canon(value) != ''} - banned
b = {canon(value) for value in right} - banned
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f63(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
064
def f64(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
listing = []
groups = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
groups.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f64(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
065
def f65(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
positions = [pos for pos, value in enumerate(windows) if value >= limit]
growth = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': positions, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f65([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
066
def f66(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = right
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f66([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
067
def f67(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f67(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
068
def f68(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f68(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
069
def f69(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
increases = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f69([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
070
def f70(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, min(50, len(combined))):
left = combined[pos][0]
gaps.append(min(100, left - combined[pos - 1][1]))
returnvalue = {'segments': combined, 'cover': sum((min(100, right - left) for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f70([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
071
def f71(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
finished = set()
sequence = []
groups = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
groups.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f71(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
072
def f72(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
grand = 0
for code, group, state, value in rows:
if state in keep:
score = value * ratemap[group]
selected.append((code, score))
totals[group] = totals.get(group, 0) + score
grand += score
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': grand, 'groups': totals, 'top': [code for code, score in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f72([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
073
def f73(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip().upper()
excluded = {str(value).upper() for value in excluded}
a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f73(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
074
def f74(board):
board = list(board)
found = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
work = [(row, col)]
found.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
work.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f74(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
075
def f75(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f75([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
076
def f76(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f76(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
077
def f77(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep:
cost = value * ratemap[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': sumvalue, 'groups': totals, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f77([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
078
def f78(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
handled = set()
sequence = []
layers = []
while len(handled) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
if not available:
break
current = available
layers.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f78(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
079
def f79(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z' or (char == "'" and word):
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in wordmap.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in wordmap.items())))}
output = dict()
output.update(returnvalue)
return output
f79(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
080
def f80(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(set(spans)):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = right
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f80([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
081
def f81(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(min(64, len(values) - size + 1)):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f81([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
082
def f82(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
routes[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
finished = set()
listing = []
rounds = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
rounds.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in routes[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': rounds, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f82(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
083
def f83(board):
board = list(board)
found = set()
components = []
for row in range(len(board)):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
pending = [(row, col)]
found.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f83(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
084
def f84(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip().upper()
ignored = {str(value).upper() for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f84(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
085
def f85(left, right, excluded):
left = list(left)
def canon(value):
return ' '.join(str(value).split()).upper()
excluded = {str(value).strip() for value in excluded}
a = {canon(value) for value in left if canon(value) != canon(value) or canon(value) != ''} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f85(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
086
def f86(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop or len(word) < 2:
continue
frequency[word] = min(9, frequency.get(word, 0) + 1)
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
output = dict()
output.update(returnvalue)
return output
f86(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
087
def f87(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(totals[:64]) if value > limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': positions, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f87([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
088
def f88(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f88(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
089
def f89(board):
board = list(board)
found = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in found:
continue
cells = []
pending = [(row, col)]
found.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
pending.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f89(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
090
def f90(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f90([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
091
def f91(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
complete = set()
sequence = []
rounds = []
while len(complete) < len(nodes) and len(complete) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f91(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
092
def f92(rows, keep, prices):
rows = list(rows)
selected = []
groupmap = {}
grand = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
charge = value * prices[group]
selected.append((code, charge))
groupmap[group] = groupmap.get(group, 0) + charge
grand += charge
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': grand, 'groups': groupmap, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f92([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
093
def f93(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f93([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
094
def f94(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f94([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
095
def f95(left, right, excluded):
left = list(left)
def canon(value):
return str(value).strip(' \n').upper()
excluded = {str(value).upper() for value in excluded}
a = {canon(value) for value in left} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f95(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
096
def f96(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': unmatched, 'count': len({key for key, value in items})}
output = dict()
output.update(returnvalue)
return output
f96([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
097
def f97(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
sorteditems = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in wordmap.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in sorteditems[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f97(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
098
def f98(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals[:64]) if value >= limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f98([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
099
def f99(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices and count > 0:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f99([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
100
def f100(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left[:20]:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f100([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
101
def f101(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = right
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f101([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
102
def f102(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
grand = 0
for code, group, state, value in rows:
if state in keep:
score = value * ratemap[group]
selected.append((code, score))
totals[group] = totals.get(group, 0) + score
grand += score
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': totals, 'top': [code for code, score in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f102([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
103
def f103(left, right, excluded):
left = list(left)
def canon(value):
return str(value).strip(' ').upper()
excluded = {str(value).upper() for value in excluded}
a = {canon(value) for value in left} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f103(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
104
def f104(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
initial = dict(indegree)
handled = set()
result = []
rounds = []
while len(handled) < len(nodes):
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
handled.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f104(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
105
def f105(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f105(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
106
def f106(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
handled = set()
sequence = []
groups = []
while len(handled) < len(nodes) and len(handled) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
if not nextbatch:
break
current = nextbatch
groups.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f106(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
107
def f107(rows, keep, factors):
rows = list(rows)
kept = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
cost = value * factors[group]
kept.append((code, cost))
totals[group] = totals.get(group, 0) + cost
amount += cost
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, cost in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f107([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
108
def f108(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in wordmap.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f108(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
109
def f109(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop or len(word) < 2:
continue
wordmap[word] = wordmap.get(word, 0) + 1
sorteditems = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in wordmap.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in wordmap.items())))}
output = dict()
output.update(returnvalue)
return output
f109(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
110
def f110(left, right, excluded):
left = list(left)
def canon(value):
return str(value).strip(' \r').upper()
excluded = {canon(value) for value in excluded}
a = {canon(value) for value in left} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f110(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
111
def f111(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f111([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
112
def f112(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip().upper()
excluded = {str(value).strip() for value in excluded}
a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
b = {normalize(value) for value in right if normalize(value) != ''} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f112(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
113
def f113(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f113([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
114
def f114(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f114([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
115
def f115(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f115([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
116
def f116(rows, keep, factors):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value != 0:
cost = value * factors[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f116([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
117
def f117(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop or len(word) > 12:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in wordmap.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f117(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
118
def f118(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted({key for key, count in left if key not in ratemap})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f118([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
119
def f119(rows, keep, factors):
rows = list(rows)
matches = []
groupmap = {}
grand = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep} and value >= 0:
cost = value * factors[group]
matches.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
grand += cost
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(matches), 'total': grand, 'groups': groupmap, 'top': list(dict.fromkeys((code for code, cost in matches)))[:3]}
output = dict()
output.update(returnvalue)
return output
f119([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
120
def f120(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] <= pair[1])):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
spaces = []
for pos in range(1, min(50, len(combined))):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f120([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
121
def f121(rows, keep, prices):
rows = list(rows)
kept = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
charge = value * abs(prices[group])
kept.append((code, charge))
buckets[group] = buckets.get(group, 0) + charge
amount += charge
kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(kept), 'total': amount, 'groups': buckets, 'top': [code for code, charge in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f121([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
122
def f122(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
excluded = {str(value).upper() for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f122(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
123
def f123(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f123([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
124
def f124(rows, keep, prices):
rows = list(rows)
kept = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * prices[group]
kept.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
amount += cost
kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': amount, 'groups': buckets, 'top': [code for code, cost in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f124([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
125
def f125(rows, keep, prices):
rows = list(rows)
kept = []
buckets = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep:
score = value * prices[group]
kept.append((code, score))
buckets[group] = buckets.get(group, 0) + score
sumvalue += score
kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': sumvalue, 'groups': buckets, 'top': list(dict.fromkeys((code for code, score in kept)))[:3]}
output = dict()
output.update(returnvalue)
return output
f125([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
126
def f126(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f126(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
127
def f127(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left:
if key in ratemap and count > 0:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f127([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
128
def f128(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, min(50, len(combined))):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f128([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
129
def f129(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop or len(word) < 2:
continue
frequency[word] = min(9, frequency.get(word, 0) + 1)
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f129(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
130
def f130(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f130(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
131
def f131(board):
board = list(board)
found = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
pending = [(row, col)]
found.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f131(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
132
def f132(rows, keep, prices):
rows = list(rows)
kept = []
totals = {}
amount = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if state in keep and value != 0:
cost = value * abs(prices[group])
kept.append((code, cost))
totals[group] = totals.get(group, 0) + cost
amount += cost
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, cost in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f132([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
133
def f133(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
ignored = {normalize(value) for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f133(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
134
def f134(left, right, excluded):
left = list(left)
def canon(value):
return str(value).strip(' ').upper()
excluded = {canon(value) for value in excluded}
a = {canon(value) for value in left} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f134(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
135
def f135(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
spaces = []
for pos in range(1, len(combined)):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f135([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
136
def f136(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
combined = []
for key, count in left:
if key in prices:
combined.append((key, count * prices[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f136([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
137
def f137(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f137([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
138
def f138(left, right, excluded):
left = list(left)
def canon(value):
return str(value).strip(' \r').upper()
excluded = {canon(value) for value in excluded}
a = {canon(value) for value in left} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f138(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
139
def f139(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(set(spans)):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = right
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f139([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
140
def f140(rows, keep, factors):
rows = list(rows)
matches = []
groupmap = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep} and value >= 0:
cost = value * abs(factors[group])
matches.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
amount += cost
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(matches), 'total': amount, 'groups': groupmap, 'top': [code for code, cost in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f140([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
141
def f141(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
needs[b] += 1
initial = dict(needs)
handled = set()
sequence = []
layers = []
while len(handled) < len(nodes) and len(handled) < 20:
available = sorted((node for node in nodes if needs[node] == 0 and node not in handled))
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
layers.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f141(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
142
def f142(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
growth = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': matches, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f142([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
143
def f143(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
sorteditems = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f143(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
144
def f144(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
terms = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in wordmap.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f144(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
145
def f145(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
finished = set()
result = []
rounds = []
while len(finished) < len(nodes) and len(finished) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f145(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
146
def f146(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + max(0, gap):
segments.append([left, right])
else:
segments[-1][1] = max(0, segments[-1][1], right)
gaps = []
for pos in range(1, min(50, len(segments))):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f146([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
147
def f147(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right:
if name0 not in factors:
factors[name0] = rate0
combined = []
for key, count in left[:20]:
if key in factors:
combined.append((key, count * factors[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted({key for key, count in left if key not in factors})
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': unmatched, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f147([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
148
def f148(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f148(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
149
def f149(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
result = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f149(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
150
def f150(board):
board = list(board)
visited = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f150(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
151
def f151(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
ignored = {normalize(value) for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f151(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
152
def f152(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
growth = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f152([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
153
def f153(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f153([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
154
def f154(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right:
if name0 not in factors:
factors[name0] = rate0
combined = []
for key, count in left:
if key in factors:
combined.append((key, count * factors[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f154([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
155
def f155(rows, keep, factors):
rows = list(rows)
selected = []
totals = {}
grand = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
cost = value * factors[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
grand += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': totals, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f155([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
156
def f156(rows, keep, ratemap):
rows = list(rows)
matches = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
charge = value * abs(ratemap[group])
matches.append((code, charge))
buckets[group] = buckets.get(group, 0) + charge
amount += charge
matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': buckets, 'top': [code for code, charge in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f156([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
157
def f157(rows, keep, prices):
rows = list(rows)
matches = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * abs(prices[group])
matches.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
amount += cost
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(matches), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, cost in matches)))[:3]}
output = dict()
output.update(returnvalue)
return output
f157([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
158
def f158(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not result or left > result[-1][1] + gap:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
spaces = []
for pos in range(1, len(result)):
left = result[pos][0]
spaces.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': spaces, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f158([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
159
def f159(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right:
if name0 not in factors:
factors[name0] = rate0
matched = []
for key, count in left:
if key in factors:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted({key for key, count in left if key not in factors})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f159([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
160
def f160(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f160([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
161
def f161(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z' or (char == "'" and word):
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop or len(word) < 2:
continue
wordmap[word] = wordmap.get(word, 0) + 1
sorteditems = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in wordmap.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in sorteditems[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f161(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
162
def f162(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z' or (char == "'" and word):
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f162(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
163
def f163(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(set(spans)):
if not combined or left >= combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(min(100, left - combined[pos - 1][1]))
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f163([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
164
def f164(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in wordmap.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f164(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
165
def f165(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
positions = [pos for pos, value in enumerate(windows) if value >= limit]
ups = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': positions, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f165([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
166
def f166(board):
board = list(board)
visited = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f166(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
167
def f167(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f167(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
168
def f168(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
ignored = {str(value).strip() for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f168(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
169
def f169(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f169([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
170
def f170(board):
board = list(board)
visited = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f170(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
171
def f171(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
sequence = []
rounds = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
if not available:
break
current = available
rounds.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f171(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
172
def f172(rows, keep, prices):
rows = list(rows)
selected = []
buckets = {}
grand = 0
for code, group, state, value in rows:
if state in keep:
charge = value * prices[group]
selected.append((code, charge))
buckets[group] = buckets.get(group, 0) + charge
grand += charge
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': grand, 'groups': buckets, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f172([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
173
def f173(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
indexes = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f173([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
174
def f174(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip(' \r').upper()[:12]
banned = {normalize(value) for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right if normalize(value) != ''} - banned
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f174(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
175
def f175(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f175(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
176
def f176(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f176(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
177
def f177(board):
board = list(board)
visited = set()
regions = []
for row in range(len(board)):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
work.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f177(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
178
def f178(left, right, ignored):
left = list(left)
def tidy(value):
return str(value).strip(' \r').upper()
ignored = {str(value).upper() for value in ignored}
a = {tidy(value) for value in left} - ignored
b = {tidy(value) for value in right} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f178(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
179
def f179(board):
board = list(board)
visited = set()
pieces = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
work.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f179(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
180
def f180(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(series))) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f180([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
181
def f181(rows, keep, prices):
rows = list(rows)
selected = []
groupmap = {}
sumvalue = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
charge = value * abs(prices[group])
selected.append((code, charge))
groupmap[group] = groupmap.get(group, 0) + charge
sumvalue += charge
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f181([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
182
def f182(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices and rate0 != 0:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f182([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
183
def f183(board):
board = list(board)
known = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in known:
continue
cells = []
pending = [(row, col)]
known.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f183(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
184
def f184(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left[:20]:
if key in ratemap and count > 0:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f184([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
185
def f185(lines, stop):
lines = list(lines)
tallies = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop or len(word) > 12:
continue
tallies[word] = tallies.get(word, 0) + 1
ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in tallies.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in tallies.items())))}
output = dict()
output.update(returnvalue)
return output
f185(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
186
def f186(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f186(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
187
def f187(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes) and len(finished) < 20:
available = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f187(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
188
def f188(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip().upper()
excluded = {str(value).strip() for value in excluded}
a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f188(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
189
def f189(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
routes[a].append(b)
indegree[b] += 1
rootsource = dict(indegree)
handled = set()
result = []
groups = []
while len(handled) < len(nodes):
available = sorted((node for node in nodes if indegree[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
groups.append(current)
for node in current:
handled.add(node)
result.append(node)
for node in current:
for nxt in routes[node]:
indegree[nxt] -= 1
returnvalue = {'order': result, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f189(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
190
def f190(board):
board = list(board)
visited = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f190(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
191
def f191(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
complete = set()
sequence = []
layers = []
while len(complete) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f191(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
192
def f192(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(set(spans)):
if not combined or left > combined[-1][1] + gap % 5:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f192([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
193
def f193(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
handled = set()
sequence = []
groups = []
while len(handled) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
if not nextbatch:
break
current = nextbatch
groups.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f193(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
194
def f194(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
incoming[b] += 1
initial = dict(incoming)
handled = set()
result = []
rounds = []
while len(handled) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
if not nextbatch:
break
current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
rounds.append(current)
for node in current:
handled.add(node)
result.append(node)
for node in current:
for nxt in routes[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f194(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
195
def f195(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f195([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
196
def f196(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f196(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
197
def f197(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = right
spaces = []
for pos in range(1, len(segments)):
left = segments[pos][0]
spaces.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f197([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
198
def f198(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(totals) if value > limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': indexes, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f198([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
199
def f199(rows, keep, ratemap):
rows = list(rows)
kept = []
totals = {}
grand = 0
for code, group, state, value in rows:
if state in keep:
score = value * abs(ratemap[group])
kept.append((code, score))
totals[group] = totals.get(group, 0) + score
grand += score
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': grand, 'groups': totals, 'top': [code for code, score in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f199([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
200
def f200(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f200(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
201
def f201(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': positions, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f201([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
202
def f202(left, right, excluded):
left = list(left)
def tidy(value):
return str(value).strip(' \r').upper()
excluded = {str(value).strip() for value in excluded}
a = {tidy(value) for value in left} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f202(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
203
def f203(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f203([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
204
def f204(left, right, excluded):
left = list(left)
def normalize(value):
return ' '.join(str(value).split()).upper()
excluded = {str(value).upper() for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f204(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
205
def f205(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left >= segments[-1][1] + gap:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f205([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
206
def f206(board):
board = list(board)
found = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f206(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
207
def f207(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans, key=lambda pair: pair[0]):
if not segments or left > segments[-1][1] + gap:
segments.append([left, right])
else:
segments[-1][1] = max(0, segments[-1][1], right)
spaces = []
for pos in range(1, len(segments)):
left = segments[pos][0]
spaces.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': min(100, max((right - left for left, right in segments)))}
output = dict()
output.update(returnvalue)
return output
f207([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
208
def f208(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices and rate0 != 0:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices and count > 0:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': unmatched, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f208([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
209
def f209(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
score = value * abs(ratemap[group])
selected.append((code, score))
totals[group] = totals.get(group, 0) + score
amount += score
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': list(dict.fromkeys((code for code, score in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f209([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
210
def f210(left, right, excluded):
left = list(left)
def canon(value):
return ' '.join(str(value).split()).upper()
excluded = {str(value).upper() for value in excluded}
a = {canon(value) for value in left} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f210(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
211
def f211(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors or rate0 <= rate0 + 0:
factors[name0] = rate0
items = []
for key, count in left[:20]:
if key in factors:
items.append((key, count * factors[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f211([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
212
def f212(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(totals) if value > limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f212([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
213
def f213(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(min(64, len(values) - size + 1)):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f213([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
214
def f214(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left >= combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
spaces = []
for pos in range(1, len(combined)):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f214([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
215
def f215(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f215(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
216
def f216(board):
board = list(board)
found = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in found:
continue
cells = []
pending = [(row, col)]
found.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f216(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
217
def f217(board):
board = list(board)
known = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in known:
continue
cells = []
pending = [(row, col)]
known.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
pending.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f217(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
218
def f218(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
items = []
for key, count in left[:20]:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len({key for key, value in items})}
output = dict()
output.update(returnvalue)
return output
f218([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
219
def f219(left, right, ignored):
left = list(left)
def tidy(value):
return str(value).strip().upper()
ignored = {tidy(value) for value in ignored}
a = {tidy(value) for value in left} - ignored
b = {tidy(value) for value in right if tidy(value) != ''} - ignored
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f219(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
220
def f220(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
series = []
for pos in range(len(values) - size + 1):
series.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': max([0] + series), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f220([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
221
def f221(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f221([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
222
def f222(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
complete = set()
sequence = []
groups = []
while len(complete) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
if not available:
break
current = available
groups.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f222(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
223
def f223(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices and count > 0:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f223([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
224
def f224(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f224([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
225
def f225(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop or len(word) > 12:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f225(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
226
def f226(rows, keep, prices):
rows = list(rows)
kept = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep:
charge = value * prices[group]
kept.append((code, charge))
totals[group] = totals.get(group, 0) + charge
sumvalue += charge
kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': sumvalue, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in kept)))[:3]}
output = dict()
output.update(returnvalue)
return output
f226([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
227
def f227(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
routes[a].append(b)
needs[b] += 1
initial = dict(needs)
complete = set()
listing = []
rounds = []
while len(complete) < len(nodes) and len(complete) < 20:
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
complete.add(node)
listing.append(node)
for node in current:
for nxt in routes[node]:
needs[nxt] -= 1
returnvalue = {'order': listing, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f227(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
228
def f228(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f228([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
229
def f229(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f229(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
230
def f230(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum((max(item, 0) for item in values[pos:pos + size])))
positions = [pos for pos, value in enumerate(series) if value >= limit and (limit >= 0 or pos > 0)]
increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': positions, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f230([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
231
def f231(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
positions = [pos for pos, value in enumerate(windows) if value > limit]
ups = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': positions, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f231([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
232
def f232(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap or rate0 <= rate0 + 0:
ratemap[name0] = rate0
combined = []
for key, count in left:
if key in ratemap and count > 0:
combined.append((key, count * ratemap[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f232([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
233
def f233(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
routes[a].append(b)
needs[b] += 1
rootsource = dict(needs)
handled = set()
sequence = []
layers = []
while len(handled) < len(nodes) and len(handled) < 20:
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in handled), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in routes[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f233(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
234
def f234(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(totals) if value >= limit]
growth = sum((1 for pos in range(1, len(totals)) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': positions, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f234([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
235
def f235(rows, keep, prices):
rows = list(rows)
kept = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
score = value * prices[group]
kept.append((code, score))
totals[group] = totals.get(group, 0) + score
sumvalue += score
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': sumvalue, 'groups': totals, 'top': [code for code, score in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f235([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
236
def f236(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, len(totals)) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f236([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
237
def f237(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
needs[b] += 1
initial = dict(needs)
handled = set()
result = []
groups = []
while len(handled) < len(nodes):
available = sorted((node for node in nodes if needs[node] == 0 and node not in handled), reverse=len(nodes) > 20)
if not available:
break
current = available
groups.append(current)
for node in current:
handled.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': result, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f237(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
238
def f238(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
initial = dict(incoming)
complete = set()
sequence = []
layers = []
while len(complete) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
layers.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f238(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
239
def f239(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
returnvalue = {'sums': series, 'best': max([0] + series), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f239([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
240
def f240(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = max(0, segments[-1][1], right)
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f240([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
241
def f241(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip().upper()
excluded = {str(value).strip() for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f241(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
242
def f242(lines, stop):
lines = list(lines)
tallies = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in tallies.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f242(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
243
def f243(rows, keep, factors):
rows = list(rows)
matches = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
score = value * abs(factors[group])
matches.append((code, score))
buckets[group] = buckets.get(group, 0) + score
amount += score
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, score in matches)))[:3]}
output = dict()
output.update(returnvalue)
return output
f243([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
244
def f244(board):
board = list(board)
visited = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f244(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
245
def f245(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
excluded = {str(value).strip() for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f245(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
246
def f246(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f246(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
247
def f247(board):
board = list(board)
visited = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f247(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
248
def f248(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z' or (char == "'" and word):
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f248(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
249
def f249(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f249(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
250
def f250(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(series) if value > limit]
increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': max(series), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f250([22, 14, 18, 14, 24, 19, 19, 13, 16, 21, 9, 7, 20, 12, 15], 4, 77)
{"best":76,"hits":[],"rises":6,"sums":[68,70,75,76,75,67,69,59,53,57,48,54]}
251
def f251(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(spans):
if not result or left > result[-1][1] + gap % 5:
result.append([left, right])
else:
result[-1][1] = max(0, result[-1][1], right)
gaps = []
for pos in range(1, len(result)):
left = result[pos][0]
gaps.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f251([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
252
def f252(rows, keep, ratemap):
rows = list(rows)
matches = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep:
score = value * ratemap[group]
matches.append((code, score))
totals[group] = totals.get(group, 0) + score
sumvalue += score
matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': sumvalue, 'groups': totals, 'top': [code for code, score in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f252([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
253
def f253(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit and (limit >= 0 or pos > 0)]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f253([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
254
def f254(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right:
if name0 not in factors and rate0 != 0:
factors[name0] = rate0
matched = []
for key, count in left:
if key in factors:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f254([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
255
def f255(rows, keep, factors):
rows = list(rows)
selected = []
buckets = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep and value != 0:
charge = value * factors[group]
selected.append((code, charge))
buckets[group] = buckets.get(group, 0) + charge
sumvalue += charge
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': buckets, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f255([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
256
def f256(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((min(100, right - left) for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f256([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
257
def f257(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f257(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
258
def f258(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted((pair for pair in spans if pair[0] <= pair[1])):
if not segments or left > segments[-1][1] + min(gap, 2):
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
gaps = []
for pos in range(1, min(50, len(segments))):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f258([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
259
def f259(rows, keep, ratemap):
rows = list(rows)
selected = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
cost = value * ratemap[group]
selected.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f259([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
260
def f260(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in routes[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f260(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
261
def f261(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
banned = {str(value).strip() for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right} - banned
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f261(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
262
def f262(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z' or (char == "'" and word):
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop or len(word) > 12:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f262(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
263
def f263(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
indexes = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f263([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
264
def f264(rows, keep, prices):
rows = list(rows)
matches = []
totals = {}
sumvalue = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if str(state).lower() in {str(item).lower() for item in keep}:
score = value * abs(prices[group])
matches.append((code, score))
totals[group] = totals.get(group, 0) + score
sumvalue += score
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(matches), 'total': sumvalue, 'groups': totals, 'top': [code for code, score in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f264([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
265
def f265(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
if not combined or left >= combined[-1][1] + gap % 5:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f265([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
266
def f266(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f266(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
267
def f267(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
combined = []
for key, count in left[:20]:
if key in prices:
combined.append((key, count * prices[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': unmatched, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f267([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
268
def f268(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
handled = set()
listing = []
rounds = []
while len(handled) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
handled.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f268(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
269
def f269(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(series))) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': max(series), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f269([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
270
def f270(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f270([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
271
def f271(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
items = []
for key, count in left[:20]:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f271([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
272
def f272(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes) and len(finished) < 20:
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f272(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
273
def f273(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(set(spans)):
if not combined or left > combined[-1][1] + gap % 5:
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f273([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
274
def f274(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f274(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
275
def f275(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(set(spans)):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = right
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f275([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
276
def f276(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
items = []
for key, count in left[:20]:
if key in ratemap:
items.append((key, count * ratemap[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in ratemap})
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len({key for key, value in items})}
output = dict()
output.update(returnvalue)
return output
f276([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 3)
{"count":6,"items":[["BR",93],["GQ",59],["DL",39],["FP",38],["AN",24]],"missing":["EV","HR"],"total":264}
277
def f277(rows, keep, factors):
rows = list(rows)
selected = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * factors[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f277([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
278
def f278(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
items = []
for key, count in left[:20]:
if key in ratemap:
items.append((key, count * ratemap[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in ratemap})
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len({key for key, value in items})}
output = dict()
output.update(returnvalue)
return output
f278([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
279
def f279(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
needs[b] += 1
initial = dict(needs)
handled = set()
sequence = []
rounds = []
while len(handled) < len(nodes) and len(handled) < 20:
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f279(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
280
def f280(lines, stop):
lines = list(lines)
tallies = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in tallies.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f280(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
281
def f281(lines, stop):
lines = list(lines)
tallies = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in tallies.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in tallies.items())))}
output = dict()
output.update(returnvalue)
return output
f281(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
282
def f282(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + max(0, gap):
segments.append([left, right])
else:
segments[-1][1] = right
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f282([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
283
def f283(board):
board = list(board)
found = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in found:
continue
cells = []
work = [(row, col)]
found.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
work.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f283(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
284
def f284(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
items = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop or len(word) < 2:
continue
frequency[word] = min(9, frequency.get(word, 0) + 1)
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f284(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
285
def f285(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
needs[b] += 1
initial = dict(needs)
finished = set()
sequence = []
groups = []
while len(finished) < len(nodes) and len(finished) < 20:
available = sorted((node for node in nodes if needs[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
groups.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f285(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
286
def f286(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
ignored = {normalize(value) for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f286(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
287
def f287(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f287([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
288
def f288(rows, keep, ratemap):
rows = list(rows)
selected = []
groupmap = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value != 0:
cost = value * ratemap[group]
selected.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': groupmap, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f288([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
289
def f289(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
banned = {str(value).strip() for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right} - banned
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f289(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
290
def f290(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms[:64]:
if word in stop or len(word) < 2:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f290(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"quartz":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"q":1},"size":142,"top":["delta","garnet","cyan","ember","blue"]}
291
def f291(left, right, ignored):
left = list(left)
def canon(value):
return str(value).strip().upper()
ignored = {canon(value) for value in ignored}
a = {canon(value) for value in left} - ignored
b = {canon(value) for value in right} - ignored
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f291(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
292
def f292(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f292([(2, 7), (5, 11), (14, 16), (18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,5,8,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[28,36],[44,50],[59,63]]}
293
def f293(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
excluded = {normalize(value) for value in excluded}
a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f293(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
294
def f294(rows, keep, prices):
rows = list(rows)
kept = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
cost = value * abs(prices[group])
kept.append((code, cost))
totals[group] = totals.get(group, 0) + cost
amount += cost
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, cost in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f294([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
295
def f295(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
listing = []
groups = []
while len(finished) < len(nodes) and len(finished) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch
groups.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in routes[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f295(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
296
def f296(rows, keep, prices):
rows = list(rows)
kept = []
buckets = {}
sumvalue = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
score = value * abs(prices[group])
kept.append((code, score))
buckets[group] = buckets.get(group, 0) + score
sumvalue += score
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(kept), 'total': sumvalue, 'groups': buckets, 'top': [code for code, score in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f296([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
297
def f297(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f297(['Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta', 'Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet'], ['amber'])
{"counts":{"blue":3,"cyan":4,"delta":6,"ember":4,"frost":2,"garnet":5,"helium":3,"vivid":1},"initials":{"b":3,"c":4,"d":6,"e":4,"f":2,"g":5,"h":3,"v":1},"size":141,"top":["delta","garnet","cyan","ember","blue"]}
298
def f298(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(set(spans)):
if not segments or left > segments[-1][1] + min(gap, 2):
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(min(100, left - segments[pos - 1][1]))
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f298([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
299
def f299(board):
board = list(board)
known = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in known:
continue
cells = []
work = [(row, col)]
known.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f299(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
300
def f300(left, right, excluded):
left = list(left)
def tidy(value):
return ' '.join(str(value).split()).upper()
excluded = {str(value).strip() for value in excluded}
a = {tidy(value) for value in left} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f300(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyanx', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYANX","DELTA","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYANX","FROST"],"score":10}
301
def f301(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(min(64, len(values) - size + 1)):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value > limit]
increases = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f301([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
302
def f302(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
indexes = [pos for pos, value in enumerate(totals[:64]) if value > limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': indexes, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f302([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
303
def f303(board):
board = list(board)
known = set()
regions = []
for row in range(len(board)):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in known:
continue
cells = []
queue = [(row, col)]
known.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f303(['.##..#', '#.....', '...#..', '...#..', '.....#', '.#...#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0],[5,1]],"count":6,"filled":9,"sizes":[2,2,2,1,1,1]}
304
def f304(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left[:20]:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f304([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
305
def f305(left, right, banned):
left = list(left)
def canon(value):
return str(value).strip().upper()
banned = {str(value).strip() for value in banned}
a = {canon(value) for value in left if canon(value) != canon(value) or canon(value) != ''} - banned
b = {canon(value) for value in right} - banned
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f305(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
306
def f306(rows, keep, ratemap):
rows = list(rows)
selected = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * ratemap[group]
selected.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f306([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":132,"north":112,"south":420},"top":["AN58","CX73","CX69"],"total":1093}
307
def f307(rows, keep, factors):
rows = list(rows)
matches = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
charge = value * factors[group]
matches.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': totals, 'top': [code for code, charge in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f307([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
308
def f308(rows, keep, factors):
rows = list(rows)
selected = []
totals = {}
sumvalue = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * factors[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f308([('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7), ('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":12,"groups":{"core":429,"edge":141,"north":112,"south":400},"top":["AN58","CX69","CX73"],"total":1082}
309
def f309(left, right, ignored):
left = list(left)
def normalize(value):
return ' '.join(str(value).split()).upper()
ignored = {str(value).upper() for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f309(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
310
def f310(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f310([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
311
def f311(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
ignored = {str(value).upper() for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right if normalize(value) != ''} - ignored
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f311(['Ember', 'delta', ' Amber', 'GARNET', 'ivory', 'helium', 'Ember'], ['BLUE', 'Ember', ' Amber', 'ivory', 'frost', 'cyan ', 'Emberx'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","EMBERX","FROST","GARNET","HELIUM","IVORY"],"both":["AMBER","IVORY"],"left":["DELTA","GARNET","HELIUM"],"right":["BLUE","CYAN","EMBERX","FROST"],"score":10}
312
def f312(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': positions, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f312([22, 19, 18, 14, 24, 19, 19, 11, 16, 21, 9, 7, 20, 12, 15], 4, 78)
{"best":76,"hits":[],"rises":5,"sums":[73,75,75,76,73,65,67,57,53,57,48,54]}
313
def f313(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
listing = []
rounds = []
while len(finished) < len(nodes) and len(finished) < 20:
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': listing, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f313(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
314
def f314(board):
board = list(board)
found = set()
regions = []
for row in range(len(board)):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
work = [(row, col)]
found.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
work.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f314(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
315
def f315(board):
board = list(board)
known = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in known:
continue
cells = []
queue = [(row, col)]
known.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f315(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
316
def f316(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans, key=lambda pair: pair[0]):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
spaces = []
for pos in range(1, len(segments)):
left = segments[pos][0]
spaces.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': min(100, max((right - left for left, right in segments)))}
output = dict()
output.update(returnvalue)
return output
f316([(2, 7), (5, 11), (14, 16), (18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63)], 1)
{"cover":34,"holes":[3,2,7,6,9],"longest":9,"segments":[[2,11],[14,16],[18,23],[30,37],[43,50],[59,63]]}
317
def f317(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
needs[b] += 1
startdegree = dict(needs)
complete = set()
sequence = []
layers = []
while len(complete) < len(nodes):
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
layers.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f317(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
318
def f318(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right:
if name0 not in factors:
factors[name0] = rate0
combined = []
for key, count in left:
if key in factors:
combined.append((key, count * factors[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in factors})
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f318([('AN', 3), ('BR', 10), ('CX', 2), ('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)], [('AN', 7), ('BR', 9), ('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)], 2)
{"count":6,"items":[["BR",92],["GQ",58],["DL",38],["FP",37],["AN",23]],"missing":["EV","HR"],"total":258}
319
def f319(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
initial = dict(indegree)
handled = set()
sequence = []
layers = []
while len(handled) < len(nodes) and len(handled) < 20:
available = sorted((node for node in nodes if indegree[node] == 0 and node not in handled))
if not available:
break
current = available
layers.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f319(['proxy', 'jobs', 'auth', 'db', 'worker', 'cache', 'ui', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}
320
def f320(board):
board = list(board)
found = set()
regions = []
for row in range(len(board)):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
pending = [(row, col)]
found.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
pending.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f320(['.###.#', '#.....', '...#..', '...#..', '.....#', '.....#'])
{"anchors":[[0,1],[2,3],[4,5],[0,5],[1,0]],"count":5,"filled":9,"sizes":[3,2,2,1,1]}
Final Query
Give me the output of the final query without executing it!
import json, re
from collections import deque
out = {}
left = list(('Ember', 'delta', ' Amber') + ('GARNET', 'ivory', 'helium', 'Ember'))
right = list(('BLUE', 'Ember', ' Amber') + ('ivory', 'frost', 'cyanx', 'Ember'))
blocked = ['EMBER']
a = set()
b = set()
ban = set()
for value in blocked:
ban.add(value.strip().upper())
for value in left:
value = value.strip().upper()
if value not in ban:
a.add(value)
for value in right:
value = value.strip().upper()
if value not in ban:
b.add(value)
both = a.intersection(b)
record = {'aa': sorted(both), 'bb': sorted(a.difference(b)), 'cc': sorted(b.difference(a)), 'dd': sorted(a.union(b)), 'ee': sum(map(len, both))}
permit = record['cc'][1]
keep = list(('ready',) + ('checked',))
rates = dict((('north', 7),) + (('south', 5), ('core', 11), ('edge', 3)))
route = permit
cases = {
'CYAN': list((('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 17), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7)) + (('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 23), ('DL43', 'south', 'checked', 17))),
'CYANX': list((('AN62', 'north', 'ready', 6), ('CX99', 'north', 'ready', 10), ('AN36', 'edge', 'checked', 24), ('CX73', 'south', 'ready', 21), ('AN10', 'core', 'checked', 7), ('DL47', 'core', 'hold', 7)) + (('AN84', 'edge', 'hold', 9), ('DL21', 'south', 'ready', 14), ('AN58', 'core', 'checked', 24), ('AN95', 'south', 'checked', 16), ('AN32', 'south', 'ready', 16), ('CX69', 'core', 'ready', 8), ('CX06', 'edge', 'checked', 20), ('DL43', 'south', 'checked', 17))),
}
rows = cases[route]
chosen = [(code, group, value) for code, group, state, value in rows if state in keep]
priced = [(code, group, value * rates[group]) for code, group, value in chosen]
groups = {}
for code, group, price in priced:
groups[group] = groups.get(group, 0) + price
ranked = sorted(priced, key=lambda row: (-row[2], row[0]))
record = {'aa': [row[0] for row in ranked[:3]], 'bb': sum((row[2] for row in priced)), 'cc': len(priced), 'dd': groups}
signal = record['bb']
nodes = list(('proxy', 'jobs', 'auth', 'db', 'worker') + ('cache', 'ui', 'api'))
route = signal
cases = {
1093: list((('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs')) + (('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('auth', 'db'))),
1082: list((('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs')) + (('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth'))),
}
edges = cases[route]
remaining = set(nodes)
done = set()
order = []
batches = []
while remaining:
ready = sorted((node for node in remaining if all((before in done for before, after in edges if after == node))))
if not ready:
break
batches.append(ready)
order.extend(ready)
done.update(ready)
remaining.difference_update(ready)
roots = sorted((node for node in nodes if all((after != node for before, after in edges))))
record = {'aa': order, 'bb': batches, 'cc': roots, 'dd': len(order)}
token = record['aa'][0]
stop = ['amber']
route = token
cases = {
'cache': list(('Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta') + ('Helium, garnet. helium ember delta', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet quartz', 'Helium, cyan. garnet garnet')),
'auth': list(('Cyan, cyan. blue ember', 'Frost, blue. blue garnet delta', 'Amber, amber. delta delta') + ('Helium, garnet. helium ember delta vivid', 'Ember, frost. amber delta', 'Amber, delta. cyan ember garnet', 'Helium, cyan. garnet garnet')),
}
lines = cases[route]
normalized = set()
for item in stop:
normalized.add(item.lower())
stop = normalized
words = []
for line in lines:
words.extend(re.findall('[a-z]+', line.lower()))
words = [word for word in words if word not in stop]
counts = {}
initials = {}
for word in words:
counts[word] = counts.get(word, 0) + 1
initials[word[0]] = initials.get(word[0], 0) + 1
top = sorted(counts, key=lambda word: (-counts[word], word))[:5]
record = {'aa': top, 'bb': counts, 'cc': initials, 'dd': sum((len(word) for word in words))}
memo = record['dd']
left = list((('AN', 3), ('BR', 10), ('CX', 2)) + (('DL', 4), ('EV', 10), ('FP', 7), ('GQ', 7), ('HR', 4)))
right = list((('AN', 7), ('BR', 9)) + (('CX', 4), ('DL', 9), ('FP', 5), ('GQ', 8)))
route = signal
cases = {
1093: 2,
1082: 3,
}
fee = cases[route]
joined = []
for key, count in left:
matches = [rate for name, rate in right if name == key]
if matches:
joined.append([key, count * matches[0] + fee])
joined.sort(key=lambda item: (-item[1], item[0]))
rightkeys = {key for key, rate in right}
record = {'aa': joined[:5], 'bb': sum((item[1] for item in joined)), 'cc': sorted((key for key, count in left if key not in rightkeys)), 'dd': len(joined)}
clue = record['bb']
route = (memo, clue)
cases = {
(142, 264): list(('.###.#', '#.....', '...#..', '...#..') + ('.....#', '.....#')),
(142, 258): list(('.###.#', '#.....', '...#..', '...#..') + ('.....#', '.....#')),
(141, 264): list(('.###.#', '#.....', '...#..', '...#..') + ('.....#', '.....#')),
(141, 258): list(('.##..#', '#.....', '...#..', '...#..') + ('.....#', '.#...#')),
}
board = cases[route]
cells = [(row, col) for row in range(len(board)) for col in range(len(board[row])) if board[row][col] == '#']
parent = {cell: cell for cell in cells}
def root(cell):
while parent[cell] != cell:
parent[cell] = parent[parent[cell]]
cell = parent[cell]
return cell
def merge(a, b):
a = root(a)
b = root(b)
if a != b:
parent[b] = a
for row, col in cells:
for other in ((row - 1, col), (row, col - 1)):
if other in parent:
merge((row, col), other)
groups = {}
for cell in cells:
groups.setdefault(root(cell), []).append(cell)
parts = [(len(group), min(group)) for group in groups.values()]
parts.sort(key=lambda item: (-item[0], item[1]))
record = {'aa': [part[0] for part in parts], 'bb': [list(part[1]) for part in parts], 'cc': len(cells), 'dd': len(parts)}
stamp = record['dd']
width = 4
route = stamp
cases = {
6: (list((22, 14, 18, 14, 24, 19, 19) + (13, 16, 21, 9, 7, 20, 12, 15)), 77),
5: (list((22, 19, 18, 14, 24, 19, 19) + (11, 16, 21, 9, 7, 20, 12, 15)), 78),
}
values, limit = cases[route]
current = sum(values[:width])
sums = [current]
for pos in range(width, len(values)):
current += values[pos] - values[pos - width]
sums.append(current)
hits = []
rises = 0
for pos, value in enumerate(sums):
if value >= limit:
hits.append(pos)
if pos and value > sums[pos - 1]:
rises += 1
record = {'aa': hits, 'bb': max(sums), 'cc': rises, 'dd': sums}
ticket = record['cc']
gap = 1
route = ticket
cases = {
5: list(((2, 7), (5, 11), (14, 16)) + ((18, 23), (30, 37), (33, 36), (43, 49), (48, 50), (59, 63))),
6: list(((2, 7), (5, 11), (14, 16)) + ((18, 23), (28, 35), (33, 36), (44, 50), (48, 50), (59, 63))),
}
spans = cases[route]
spans.sort(key=lambda pair: (pair[0], pair[1]))
parts = []
pos = 0
while pos < len(spans):
left, right = spans[pos]
pos += 1
while pos < len(spans) and spans[pos][0] <= right + gap:
right = max(right, spans[pos][1])
pos += 1
parts.append([left, right])
holes = [parts[pos][0] - parts[pos - 1][1] for pos in range(1, len(parts))]
record = {'aa': parts, 'bb': holes, 'cc': sum((part[1] - part[0] for part in parts)), 'dd': max((part[1] - part[0] for part in parts))}
out['aa'] = record['aa']
out['bb'] = record['bb']
out['cc'] = record['cc']
out['dd'] = record['dd']
print(json.dumps(out, separators=(",", ":"), sort_keys=True))