quanghieupham's picture
Publish LongHarness benchmark snapshot (part 2)
43729b2 verified
|
Raw History Blame Contribute Delete
377 kB

001

def f1(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * prices[group]
            selected.append((code, score))
            buckets[group] = buckets.get(group, 0) + score
            amount += score
    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, score in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f1([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

002

def f2(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[:20]:
        if key in ratemap:
            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({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output
f2([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

003

def f3(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(windows[:64]) 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
f3([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

004

def f4(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([0] + windows), 'hits': positions, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f4([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

005

def f5(nodes, edges):
    nodes = list(nodes)
    indegree = {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)
        indegree[b] += 1
    rootsource = dict(indegree)
    complete = set()
    sequence = []
    groups = []
    while len(complete) < len(nodes) and len(complete) < 20:
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in complete))
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in nextmap[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f5(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', '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(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f6([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

007

def f7(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(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': min(256, max(windows)), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f7([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

008

def f8(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f8([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

009

def f9(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.setdefault(a, []).append(b)
    distance = {start: 0} if any((start in edge for edge in edges)) else {}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    pending.append(nxt)
    sequence = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f9([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

010

def f10(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:
        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
f10([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

011

def f11(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
f11([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

012

def f12(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f12([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

013

def f13(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)
    handled = set()
    sequence = []
    layers = []
    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
        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
f13(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

014

def f14(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
    startdegree = dict(incoming)
    finished = set()
    result = []
    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=len(nodes) > 20)
        if not available:
            break
        current = available
        rounds.append(current)
        for node in current:
            finished.add(node)
            result.append(node)
        for node in current:
            for nxt in nextmap[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output
f14(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

015

def f15(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
        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
f15([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

016

def f16(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]))
    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(matched)}
    output = dict()
    output.update(returnvalue)
    return output
f16([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

017

def f17(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = min(64, max(far, abs(x) + abs(y)))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f17([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

018

def f18(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap or rate0 <= rate0 + 0:
            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({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output
f18([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

019

def f19(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] = 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
f19([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

020

def f20(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[:20]:
        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
f20([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

021

def f21(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()
    result = []
    layers = []
    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=any((str(node).isupper() for node in nodes)))
        if not nextbatch:
            break
        current = nextbatch
        layers.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': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output
f21(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

022

def f22(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
f22([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

023

def f23(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]))
    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
f23([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

024

def f24(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.setdefault(a, []).append(b)
    steps = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < min(limit, 3):
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps and (not nxt.startswith('Z')):
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    result = list(steps)
    edge = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': result, 'depth': steps, 'frontier': edge, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f24([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

025

def f25(rows, keep, prices):
    rows = list(rows)
    kept = []
    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:
            cost = value * 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(kept), 'total': amount, 'groups': buckets, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f25([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

026

def f26(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)
    finished = set()
    result = []
    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
        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
f26(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

027

def f27(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(set(spans)):
        if not result or left > result[-1][1] + max(0, gap):
            result.append([left, right])
        else:
            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
f27([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

028

def f28(rows, keep, prices):
    rows = list(rows)
    matches = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * prices[group]
            matches.append((code, score))
            groupmap[group] = groupmap.get(group, 0) + score
            amount += score
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': amount, 'groups': groupmap, 'top': [code for code, score in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f28([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

029

def f29(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[:64]:
        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
f29(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

030

def f30(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()
    result = []
    rounds = []
    while len(handled) < len(nodes):
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in handled))
        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]:
                needs[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
f30(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

031

def f31(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
f31([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

032

def f32(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f32([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

033

def f33(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]))
    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
f33([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

034

def f34(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:32]:
        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[:64]:
        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
f34(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

035

def f35(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, 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
f35([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

036

def f36(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:
            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) > 12:
            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': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f36(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

037

def f37(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in returns:
                returns.append(list(point))
            known.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f37([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

038

def f38(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in returns:
                returns.append(list(point))
            found.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f38([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

039

def f39(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(nextmap.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    result = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': result, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f39([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

040

def f40(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        nextmap.setdefault(a, []).append(b)
    steps = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < min(limit, 3):
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    result = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': result, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f40([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

041

def f41(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:
            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
    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
f41(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

042

def f42(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f42([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

043

def f43(rows, keep, prices):
    rows = list(rows)
    matches = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * abs(prices[group])
            matches.append((code, score))
            buckets[group] = buckets.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': buckets, 'top': [code for code, score in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f43([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

044

def f44(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f44([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

045

def f45(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in visited and list(point) not in repeats:
                repeats.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f45([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

046

def f46(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    indexes = [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': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f46([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

047

def f47(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = min(64, max(far, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f47([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

048

def f48(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 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
            grand += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f48([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

049

def f49(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(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': min(256, max(windows)), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f49([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

050

def f50(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
f50([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

051

def f51(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, min(65, len(windows))) if windows[pos] >= windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f51([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

052

def f52(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, 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, min(65, 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
f52([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

053

def f53(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]))
    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
f53([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

054

def f54(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:
        if before == after:
            continue
        a, b = (before, after)
        children[a].append(b)
        indegree[b] += 1
    startdegree = dict(indegree)
    finished = set()
    sequence = []
    groups = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished))
        if not nextbatch:
            break
        current = nextbatch
        groups.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': groups, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f54(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

055

def f55(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans, key=lambda pair: pair[0]):
        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, 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
f55([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

056

def f56(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]
    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': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f56([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

057

def f57(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges[:16]:
        children.setdefault(a, []).append(b)
    steps = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    pending.append(nxt)
    result = list(steps)
    lastlevel = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': result, 'depth': steps, 'frontier': lastlevel[:3], 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f57([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

058

def f58(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    items = []
    for line in lines[:32]:
        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[:64]:
        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
f58(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

059

def f59(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)
    finished = set()
    result = []
    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))
        if not available:
            break
        current = available
        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 initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output
f59(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

060

def f60(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[:64]:
        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
f60(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

061

def f61(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 = []
    layers = []
    while len(handled) < len(nodes) and len(handled) < 20:
        available = 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 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 initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f61(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

062

def f62(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[: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({key for key, value in items})}
    output = dict()
    output.update(returnvalue)
    return output
f62([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

063

def f63(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {str(word) 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[:64]:
        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': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f63(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

064

def f64(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) for word in stop}
    items = []
    for line in lines[:20]:
        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:
            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': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f64(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

065

def f65(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(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(windows), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f65([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

066

def f66(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
f66([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

067

def f67(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
    initial = dict(needs)
    finished = set()
    result = []
    rounds = []
    while len(finished) < len(nodes):
        available = sorted((node for node in nodes if needs[node] == 0 and node not in finished))
        if not available:
            break
        current = available
        rounds.append(current)
        for node in current:
            finished.add(node)
            result.append(node)
        for node in current:
            for nxt in nextmap[node]:
                needs[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
f67(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

068

def f68(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) 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
        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
f68(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

069

def f69(nodes, edges):
    nodes = list(nodes)
    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
    rootsource = dict(incoming)
    handled = set()
    result = []
    layers = []
    while len(handled) < len(nodes) and len(handled) < 20:
        available = sorted((node for node in nodes if incoming[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)
            result.append(node)
        for node in current:
            for nxt in nextmap[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output
f69(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

070

def f70(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + gap:
            result.append([left, right])
        else:
            result[-1][1] = right
    gaps = []
    for pos in range(1, min(50, len(result))):
        left = result[pos][0]
        gaps.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((min(100, 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
f70([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

071

def f71(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 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': min(256, max(windows)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f71([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

072

def f72(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 = []
    rounds = []
    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
        rounds.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': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f72(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

073

def f73(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': list(dict.fromkeys((code for code, cost in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f73([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

074

def f74(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        if name0 not in ratemap:
            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]))
    leftover = 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': leftover, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output
f74([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

075

def f75(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(matched)}
    output = dict()
    output.update(returnvalue)
    return output
f75([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

076

def f76(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
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in tallies.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f76(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

077

def f77(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
    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
f77(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

078

def f78(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in found and list(point) not in crossings:
                crossings.append(list(point))
            found.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f78([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

079

def f79(nodes, edges):
    nodes = list(nodes)
    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
    rootsource = dict(incoming)
    handled = set()
    listing = []
    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[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        layers.append(current)
        for node in current:
            handled.add(node)
            listing.append(node)
        for node in current:
            for nxt in nextmap[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f79(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

080

def f80(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
        if not result or left > result[-1][1] + gap:
            result.append([left, right])
        else:
            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
f80([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

081

def f81(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)
    complete = set()
    sequence = []
    rounds = []
    while len(complete) < len(nodes):
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in complete))
        if not available:
            break
        current = available
        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 rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f81(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

082

def f82(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    listing = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': listing, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f82([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

083

def f83(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + gap % 5 + 1:
            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
f83([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

084

def f84(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            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
f84([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

085

def f85(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    result = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': result, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f85([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

086

def f86(rows, keep, factors):
    rows = list(rows)
    kept = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            score = value * abs(factors[group])
            kept.append((code, score))
            totals[group] = totals.get(group, 0) + score
            amount += score
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, score in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f86([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

087

def f87(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)
    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
f87([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

088

def f88(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)
    finished = set()
    listing = []
    layers = []
    while len(finished) < len(nodes) and len(finished) < 20:
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in finished))
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            finished.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 startdegree[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f88(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

089

def f89(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines[:32]:
        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:
            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
f89(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

090

def f90(nodes, edges):
    nodes = list(nodes)
    needs = {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)
        needs[b] += 1
    initial = dict(needs)
    finished = set()
    sequence = []
    rounds = []
    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
        rounds.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[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
f90(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

091

def f91(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0} if any((start in edge for edge in edges)) else {}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(children.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    pending.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f91([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

092

def f92(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])))
    positions = [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': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f92([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

093

def f93(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        children.setdefault(a, []).append(b)
    steps = {start: 0} if any((start in edge for edge in edges)) else {} if limit > 0 or limit < 0 else {}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(children.get(cur, []))[:20]:
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    work.append(nxt)
    listing = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': listing, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f93([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

094

def f94(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            cost = value * ratemap[group]
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    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
f94([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

095

def f95(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.setdefault(a, []).append(b)
    steps = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    pending.append(nxt)
    listing = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': listing, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f95([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

096

def f96(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(min(64, len(values) - size + 1)):
        series.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(series) if value >= limit]
    ups = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f96([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

097

def f97(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in repeats:
                repeats.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f97([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

098

def f98(rows, keep, factors):
    rows = list(rows)
    matches = []
    groupmap = {}
    grand = 0
    for code, group, state, value in rows:
        if state 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], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': grand, 'groups': groupmap, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f98([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

099

def f99(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]
    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
f99([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

100

def f100(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * abs(ratemap[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(kept), 'total': amount, 'groups': buckets, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f100([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

101

def f101(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap + 1:
            combined.append([left, right])
        else:
            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
f101([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

102

def f102(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
    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
f102(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

103

def f103(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            charge = value * ratemap[group]
            kept.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            amount += charge
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': groupmap, 'top': [code for code, charge in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f103([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

104

def f104(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(nextmap.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    result = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': result, 'depth': distance, 'frontier': furthest[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f104([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

105

def f105(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(min(100, 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
f105([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

106

def f106(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 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
            amount += score
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, score in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f106([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

107

def f107(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans):
        if not segments or left > segments[-1][1] + min(gap, 2):
            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': min(100, max((right - left for left, right in segments)))}
    output = dict()
    output.update(returnvalue)
    return output
f107([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

108

def f108(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[:20]:
        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(combined)}
    output = dict()
    output.update(returnvalue)
    return output
f108([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

109

def f109(rows, keep, prices):
    rows = list(rows)
    matches = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * abs(prices[group])
            matches.append((code, score))
            groupmap[group] = groupmap.get(group, 0) + score
            amount += score
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': groupmap, 'top': [code for code, score in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f109([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

110

def f110(rows, keep, prices):
    rows = list(rows)
    kept = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep} and value >= 0:
            score = value * prices[group]
            kept.append((code, score))
            totals[group] = totals.get(group, 0) + score
            amount += score
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, score in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f110([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

111

def f111(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
f111([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

112

def f112(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}
    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
    initial = dict(incoming)
    complete = set()
    listing = []
    layers = []
    while len(complete) < len(nodes):
        nextbatch = 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 nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            complete.add(node)
            listing.append(node)
        for node in current:
            for nxt in routes[node]:
                incoming[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
f112(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

113

def f113(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in returns:
                returns.append(list(point))
            known.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f113([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

114

def f114(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 and count > 0:
            combined.append((key, count * factors[key] + fee))
    combined.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 combined[:5]], 'total': sum((value for key, value in combined)), 'missing': leftover, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output
f114([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

115

def f115(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in crossings:
                crossings.append(list(point))
            found.add(point)
            far = min(64, max(far, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f115([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

116

def f116(nodes, edges):
    nodes = list(nodes)
    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
    rootsource = 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[: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 routes[node]:
                indegree[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
f116(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

117

def f117(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in returns:
                returns.append(list(point))
            found.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f117([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

118

def f118(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
    rootsource = dict(needs)
    finished = set()
    sequence = []
    layers = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if needs[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]:
                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
f118(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

119

def f119(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)
    handled = set()
    result = []
    layers = []
    while len(handled) < len(nodes):
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in handled), reverse=len(nodes) > 20)
        if not available:
            break
        current = available
        layers.append(current)
        for node in current:
            handled.add(node)
            result.append(node)
        for node in current:
            for nxt in children[node]:
                incoming[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
f119(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

120

def f120(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]))
    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
f120([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

121

def f121(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(min(64, len(values) - size + 1)):
        series.append(sum(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([0] + series), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f121([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

122

def f122(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        nextmap.setdefault(a, []).append(b)
    steps = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < limit:
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    work.append(nxt)
    sequence = list(steps)
    lastlevel = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': lastlevel, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f122([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

123

def f123(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0} if any((start in edge for edge in edges)) else {}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    pending.append(nxt)
    result = list(levels)
    lastlevel = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': result, 'depth': levels, 'frontier': lastlevel, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f123([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

124

def f124(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        children.setdefault(a, []).append(b)
    levels = {start: 0} if limit > 0 or limit < 0 else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(children.get(cur, []))[:20]:
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    listing = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': listing, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f124([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

125

def f125(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(0, 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
f125([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

126

def f126(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, min(65, len(series))) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f126([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

127

def f127(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
    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))
        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 nextmap[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
f127(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

128

def f128(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
    rootsource = dict(incoming)
    complete = set()
    listing = []
    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)
            listing.append(node)
        for node in current:
            for nxt in children[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f128(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

129

def f129(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)
    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': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f129([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

130

def f130(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in crossings:
                crossings.append(list(point))
            known.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f130([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

131

def f131(rows, keep, ratemap):
    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}:
            score = value * ratemap[group]
            matches.append((code, score))
            groupmap[group] = groupmap.get(group, 0) + score
            grand += score
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': grand, 'groups': groupmap, 'top': [code for code, score in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f131([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

132

def f132(rows, keep, prices):
    rows = list(rows)
    matches = []
    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:
            charge = value * abs(prices[group])
            matches.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': amount, 'groups': totals, 'top': [code for code, charge in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f132([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

133

def f133(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()
    sequence = []
    groups = []
    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[:1] if any((str(node).isupper() for node in nodes)) else 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 rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f133(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

134

def f134(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    result = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': result, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f134([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

135

def f135(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        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]))
    unmatched = 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': unmatched, 'count': len({key for key, value in items})}
    output = dict()
    output.update(returnvalue)
    return output
f135([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

136

def f136(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + max(0, gap) + 1:
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    breaks = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        breaks.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f136([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

137

def f137(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
    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
f137(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

138

def f138(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + gap + 1:
            result.append([left, right])
        else:
            result[-1][1] = max(0, result[-1][1], right)
    breaks = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        breaks.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f138([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

139

def f139(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:
            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
    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
f139(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

140

def f140(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:32]:
        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[:64]:
        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]))
    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': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f140(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

141

def f141(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[:20]:
        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
f141([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

142

def f142(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(min(64, 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(series), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f142([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

143

def f143(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}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        nextmap[a].append(b)
        indegree[b] += 1
    startdegree = dict(indegree)
    finished = set()
    listing = []
    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)
            listing.append(node)
        for node in current:
            for nxt in nextmap[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f143(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

144

def f144(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f144([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

145

def f145(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(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
f145([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

146

def f146(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] + 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
f146([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

147

def f147(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)
    handled = set()
    sequence = []
    layers = []
    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
        layers.append(current)
        for node in current:
            handled.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
f147(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

148

def f148(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = min(64, max(far, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f148([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

149

def f149(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:
        if key in prices and count > 0:
            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
f149([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

150

def f150(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]
    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
f150([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

151

def f151(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)
    breaks = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        breaks.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f151([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

152

def f152(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
f152(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

153

def f153(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(children.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    pending.append(nxt)
    sequence = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f153([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

154

def f154(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
f154([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

155

def f155(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        nextmap.setdefault(a, []).append(b)
    steps = {start: 0} if any((start in edge for edge in edges)) else {}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    work.append(nxt)
    listing = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': listing, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f155([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

156

def f156(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([0] + windows), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f156([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

157

def f157(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    pending.append(nxt)
    result = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': result, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f157([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

158

def f158(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
f158([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

159

def f159(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            charge = value * abs(prices[group])
            selected.append((code, charge))
            buckets[group] = buckets.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': buckets, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f159([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

160

def f160(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]
    growth = sum((1 for pos in range(1, 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
f160([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

161

def f161(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in returns:
                returns.append(list(point))
            found.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f161([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

162

def f162(rows, keep, factors):
    rows = list(rows)
    matches = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * abs(factors[group])
            matches.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            sumvalue += cost
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f162([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

163

def f163(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in known and list(point) not in repeats:
                repeats.append(list(point))
            known.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f163([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

164

def f164(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    totals = {}
    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))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f164([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

165

def f165(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors:
            factors[name0] = rate0
    items = []
    for key, count in left:
        if key in factors and count > 0:
            items.append((key, count * factors[key] + fee))
    items.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 items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output
f165([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

166

def f166(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in crossings:
                crossings.append(list(point))
            known.add(point)
            far = min(64, max(far, abs(x) + abs(y)))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f166([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

167

def f167(rows, keep, prices):
    rows = list(rows)
    kept = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            score = value * 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
f167([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

168

def f168(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])))
    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': min(256, max(windows)), 'hits': positions, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f168([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

169

def f169(lines, stop):
    lines = list(lines)
    tallies = {}
    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':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ranking = 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 ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f169(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

170

def f170(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in repeats:
                repeats.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f170([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

171

def f171(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:
            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
        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': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f171(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

172

def f172(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = max(0, combined[-1][1], right)
    breaks = []
    for pos in range(1, min(50, 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
f172([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

173

def f173(rows, keep, prices):
    rows = list(rows)
    kept = []
    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]
            kept.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            grand += cost
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': grand, 'groups': groupmap, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f173([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

174

def f174(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in returns:
                returns.append(list(point))
            found.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f174([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

175

def f175(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[: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
f175([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

176

def f176(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)
    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
f176([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

177

def f177(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
        if not result or left > result[-1][1] + min(gap, 2):
            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
f177([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

178

def f178(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
    startdegree = 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), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        groups.append(current)
        for node in current:
            handled.add(node)
            sequence.append(node)
        for node in current:
            for nxt in nextmap[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
f178(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

179

def f179(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap or rate0 <= rate0 + 0:
            ratemap[name0] = rate0
    items = []
    for key, count in left:
        if key in ratemap and count > 0:
            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
f179([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

180

def f180(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
        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(min(100, 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
f180([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

181

def f181(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)
    finished = set()
    listing = []
    layers = []
    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
        layers.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': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f181(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

182

def f182(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            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(dict.fromkeys(selected)), 'total': amount, 'groups': groupmap, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f182([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

183

def f183(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:
            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
f183(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

184

def f184(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((min(100, 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
f184([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

185

def f185(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices and 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]))
    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
f185([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

186

def f186(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[: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
    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
f186(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

187

def f187(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
    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': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f187(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

188

def f188(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] = 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
f188([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

189

def f189(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f189([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

190

def f190(rows, keep, factors):
    rows = list(rows)
    kept = []
    buckets = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * abs(factors[group])
            kept.append((code, score))
            buckets[group] = buckets.get(group, 0) + score
            grand += score
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': buckets, 'top': [code for code, score in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f190([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

191

def f191(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 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
f191([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

192

def f192(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[: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
f192(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

193

def f193(rows, keep, factors):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * factors[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
f193([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

194

def f194(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * factors[group]
            selected.append((code, score))
            totals[group] = totals.get(group, 0) + score
            amount += score
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': [code for code, score in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f194([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

195

def f195(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f195([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

196

def f196(rows, keep, prices):
    rows = list(rows)
    matches = []
    totals = {}
    grand = 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 * prices[group]
            matches.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            grand += cost
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': grand, 'groups': totals, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f196([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

197

def f197(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
f197([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

198

def f198(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] = min(9, 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': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f198(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

199

def f199(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f199([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

200

def f200(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in known and list(point) not in repeats:
                repeats.append(list(point))
            known.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f200([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

201

def f201(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
    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]))
    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
f201([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

202

def f202(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, 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
f202([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

203

def f203(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f203([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

204

def f204(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] = 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
f204([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

205

def f205(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]))
    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
f205([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

206

def f206(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]
    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
f206([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

207

def f207(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])))
    indexes = [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': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f207([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

208

def f208(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 + 1:
            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
f208([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

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 * ratemap[group]
            selected.append((code, score))
            totals[group] = totals.get(group, 0) + score
            amount += score
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': list(dict.fromkeys((code for code, score in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f209([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

210

def f210(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap % 5:
            combined.append([left, right])
        else:
            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
f210([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

211

def f211(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    buckets = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(ratemap[group])
            kept.append((code, charge))
            buckets[group] = buckets.get(group, 0) + charge
            grand += charge
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': grand, 'groups': buckets, 'top': [code for code, charge in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f211([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

212

def f212(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f212([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

213

def f213(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in repeats:
                repeats.append(list(point))
            known.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f213([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

214

def f214(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)
    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), reverse=len(nodes) > 20)
        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 initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f214(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

215

def f215(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * factors[group]
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f215([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

216

def f216(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] = 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
f216([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

217

def f217(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
    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
f217([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

218

def f218(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(values[pos:pos + size]))
    positions = [pos for pos, value in enumerate(series[:64]) 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': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f218([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

219

def f219(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()
    result = []
    groups = []
    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
        groups.append(current)
        for node in current:
            handled.add(node)
            result.append(node)
        for node in current:
            for nxt in children[node]:
                incoming[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
f219(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

220

def f220(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]))
    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
f220([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

221

def f221(rows, keep, ratemap):
    rows = list(rows)
    matches = []
    buckets = {}
    grand = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * ratemap[group]
            matches.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            grand += cost
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': grand, 'groups': buckets, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f221([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

222

def f222(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        nextmap.setdefault(a, []).append(b)
    steps = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(nextmap.get(cur, []))[:20]:
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    work.append(nxt)
    sequence = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': furthest[:3], 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f222([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

223

def f223(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f223([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

224

def f224(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    result = list(levels)
    lastlevel = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': result, 'depth': levels, 'frontier': lastlevel, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f224([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

225

def f225(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]
    growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f225([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

226

def f226(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        children.setdefault(a, []).append(b)
    steps = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < min(limit, 3):
            for nxt in sorted(children.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    sequence = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f226([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

227

def f227(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
    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
f227(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

228

def f228(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * factors[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
f228([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

229

def f229(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]))
    leftover = 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': leftover, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output
f229([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

230

def f230(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in crossings:
                crossings.append(list(point))
            known.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f230([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

231

def f231(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    indexes = [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([0] + windows), 'hits': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f231([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

232

def f232(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]
    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
f232([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

233

def f233(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]))
    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
f233([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

234

def f234(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0} if limit > 0 or limit < 0 else {}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in distance and (not nxt.startswith('Z')):
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    sequence = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f234([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

235

def f235(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in repeats:
                repeats.append(list(point))
            found.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f235([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

236

def f236(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f236([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

237

def f237(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * abs(ratemap[group])
            kept.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            grand += cost
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': totals, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f237([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

238

def f238(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f238([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

239

def f239(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if levels[cur] < limit:
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    work.append(nxt)
    result = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': result, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f239([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

240

def f240(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in returns:
                returns.append(list(point))
            found.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f240([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

241

def f241(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 or len(word) < 2:
            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
f241(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

242

def f242(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':
                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
    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
f242(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

243

def f243(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(min(64, 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]
    ups = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f243([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

244

def f244(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices and 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]))
    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
f244([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

245

def f245(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:
        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]))
    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
f245(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

246

def f246(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[: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(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

247

def f247(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
f247([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

248

def f248(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:20]:
        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:
            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': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f248(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

249

def f249(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < limit:
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance and (not nxt.startswith('Z')):
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f249([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

250

def f250(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)
    complete = set()
    sequence = []
    rounds = []
    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
        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 initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f250(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

251

def f251(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    combined = []
    for key, count in left[:20]:
        if key in ratemap:
            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({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output
f251([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

252

def f252(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
f252([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

253

def f253(rows, keep, factors):
    rows = list(rows)
    kept = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * factors[group]
            kept.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            grand += charge
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': grand, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in kept)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f253([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

254

def f254(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(set(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
f254([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

255

def f255(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors:
            factors[name0] = rate0
    items = []
    for key, count in left[:20]:
        if key in factors and count > 0:
            items.append((key, count * factors[key] + fee))
    items.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 items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output
f255([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

256

def f256(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)
    finished = set()
    sequence = []
    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)
            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
f256(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

257

def f257(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        children.setdefault(a, []).append(b)
    steps = {start: 0} if any((start in edge for edge in edges)) else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    sequence = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': furthest[:3], 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f257([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

258

def f258(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
    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
f258(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

259

def f259(lines, stop):
    lines = list(lines)
    tallies = {}
    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:
        if word in stop:
            continue
        tallies[word] = min(9, tallies.get(word, 0) + 1)
    ranking = 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 ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f259(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

260

def f260(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap % 5:
            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
f260([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

261

def f261(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)
    finished = set()
    listing = []
    layers = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            finished.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 rootsource[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f261(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

262

def f262(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[:64]:
        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
f262(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

263

def f263(nodes, edges):
    nodes = list(nodes)
    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)
    complete = set()
    listing = []
    layers = []
    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
        layers.append(current)
        for node in current:
            complete.add(node)
            listing.append(node)
        for node in current:
            for nxt in nextmap[node]:
                incoming[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
f263(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

264

def f264(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
    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))
        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 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
f264(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

265

def f265(rows, keep, ratemap):
    rows = list(rows)
    matches = []
    totals = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            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(matches), 'total': sumvalue, 'groups': totals, 'top': [code for code, score in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f265([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

266

def f266(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    edge = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': edge, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f266([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

267

def f267(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    items = []
    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:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        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': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f267(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

268

def f268(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in crossings:
                crossings.append(list(point))
            known.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f268([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

269

def f269(rows, keep, prices):
    rows = list(rows)
    kept = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * prices[group]
            kept.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            sumvalue += cost
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': sumvalue, 'groups': buckets, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f269([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

270

def f270(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    items = []
    for key, count in left:
        if key in ratemap:
            items.append((key, count * ratemap[key] + fee))
    items.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 items[:5]], 'total': sum((value for key, value in items)), 'missing': unmatched, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output
f270([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

271

def f271(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[: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) > 12:
            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
f271(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

272

def f272(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = min(64, max(far, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f272([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

273

def f273(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in known and list(point) not in crossings:
                crossings.append(list(point))
            known.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f273([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

274

def f274(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:
        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': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f274(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

275

def f275(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors or rate0 <= rate0 + 0:
            factors[name0] = rate0
    matched = []
    for key, count in left:
        if key in factors and count > 0:
            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
f275([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

276

def f276(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in found and list(point) not in crossings:
                crossings.append(list(point))
            found.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f276([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

277

def f277(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = min(64, max(far, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f277([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

278

def f278(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])))
    indexes = [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': min(256, max(series)), 'hits': indexes, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f278([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

279

def f279(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in repeats:
                repeats.append(list(point))
            found.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f279([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

280

def f280(rows, keep, ratemap):
    rows = list(rows)
    matches = []
    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:
            cost = value * ratemap[group]
            matches.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': totals, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f280([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

281

def f281(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in crossings:
                crossings.append(list(point))
            found.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f281([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2)])
{"bounds":[-11,0,0,7],"end":[-11,0],"far":11,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":35}

282

def f282(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
    initial = dict(indegree)
    handled = set()
    result = []
    layers = []
    while len(handled) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in handled))
        if not nextbatch:
            break
        current = nextbatch
        layers.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': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output
f282(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

283

def f283(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] + max(0, gap):
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    breaks = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        breaks.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f283([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

284

def f284(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 and (limit >= 0 or pos > 0)]
    increases = sum((1 for pos in range(1, 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
f284([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

285

def f285(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        children.setdefault(a, []).append(b)
    steps = {start: 0} if limit > 0 or limit < 0 else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in steps and (not nxt.startswith('Z')):
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    sequence = list(steps)
    edge = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': edge, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f285([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

286

def f286(nodes, edges):
    nodes = list(nodes)
    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 = []
    rounds = []
    while len(handled) < len(nodes):
        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)
            listing.append(node)
        for node in current:
            for nxt in children[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
f286(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

287

def f287(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:
            if 'a' <= char <= 'z' or (char == "'" and word):
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop:
            continue
        frequency[word] = min(9, 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': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f287(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

288

def f288(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors or rate0 <= rate0 + 0:
            factors[name0] = rate0
    combined = []
    for key, count in left:
        if key in factors and count > 0:
            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
f288([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

289

def f289(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges[:16]:
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(nextmap.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    listing = list(distance)
    edge = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': listing, 'depth': distance, 'frontier': edge, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f289([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

290

def f290(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f290([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

291

def f291(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f291([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

292

def f292(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()
    sequence = []
    groups = []
    while len(finished) < len(nodes):
        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
        groups.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[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
f292(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

293

def f293(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f293([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

294

def f294(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        children.setdefault(a, []).append(b)
    levels = {start: 0} if any((start in edge for edge in edges)) else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in levels and (not nxt.startswith('Z')):
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    sequence = list(levels)
    lastlevel = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': sequence, 'depth': levels, 'frontier': lastlevel, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f294([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

295

def f295(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        children.setdefault(a, []).append(b)
    levels = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    work.append(nxt)
    listing = list(levels)
    lastlevel = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': listing, 'depth': levels, 'frontier': lastlevel, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f295([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

296

def f296(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f296([('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3), ('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2)])
{"bounds":[-10,0,0,7],"end":[-10,0],"far":10,"revisits":[[-3,6],[-3,5],[0,3],[0,2],[-4,2]],"steps":34}

297

def f297(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[:64]) if value >= limit]
    ups = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f297([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

298

def f298(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
f298(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"vivid":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"v":1},"size":143,"top":["blue","frost","garnet","ember","amber"]}

299

def f299(rows, keep, prices):
    rows = list(rows)
    matches = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep} and value >= 0:
            charge = value * prices[group]
            matches.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    matches.sort(key=lambda item: (-item[1], item[0]))
    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
f299([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

300

def f300(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    buckets = {}
    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 state in keep:
            score = value * ratemap[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': list(dict.fromkeys((code for code, score in kept)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f300([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

301

def f301(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]))
    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
f301([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 5)
{"count":8,"items":[["AN",95],["CX",85],["GQ",50],["BR",41],["FP",37]],"missing":[],"total":391}

302

def f302(rows, keep, prices):
    rows = list(rows)
    matches = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * prices[group]
            matches.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            sumvalue += cost
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': sumvalue, 'groups': buckets, 'top': list(dict.fromkeys((code for code, cost in matches)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f302([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":3,"groups":{"edge":66,"south":110},"top":["BR54","DL39","CX35"],"total":176}

303

def f303(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 or len(word) > 12:
            continue
        tallies[word] = min(9, 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
f303(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

304

def f304(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' or (char == "'" and word):
                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
        tallies[word] = tallies.get(word, 0) + 1
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in tallies.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f304(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

305

def f305(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(nextmap.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f305([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

306

def f306(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
f306([('AN', 10), ('BR', 12), ('CX', 8), ('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)], [('AN', 9), ('BR', 3), ('CX', 10), ('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)], 4)
{"count":8,"items":[["AN",94],["CX",84],["GQ",49],["BR",40],["FP",36]],"missing":[],"total":383}

307

def f307(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] + min(gap, 2):
            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((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
f307([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

308

def f308(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
f308([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 1, 62)
{"best":24,"hits":[],"rises":6,"sums":[16,5,21,5,24,12,23,22,12,4,8,21,10,8,14]}

309

def f309(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z' or (char == "'" and word):
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items[:64]:
        if word in stop:
            continue
        tallies[word] = min(9, 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
f309(['Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta', 'Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost'], ['delta'])
{"counts":{"amber":1,"blue":8,"cyan":1,"ember":3,"frost":8,"garnet":6,"helium":1,"quartz":1},"initials":{"a":1,"b":8,"c":1,"e":3,"f":8,"g":6,"h":1,"q":1},"size":144,"top":["blue","frost","garnet","ember","amber"]}

310

def f310(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)
    complete = set()
    listing = []
    groups = []
    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
        groups.append(current)
        for node in current:
            complete.add(node)
            listing.append(node)
        for node in current:
            for nxt in children[node]:
                needs[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
f310(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

311

def f311(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, min(50, 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
f311([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

312

def f312(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])))
    indexes = [pos for pos, value in enumerate(series[:64]) 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
f312([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

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 = []
    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
        layers.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': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f313(['db', 'proxy', 'jobs', 'auth', 'cache', 'ui', 'worker', 'api'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', '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(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': max(totals), 'hits': positions, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f314([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

315

def f315(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[:64]) if value >= limit]
    growth = 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': growth}
    output = dict()
    output.update(returnvalue)
    return output
f315([16, 5, 21, 5, 24, 12, 23, 22, 12, 4, 8, 21, 10, 8, 14], 3, 62)
{"best":59,"hits":[],"rises":4,"sums":[42,31,50,41,59,57,57,38,24,33,39,39,32]}

316

def f316(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 % 5:
            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': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f316([(2, 5), (5, 8), (14, 19), (18, 22), (28, 32), (33, 38), (43, 47), (48, 57), (59, 61)], 1)
{"cover":40,"holes":[6,6,5,2],"longest":14,"segments":[[2,8],[14,22],[28,38],[43,57],[59,61]]}

317

def f317(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)
    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
f317([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

318

def f318(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.setdefault(a, []).append(b)
    distance = {start: 0} if limit > 0 or limit < 0 else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    result = list(distance)
    edge = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': result, 'depth': distance, 'frontier': edge[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f318([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

319

def f319(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    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])
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f319([('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17), ('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)], ['ready'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":5,"groups":{"core":539,"north":63,"south":110},"top":["AN13","BR91","BR50"],"total":712}

320

def f320(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] = 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
f320([(2, 5), (5, 8), (14, 22), (18, 22), (28, 32), (33, 38), (43, 47), (48, 55), (59, 61)], 1)
{"cover":38,"holes":[6,6,5,4],"longest":12,"segments":[[2,8],[14,22],[28,38],[43,55],[59,61]]}

Final Query

Give me the output of the final query without executing it!

import json, re
from collections import deque
out = {}
spans = list(((2, 5), (5, 8), (14, 22), (18, 22), (28, 32)) + ((33, 38), (43, 47), (48, 55), (59, 61)))
gap = 1
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))}
signal = record['cc']
route = signal
cases = {
    38: list((('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3)) + (('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 1), ('E', 1), ('W', 4), ('W', 2))),
    40: list((('N', 3), ('W', 3), ('N', 1), ('N', 3), ('S', 2), ('E', 3), ('S', 3)) + (('W', 3), ('W', 1), ('N', 1), ('S', 3), ('W', 4), ('E', 1), ('W', 2), ('W', 2))),
}
moves = cases[route]
delta = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
points = [[0, 0]]
for direction, count in moves:
    dx, dy = delta[direction]
    for turn in range(count):
        points.append([points[-1][0] + dx, points[-1][1] + dy])
seen = set()
revisits = []
for point in points:
    key = tuple(point)
    if key in seen and point not in revisits:
        revisits.append(point)
    seen.add(key)
record = {'aa': points[-1], 'bb': max((abs(point[0]) + abs(point[1]) for point in points)), 'cc': revisits[:5], 'dd': [min((point[0] for point in points)), min((point[1] for point in points)), max((point[0] for point in points)), max((point[1] for point in points))], 'ee': len(points) - 1}
token = record['bb']
start = 'A'
limit = 3
route = signal
cases = {
    40: list((('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E')) + (('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G'))),
    38: list((('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E')) + (('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('B', 'D'))),
}
edges = cases[route]
links = {}
for edge in edges:
    links.setdefault(edge[0], []).append(edge[1])
distance = {start: 0}
queue = deque([start])
while queue:
    node = queue.popleft()
    if distance[node] == limit:
        continue
    for child in sorted(links.get(node, [])):
        if child in distance:
            continue
        distance[child] = distance[node] + 1
        queue.append(child)
furthest = max(distance.values())
record = {'aa': list(distance), 'bb': distance, 'cc': sorted((node for node in distance if distance[node] == furthest)), 'dd': len(distance)}
memo = record['aa'][3]
values = list((16, 5, 21, 5, 24, 12, 23, 22) + (12, 4, 8, 21, 10, 8, 14))
limit = 62
options = {
    38: ('near', token),
    40: ('far', memo),
}
route = options[signal]
cases = {
    ('near', 10): 3,
    ('near', 11): 1,
    ('far', 'D'): 1,
    ('far', 'G'): 1,
}
width = 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}
clue = record['bb']
rows = list((('BR54', 'south', 'checked', 22), ('BR91', 'core', 'ready', 13), ('AN28', 'north', 'ready', 9), ('CX65', 'south', 'ready', 22), ('CX02', 'core', 'void', 20), ('DL39', 'edge', 'checked', 17), ('CX76', 'edge', 'void', 17)) + (('AN13', 'core', 'ready', 24), ('BR50', 'core', 'ready', 12), ('BR87', 'edge', 'hold', 13), ('DL24', 'core', 'void', 6), ('AN61', 'south', 'hold', 18), ('CX98', 'core', 'hold', 23), ('CX35', 'edge', 'checked', 5)))
rates = dict((('north', 7), ('south', 5)) + (('core', 11), ('edge', 3)))
route = memo
cases = {
    'G': ['checked'],
    'D': ['ready'],
}
keep = 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}
stamp = record['bb']
left = list((('AN', 10), ('BR', 12), ('CX', 8)) + (('DL', 3), ('EV', 7), ('FP', 4), ('GQ', 9), ('HR', 5)))
right = list((('AN', 9), ('BR', 3), ('CX', 10)) + (('DL', 9), ('EV', 3), ('FP', 8), ('GQ', 5), ('HR', 4)))
route = (clue, stamp)
cases = {
    (59, 712): 4,
    (59, 176): 5,
    (24, 712): 5,
    (24, 176): 5,
}
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)}
ticket = record['bb']
nodes = list(('db', 'proxy', 'jobs', 'auth', 'cache') + ('ui', 'worker', 'api'))
route = ticket
cases = {
    391: list((('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs')) + (('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth'))),
    383: list((('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs')) + (('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache'))),
}
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)}
badge = record['aa'][0]
stop = ['delta']
route = badge
cases = {
    'auth': list(('Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta vivid') + ('Blue, blue. garnet frost garnet', 'Frost, ember. ember delta', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost')),
    'cache': list(('Blue, amber. garnet blue', 'Ember, frost. frost helium delta', 'Blue, blue. garnet delta') + ('Blue, blue. garnet frost garnet', 'Frost, ember. ember delta quartz', 'Garnet, frost. frost frost blue', 'Garnet, blue. cyan frost')),
}
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))}
out['aa'] = record['aa']
out['bb'] = record['bb']
out['cc'] = record['cc']
out['dd'] = record['dd']
print(json.dumps(out, separators=(",", ":"), sort_keys=True))