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

001

def f1(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) 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': max([0] + series), 'hits': positions, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f1([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

002

def f2(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges[:16]:
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    pending.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[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f2([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

003

def f3(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        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)
    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
f3([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

004

def f4(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(totals) 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': indexes, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f4([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

005

def f5(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        nextmap.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] < min(limit, 3):
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    work.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
f5([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

006

def f6(rows, keep, factors):
    rows = list(rows)
    kept = []
    groupmap = {}
    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:
            cost = value * factors[group]
            kept.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            grand += cost
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': groupmap, 'top': list(dict.fromkeys((code for code, cost in kept)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f6([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

007

def f7(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]
    growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': positions, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f7([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

008

def f8(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(count):
            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
f8([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

009

def f9(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            pending = [(row, col)]
            visited.add((row, col))
            while pending:
                cur = pending.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        pending.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f9(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

010

def f10(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    items = []
    for key, count in left:
        if key in prices:
            items.append((key, count * prices[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len({key for key, value in items})}
    output = dict()
    output.update(returnvalue)
    return output
f10([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

011

def f11(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            pending = [(row, col)]
            visited.add((row, col))
            while pending:
                cur = pending.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        if len(visited) >= 100:
                            continue
                        pending.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f11(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

012

def f12(rows, keep, factors):
    rows = list(rows)
    kept = []
    groupmap = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            cost = value * factors[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(kept), 'total': grand, 'groups': groupmap, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f12([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

013

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

014

def f14(rows, keep, factors):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            score = value * factors[group]
            selected.append((code, score))
            groupmap[group] = groupmap.get(group, 0) + score
            amount += score
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': groupmap, 'top': [code for code, score in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f14([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

015

def f15(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([0] + windows), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f15([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

016

def f16(left, right, banned):
    left = list(left)

    def tidy(value):
        return str(value).strip(' \n').upper()
    banned = {tidy(value) for value in banned}
    a = {tidy(value) for value in left} - banned
    b = {tidy(value) for value in right} - banned
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f16(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

017

def f17(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(prices[group])
            selected.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            grand += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': grand, 'groups': groupmap, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f17([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

018

def f18(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * ratemap[group]
            kept.append((code, score))
            totals[group] = totals.get(group, 0) + score
            grand += score
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': totals, 'top': [code for code, score in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f18([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

019

def f19(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices or rate0 <= rate0 + 0:
            prices[name0] = rate0
    matched = []
    for key, count in left:
        if key in prices and count > 0:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    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
f19([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

020

def f20(left, right, excluded):
    left = list(left)

    def canon(value):
        return str(value).strip().upper()
    excluded = {canon(value) for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f20(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

021

def f21(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(series[: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': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f21([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

022

def f22(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}:
            charge = value * abs(prices[group])
            kept.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            grand += charge
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': groupmap, 'top': [code for code, charge in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f22([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

023

def f23(board):
    board = list(board)
    known = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            work = [(row, col)]
            known.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        work.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f23(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

024

def f24(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()
    sequence = []
    layers = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
        if not nextbatch:
            break
        current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        layers.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f24(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

025

def f25(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[:20]:
        dx, dy = step[direction]
        for turn in range(count % 100):
            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 = (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
f25([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

026

def f26(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(routes.get(cur, [])):
                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
f26([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

027

def f27(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[: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 repeats:
                repeats.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': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f27([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

028

def f28(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        routes[a].append(b)
        incoming[b] += 1
    initial = dict(incoming)
    handled = set()
    result = []
    rounds = []
    while len(handled) < len(nodes) 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
        rounds.append(current)
        for node in current:
            handled.add(node)
            result.append(node)
        for node in current:
            for nxt in routes[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output
f28(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

029

def f29(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap and rate0 != 0:
            ratemap[name0] = rate0
    items = []
    for key, count in left[:20]:
        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(items)}
    output = dict()
    output.update(returnvalue)
    return output
f29([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

030

def f30(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            score = value * prices[group]
            selected.append((code, score))
            groupmap[group] = groupmap.get(group, 0) + score
            sumvalue += score
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, score in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f30([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

031

def f31(left, right, ignored):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \r').upper()
    ignored = {normalize(value) for value in ignored}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - ignored
    b = {normalize(value) for value in right} - ignored
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f31(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

032

def f32(board):
    board = list(board)
    found = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            queue = [(row, col)]
            found.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        if len(found) >= 100:
                            continue
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f32(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

033

def f33(left, right, banned):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \n').upper()
    banned = {normalize(value) for value in banned}
    a = {normalize(value) for value in left} - banned
    b = {normalize(value) for value in right} - banned
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f33(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

034

def f34(left, right, ignored):
    left = list(left)

    def normalize(value):
        return str(value).strip().upper()
    ignored = {str(value).strip() for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right} - ignored
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f34(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

035

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

036

def f36(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] < limit:
            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)
    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
f36([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

037

def f37(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges[:16]:
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.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
                    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[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f37([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

038

def f38(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        routes[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    finished = set()
    sequence = []
    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)
            sequence.append(node)
        for node in current:
            for nxt in routes[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
f38(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

039

def f39(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap and 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]))
    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
f39([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

040

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

041

def f41(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    positions = [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': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f41([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

042

def f42(board):
    board = list(board)
    visited = set()
    pieces = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            queue = [(row, col)]
            visited.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        if len(visited) >= 100:
                            continue
                        queue.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f42(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

043

def f43(left, right, excluded):
    left = list(left)

    def canon(value):
        return str(value).strip(' \r').upper()
    excluded = {canon(value) for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right if canon(value) != ''} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f43(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

044

def f44(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]))
    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
f44([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

045

def f45(board):
    board = list(board)
    found = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            work = [(row, col)]
            found.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        work.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f45(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

046

def f46(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[: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 repeats:
                repeats.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': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f46([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

047

def f47(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)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.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
f47([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

048

def f48(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip(' ').upper()
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
    b = {normalize(value) for value in right if normalize(value) != ''} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f48(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

049

def f49(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}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    pending.append(nxt)
    sequence = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': sequence, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f49([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

050

def f50(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * ratemap[group]
            kept.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            grand += charge
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': grand, 'groups': totals, 'top': [code for code, charge in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f50([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

051

def f51(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices or rate0 <= rate0 + 0:
            prices[name0] = rate0
    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
f51([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

052

def f52(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}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    pending.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
f52([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

053

def f53(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value >= limit]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f53([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

054

def f54(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
    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': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f54([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

055

def f55(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)
    steps = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    work.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[:3], 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f55([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

056

def f56(left, right, ignored):
    left = list(left)

    def normalize(value):
        return str(value).strip(' ').upper()
    ignored = {normalize(value) for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right} - ignored
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f56(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

057

def f57(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(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
f57([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

058

def f58(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            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], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f58([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

059

def f59(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 = max(-64, min(64, 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
f59([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

060

def f60(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, 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
f60([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

061

def f61(rows, keep, factors):
    rows = list(rows)
    matches = []
    totals = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * factors[group]
            matches.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            sumvalue += cost
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f61([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

062

def f62(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \n').upper()[:12]
    excluded = {str(value).strip() for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f62(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

063

def f63(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 = 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, 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
f63([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

064

def f64(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
    rootsource = dict(incoming)
    handled = set()
    sequence = []
    rounds = []
    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), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        rounds.append(current)
        for node in current:
            handled.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                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
f64(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

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((max(item, 0) for item in 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
f65([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

066

def f66(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 = 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 = (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
f66([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

067

def f67(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]
    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
f67([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

068

def f68(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 += 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 = (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
f68([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

069

def f69(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:
        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({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output
f69([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

070

def f70(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        children[a].append(b)
        incoming[b] += 1
    initial = dict(incoming)
    handled = set()
    listing = []
    groups = []
    while len(handled) < len(nodes):
        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[:1] if any((str(node).isupper() for node in nodes)) else available
        groups.append(current)
        for node in current:
            handled.add(node)
            listing.append(node)
        for node in current:
            for nxt in children[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f70(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

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]
    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
f71([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

072

def f72(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * prices[group]
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            sumvalue += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f72([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

073

def f73(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
f73([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

074

def f74(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(windows) if value > limit]
    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
f74([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

075

def f75(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(min(len(board[row]), 10)):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            queue = [(row, col)]
            visited.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f75(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

076

def f76(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.setdefault(a, []).append(b)
    levels = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                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
f76([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

077

def f77(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors:
            factors[name0] = rate0
    combined = []
    for key, count in left[:20]:
        if key in factors:
            combined.append((key, count * factors[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    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(combined)}
    output = dict()
    output.update(returnvalue)
    return output
f77([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

078

def f78(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]))
    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
f78([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

079

def f79(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 * prices[group]
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f79([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

080

def f80(nodes, edges):
    nodes = list(nodes)
    needs = {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)
        needs[b] += 1
    rootsource = 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=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:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in nextmap[node]:
                needs[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f80(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

081

def f81(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(min(64, len(values) - size + 1)):
        totals.append(sum(values[pos:pos + size]))
    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([0] + totals), 'hits': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f81([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

082

def f82(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        nextmap[a].append(b)
        indegree[b] += 1
    startdegree = 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))
        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 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
f82(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

083

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

084

def f84(board):
    board = list(board)
    known = set()
    regions = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            work = [(row, col)]
            known.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        work.append(nxt)
            regions.append((len(cells), min(cells)))
    regions.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
    output = dict()
    output.update(returnvalue)
    return output
f84(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

085

def f85(board):
    board = list(board)
    known = set()
    pieces = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            queue = [(row, col)]
            known.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        if len(known) >= 100:
                            continue
                        queue.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f85(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

086

def f86(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * ratemap[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
f86([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

087

def f87(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges[:16]:
        nextmap.setdefault(a, []).append(b)
    steps = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    pending.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
f87([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

088

def f88(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}
    pending = [start]
    while pending:
        cur = pending.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
                    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
f88([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

089

def f89(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 += 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, 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': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f89([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

090

def f90(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:
            score = value * prices[group]
            matches.append((code, score))
            totals[group] = totals.get(group, 0) + score
            amount += score
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': amount, 'groups': totals, 'top': [code for code, score in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f90([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

091

def f91(board):
    board = list(board)
    known = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            queue = [(row, col)]
            known.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        if len(known) >= 100:
                            continue
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f91(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

092

def f92(rows, keep, prices):
    rows = list(rows)
    matches = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            score = value * abs(prices[group])
            matches.append((code, score))
            buckets[group] = buckets.get(group, 0) + score
            amount += score
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': amount, 'groups': buckets, 'top': [code for code, score in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f92([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

093

def f93(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 += 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
f93([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

094

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

095

def f95(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
f95([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

096

def f96(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(prices[group])
            selected.append((code, charge))
            buckets[group] = buckets.get(group, 0) + charge
            grand += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': buckets, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f96([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

097

def f97(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(series), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f97([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

098

def f98(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
f98([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

099

def f99(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            queue = [(row, col)]
            visited.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        if len(visited) >= 100:
                            continue
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f99(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

100

def f100(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]))
    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({key for key, value in items})}
    output = dict()
    output.update(returnvalue)
    return output
f100([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

101

def f101(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(series) if value >= limit]
    increases = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
    returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f101([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

102

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

103

def f103(left, right, banned):
    left = list(left)

    def tidy(value):
        return str(value).strip(' \r').upper()
    banned = {str(value).upper() for value in banned}
    a = {tidy(value) for value in left} - banned
    b = {tidy(value) for value in right} - banned
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f103(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

104

def f104(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}:
            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(matches), 'total': amount, 'groups': totals, 'top': [code for code, charge in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f104([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

105

def f105(nodes, edges):
    nodes = list(nodes)
    needs = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        children[a].append(b)
        needs[b] += 1
    initial = dict(needs)
    handled = set()
    sequence = []
    groups = []
    while len(handled) < len(nodes):
        available = sorted((node for node in nodes if needs[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
        if not available:
            break
        current = available
        groups.append(current)
        for node in current:
            handled.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                needs[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f105(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

106

def f106(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \n').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f106(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

107

def f107(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[:20]:
        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 repeats:
                repeats.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': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f107([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

108

def f108(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(min(len(board[row]), 10)):
            if board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            pending = [(row, col)]
            visited.add((row, col))
            while pending:
                cur = pending.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        pending.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f108(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

109

def f109(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip(' ').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f109(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

110

def f110(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * 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(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f110([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

111

def f111(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            charge = value * factors[group]
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            grand += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f111([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

112

def f112(board):
    board = list(board)
    known = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(min(len(board[row]), 10)):
            if board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            queue = [(row, col)]
            known.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        if len(known) >= 100:
                            continue
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f112(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

113

def f113(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            queue = [(row, col)]
            visited.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f113(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

114

def f114(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        nextmap[a].append(b)
        indegree[b] += 1
    initial = dict(indegree)
    finished = set()
    listing = []
    layers = []
    while len(finished) < len(nodes) and len(finished) < 20:
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
        if not nextbatch:
            break
        current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        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 initial[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f114(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

115

def f115(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 = 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
f115([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

116

def f116(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip().upper()
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f116(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

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)}
    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, 3 + (count - 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, 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
f117([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

118

def f118(nodes, edges):
    nodes = list(nodes)
    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
    startdegree = dict(indegree)
    complete = set()
    sequence = []
    layers = []
    while len(complete) < len(nodes):
        available = sorted((node for node in nodes if indegree[node] == 0 and node not in complete))
        if not available:
            break
        current = available
        layers.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f118(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

119

def f119(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    matched = []
    for key, count in left:
        if key in ratemap:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted({key for key, count in left if key not in ratemap})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output
f119([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

120

def f120(board):
    board = list(board)
    found = set()
    components = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if col >= 12 or board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            queue = [(row, col)]
            found.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        if len(found) >= 100:
                            continue
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f120(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

121

def f121(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        children[a].append(b)
        indegree[b] += 1
    startdegree = dict(indegree)
    complete = set()
    result = []
    rounds = []
    while len(complete) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
        if not nextbatch:
            break
        current = nextbatch
        rounds.append(current)
        for node in current:
            complete.add(node)
            result.append(node)
        for node in current:
            for nxt in children[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output
f121(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

122

def f122(rows, keep, prices):
    rows = list(rows)
    matches = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * prices[group]
            matches.append((code, score))
            buckets[group] = buckets.get(group, 0) + score
            amount += score
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, score in matches)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f122([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

123

def f123(rows, keep, ratemap):
    rows = list(rows)
    matches = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * ratemap[group]
            matches.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            grand += charge
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': grand, 'groups': totals, 'top': [code for code, charge in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f123([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

124

def f124(board):
    board = list(board)
    found = set()
    regions = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            work = [(row, col)]
            found.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        if len(found) >= 100:
                            continue
                        work.append(nxt)
            regions.append((len(cells), min(cells)))
    regions.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
    output = dict()
    output.update(returnvalue)
    return output
f124(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

125

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

126

def f126(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()
    sequence = []
    rounds = []
    while len(handled) < len(nodes) and len(handled) < 20:
        available = sorted((node for node in nodes if needs[node] == 0 and node not in handled), reverse=len(nodes) > 20)
        if not available:
            break
        current = available[:1] if any((str(node).isupper() for node in nodes)) else available
        rounds.append(current)
        for node in current:
            handled.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                needs[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f126(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

127

def f127(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 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(items)}
    output = dict()
    output.update(returnvalue)
    return output
f127([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

128

def f128(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices or rate0 <= rate0 + 0:
            prices[name0] = rate0
    combined = []
    for key, count in left:
        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
f128([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

129

def f129(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:
            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
f129([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

130

def f130(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            queue = [(row, col)]
            visited.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        if len(visited) >= 100:
                            continue
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f130(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

131

def f131(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, [])):
                if nxt not in distance and (not nxt.startswith('Z')):
                    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
f131([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

132

def f132(board):
    board = list(board)
    known = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            queue = [(row, col)]
            known.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f132(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

133

def f133(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}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < min(limit, 3):
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    work.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
f133([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

134

def f134(left, right, banned):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \r').upper()
    banned = {str(value).upper() for value in banned}
    a = {normalize(value) for value in left} - banned
    b = {normalize(value) for value in right} - banned
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f134(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

135

def f135(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 % 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 = (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
f135([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

136

def f136(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            charge = value * abs(ratemap[group])
            selected.append((code, charge))
            buckets[group] = buckets.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f136([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

137

def f137(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]
    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
f137([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

138

def f138(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, 3 + (count - 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
f138([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

139

def f139(rows, keep, factors):
    rows = list(rows)
    matches = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            score = value * factors[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': list(dict.fromkeys((code for code, score in matches)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f139([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

140

def f140(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)
    steps = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    work.append(nxt)
    listing = list(steps)
    lastlevel = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': listing, 'depth': steps, 'frontier': lastlevel, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f140([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

141

def f141(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 = 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, 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
f141([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

142

def f142(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()
    sequence = []
    groups = []
    while len(complete) < len(nodes):
        available = sorted((node for node in nodes if needs[node] == 0 and node not in complete))
        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:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                needs[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f142(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

143

def f143(board):
    board = list(board)
    known = set()
    pieces = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            queue = [(row, col)]
            known.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        queue.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f143(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

144

def f144(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            work = [(row, col)]
            visited.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        if len(visited) >= 100:
                            continue
                        work.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f144(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

145

def f145(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            score = value * prices[group]
            selected.append((code, score))
            buckets[group] = buckets.get(group, 0) + score
            sumvalue += score
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': buckets, 'top': [code for code, score in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f145([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

146

def f146(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}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            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)
    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
f146([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

147

def f147(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]))
    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
f147([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

148

def f148(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        routes[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    finished = set()
    sequence = []
    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)
            sequence.append(node)
        for node in current:
            for nxt in routes[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
f148(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

149

def f149(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(series) if value >= limit]
    increases = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
    returnvalue = {'sums': series, 'best': max([0] + series), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f149([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

150

def f150(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[: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({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output
f150([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

151

def f151(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 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
f151([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

152

def f152(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges[:16]:
        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, []))[:20]:
                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
f152([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

153

def f153(board):
    board = list(board)
    found = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            work = [(row, col)]
            found.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        work.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f153(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

154

def f154(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
    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
f154([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

155

def f155(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(series) if value >= limit]
    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
f155([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

156

def f156(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(count):
            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 = 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
f156([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

157

def f157(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, len(series)) if series[pos] >= series[pos - 1]))
    returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f157([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

158

def f158(board):
    board = list(board)
    found = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            pending = [(row, col)]
            found.add((row, col))
            while pending:
                cur = pending.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        if len(found) >= 100:
                            continue
                        pending.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f158(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

159

def f159(left, right, excluded):
    left = list(left)

    def tidy(value):
        return str(value).strip(' \n').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f159(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

160

def f160(nodes, edges):
    nodes = list(nodes)
    needs = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        routes[a].append(b)
        needs[b] += 1
    rootsource = dict(needs)
    handled = set()
    result = []
    rounds = []
    while len(handled) < len(nodes):
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in handled), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        rounds.append(current)
        for node in current:
            handled.add(node)
            result.append(node)
        for node in current:
            for nxt in routes[node]:
                needs[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
f160(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

161

def f161(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        children[a].append(b)
        incoming[b] += 1
    initial = dict(incoming)
    finished = set()
    sequence = []
    groups = []
    while len(finished) < len(nodes) and len(finished) < 20:
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f161(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

162

def f162(left, right, ignored):
    left = list(left)

    def tidy(value):
        return ' '.join(str(value).split()).upper()
    ignored = {tidy(value) for value in ignored}
    a = {tidy(value) for value in left} - ignored
    b = {tidy(value) for value in right} - ignored
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f162(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

163

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

164

def f164(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        routes[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    finished = set()
    sequence = []
    layers = []
    while len(finished) < len(nodes) and len(finished) < 20:
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
        if not available:
            break
        current = available
        layers.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f164(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

165

def f165(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output
f165([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

166

def f166(board):
    board = list(board)
    found = set()
    pieces = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if col >= 12 or board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            work = [(row, col)]
            found.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        if len(found) >= 100:
                            continue
                        work.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f166(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

167

def f167(left, right, excluded):
    left = list(left)

    def canon(value):
        return str(value).strip(' \r').upper()
    excluded = {str(value).upper() for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f167(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

168

def f168(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    positions = [pos for pos, value in enumerate(windows) if value > limit]
    ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': positions, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f168([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

169

def f169(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]))
    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({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output
f169([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

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)}
    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, 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
f170([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

171

def f171(left, right, excluded):
    left = list(left)

    def tidy(value):
        return str(value).strip(' \r').upper()
    excluded = {tidy(value) for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f171(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

172

def f172(board):
    board = list(board)
    known = set()
    regions = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(min(len(board[row]), 10)):
            if board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            work = [(row, col)]
            known.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        if len(known) >= 100:
                            continue
                        work.append(nxt)
            regions.append((len(cells), min(cells)))
    regions.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
    output = dict()
    output.update(returnvalue)
    return output
f172(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

173

def f173(rows, keep, factors):
    rows = list(rows)
    kept = []
    totals = {}
    amount = 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
            amount += charge
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in kept)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f173([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

174

def f174(board):
    board = list(board)
    known = set()
    pieces = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[0])):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            work = [(row, col)]
            known.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        work.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f174(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

175

def f175(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[:20]:
        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
f175([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

176

def f176(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors and rate0 != 0:
            factors[name0] = rate0
    matched = []
    for key, count in left:
        if key in factors:
            matched.append((key, count * factors[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output
f176([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

177

def f177(left, right, banned):
    left = list(left)

    def normalize(value):
        return str(value).strip().upper()
    banned = {normalize(value) for value in banned}
    a = {normalize(value) for value in left} - banned
    b = {normalize(value) for value in right} - banned
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f177(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

178

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

179

def f179(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}
    work = [start]
    while work:
        cur = work.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    work.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
f179([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

180

def f180(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[: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(combined)}
    output = dict()
    output.update(returnvalue)
    return output
f180([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

181

def f181(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]
    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
f181([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

182

def f182(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:
        if key in factors:
            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
f182([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

183

def f183(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        children.setdefault(a, []).append(b)
    distance = {start: 0} if limit > 0 or limit < 0 else {}
    pending = [start]
    while pending:
        cur = pending.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
                    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, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f183([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

184

def f184(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(min(count, 3 + (count - 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 = (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
f184([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

185

def f185(left, right, excluded):
    left = list(left)

    def tidy(value):
        return str(value).strip(' \r').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f185(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

186

def f186(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 (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)
    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
f186([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

187

def f187(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * 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
f187([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

188

def f188(board):
    board = list(board)
    known = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            pending = [(row, col)]
            known.add((row, col))
            while pending:
                cur = pending.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        if len(known) >= 100:
                            continue
                        pending.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f188(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

189

def f189(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0} if any((start in edge for edge in edges)) else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            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)
    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
f189([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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(board):
    board = list(board)
    known = set()
    pieces = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(min(len(board[row]), 10)):
            if board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            queue = [(row, col)]
            known.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        queue.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f190(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

191

def f191(board):
    board = list(board)
    found = set()
    pieces = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            queue = [(row, col)]
            found.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        if len(found) >= 100:
                            continue
                        queue.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f191(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

192

def f192(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            queue = [(row, col)]
            visited.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f192(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

193

def f193(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices and rate0 != 0:
            prices[name0] = rate0
    combined = []
    for key, count in left[:20]:
        if key in prices:
            combined.append((key, count * prices[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    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
f193([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

194

def f194(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(totals) if value >= limit]
    ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f194([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

195

def f195(left, right, ignored):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \r').upper()
    ignored = {str(value).strip() for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right if normalize(value) != ''} - ignored
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f195(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

196

def f196(rows, keep, factors):
    rows = list(rows)
    kept = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * abs(factors[group])
            kept.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            amount += cost
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': groupmap, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f196([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

197

def f197(board):
    board = list(board)
    known = set()
    pieces = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[0])):
            if board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            queue = [(row, col)]
            known.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        if len(known) >= 100:
                            continue
                        queue.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f197(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

198

def f198(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    totals = {}
    sumvalue = 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
            sumvalue += cost
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f198([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

199

def f199(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], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': sumvalue, 'groups': buckets, 'top': list(dict.fromkeys((code for code, score in matches)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f199([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

200

def f200(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}
    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
f200([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

201

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

202

def f202(nodes, edges):
    nodes = list(nodes)
    needs = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        routes[a].append(b)
        needs[b] += 1
    initial = dict(needs)
    complete = set()
    sequence = []
    groups = []
    while len(complete) < len(nodes) and len(complete) < 20:
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete))
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[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
f202(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

203

def f203(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}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < min(limit, 3):
            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
f203([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

204

def f204(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.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(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    work.append(nxt)
    sequence = list(levels)
    edge = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': sequence, 'depth': levels, 'frontier': edge, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output
f204([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

205

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

206

def f206(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(count % 100):
            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 = (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
f206([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

207

def f207(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}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < min(limit, 3):
            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
                    pending.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
f207([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

208

def f208(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    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]
    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
f208([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

209

def f209(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)
    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))
        if not available:
            break
        current = available[:1] if any((str(node).isupper() for node in nodes)) else available
        layers.append(current)
        for node in current:
            finished.add(node)
            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
f209(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

210

def f210(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, 3 + (count - count))):
            x += dx
            y += dy
            used = min(64, 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
f210([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

211

def f211(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(series) if value >= limit and (limit >= 0 or pos > 0)]
    increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max([0] + series), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f211([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

212

def f212(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 = max(-64, min(64, 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 = (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
f212([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

213

def f213(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \r').upper()
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f213(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

214

def f214(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    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
f214([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

215

def f215(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
f215([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

216

def f216(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 = 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
f216([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

217

def f217(left, right, ignored):
    left = list(left)

    def normalize(value):
        return str(value).strip(' ').upper()
    ignored = {str(value).strip() for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right} - ignored
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f217(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

218

def f218(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]))
    unmatched = 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': unmatched, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output
f218([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

219

def f219(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
f219([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

220

def f220(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        nextmap[a].append(b)
        indegree[b] += 1
    startdegree = dict(indegree)
    finished = set()
    sequence = []
    groups = []
    while len(finished) < len(nodes):
        available = sorted((node for node in nodes if indegree[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]:
                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
f220(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

221

def f221(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}
    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)
    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
f221([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

222

def f222(rows, keep, ratemap):
    rows = list(rows)
    matches = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(ratemap[group])
            matches.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': totals, 'top': [code for code, charge in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f222([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

223

def f223(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
f223([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

224

def f224(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, 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
f224([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

225

def f225(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    totals = {}
    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]
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            grand += cost
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    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
f225([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

226

def f226(rows, keep, ratemap):
    rows = list(rows)
    matches = []
    totals = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * ratemap[group]
            matches.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            sumvalue += charge
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': sumvalue, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in matches)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f226([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

227

def f227(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors or rate0 <= rate0 + 0:
            factors[name0] = rate0
    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]))
    unmatched = 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': unmatched, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output
f227([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

228

def f228(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    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 str(state).lower() in {str(item).lower() for item 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], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, score in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f228([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

229

def f229(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * abs(factors[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
f229([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

230

def f230(left, right, ignored):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \r').upper()
    ignored = {str(value).strip() for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right} - ignored
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f230(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

231

def f231(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    grand = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            charge = value * prices[group]
            selected.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            grand += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': grand, 'groups': groupmap, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f231([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

232

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

233

def f233(left, right, ignored):
    left = list(left)

    def canon(value):
        return str(value).strip().upper()
    ignored = {str(value).upper() for value in ignored}
    a = {canon(value) for value in left} - ignored
    b = {canon(value) for value in right} - ignored
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f233(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

234

def f234(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        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, []))[:20]:
                if nxt not in distance:
                    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[:3], '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'), ('F', 'G')], '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"]}

235

def f235(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}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(children.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    listing = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': listing, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f235([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

236

def f236(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
f236([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

237

def f237(board):
    board = list(board)
    found = set()
    regions = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            work = [(row, col)]
            found.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        work.append(nxt)
            regions.append((len(cells), min(cells)))
    regions.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
    output = dict()
    output.update(returnvalue)
    return output
f237(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

238

def f238(board):
    board = list(board)
    found = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[0])):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            queue = [(row, col)]
            found.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f238(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

239

def f239(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        nextmap[a].append(b)
        indegree[b] += 1
    initial = dict(indegree)
    handled = set()
    listing = []
    groups = []
    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[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        groups.append(current)
        for node in current:
            handled.add(node)
            listing.append(node)
        for node in current:
            for nxt in nextmap[node]:
                indegree[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
f239(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

240

def f240(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 = max(-64, min(64, y + dy))
            used = min(64, 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, 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
f240([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

241

def f241(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(totals) if value >= limit]
    increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f241([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

242

def f242(left, right, excluded):
    left = list(left)

    def tidy(value):
        return str(value).strip().upper()
    excluded = {tidy(value) for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right if tidy(value) != ''} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f242(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

243

def f243(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] < limit:
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in distance and (not nxt.startswith('Z')):
                    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
f243([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

244

def f244(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
f244([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

245

def f245(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(min(count, 3 + (count - count))):
            x = max(-64, min(64, 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
f245([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

246

def f246(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep:
            cost = value * abs(prices[group])
            selected.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output
f246([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

247

def f247(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    items = []
    for key, count in left:
        if key in prices:
            items.append((key, count * prices[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output
f247([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

248

def f248(left, right, excluded):
    left = list(left)

    def canon(value):
        return str(value).strip(' \n').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f248(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

249

def f249(left, right, excluded):
    left = list(left)

    def canon(value):
        return ' '.join(str(value).split()).upper()
    excluded = {str(value).upper() for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f249(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

250

def f250(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(min(count, 64)):
            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
f250([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

251

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

252

def f252(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:
        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(items)}
    output = dict()
    output.update(returnvalue)
    return output
f252([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

253

def f253(board):
    board = list(board)
    found = set()
    pieces = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            queue = [(row, col)]
            found.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        if len(found) >= 100:
                            continue
                        queue.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f253(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

254

def f254(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 = max(-64, min(64, 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 = 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
f254([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

255

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

256

def f256(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, 3 + (count - count))):
            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
f256([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

257

def f257(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 = (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
f257([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

258

def f258(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 = max(-64, min(64, 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
f258([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

259

def f259(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip(' ').upper()[:12]
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f259(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

260

def f260(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, 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
f260([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

261

def f261(board):
    board = list(board)
    known = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            work = [(row, col)]
            known.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        work.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f261(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

262

def f262(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(min(count, 3 + (count - 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 = (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
f262([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

263

def f263(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, 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
f263([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

264

def f264(board):
    board = list(board)
    known = set()
    pieces = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            pending = [(row, col)]
            known.add((row, col))
            while pending:
                cur = pending.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        pending.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f264(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

265

def f265(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}
    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 and (not nxt.startswith('Z')):
                    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
f265([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

266

def f266(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(count):
            x = max(-64, min(64, x + dx))
            y = max(-64, min(64, 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
f266([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

267

def f267(left, right, excluded):
    left = list(left)

    def canon(value):
        return str(value).strip().upper()[:12]
    excluded = {canon(value) for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f267(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

268

def f268(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]))
    leftover = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output
f268([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

269

def f269(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f269([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

270

def f270(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(min(64, len(values) - size + 1)):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals[:64]) 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': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f270([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

271

def f271(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            queue = [(row, col)]
            visited.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        queue.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f271(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

272

def f272(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': min(256, max(windows)), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f272([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

273

def f273(left, right, banned):
    left = list(left)

    def normalize(value):
        return ' '.join(str(value).split()).upper()
    banned = {str(value).strip() for value in banned}
    a = {normalize(value) for value in left} - banned
    b = {normalize(value) for value in right} - banned
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f273(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

274

def f274(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \r').upper()
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
    b = {normalize(value) for value in right if normalize(value) != ''} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f274(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

275

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

276

def f276(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.setdefault(a, []).append(b)
    steps = {start: 0} if any((start in edge for edge in edges)) else {} if limit > 0 or limit < 0 else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(routes.get(cur, []))[:20]:
                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
f276([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

277

def f277(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:
            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
f277([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

278

def f278(left, right, excluded):
    left = list(left)

    def tidy(value):
        return str(value).strip(' ').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f278(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

279

def f279(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(series) if value >= limit]
    increases = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f279([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

280

def f280(board):
    board = list(board)
    visited = set()
    regions = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            queue = [(row, col)]
            visited.add((row, col))
            while queue:
                cur = queue.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        queue.append(nxt)
            regions.append((len(cells), min(cells)))
    regions.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
    output = dict()
    output.update(returnvalue)
    return output
f280(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

281

def f281(board):
    board = list(board)
    found = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[0])):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            pending = [(row, col)]
            found.add((row, col))
            while pending:
                cur = pending.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        pending.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f281(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

282

def f282(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 sorted(routes.get(cur, [])):
                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
f282([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

283

def f283(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 = []
    layers = []
    while len(finished) < len(nodes) and len(finished) < 20:
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
        if not available:
            break
        current = available[:1] if any((str(node).isupper() for node in nodes)) else available
        layers.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in 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
f283(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

284

def f284(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices:
            prices[name0] = rate0
    items = []
    for key, count in left:
        if key in prices and count > 0:
            items.append((key, count * prices[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    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
f284([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

285

def f285(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)
    finished = set()
    listing = []
    groups = []
    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), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            finished.add(node)
            listing.append(node)
        for node in current:
            for nxt in 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
f285(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

286

def f286(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(min(count, 3 + (count - count))):
            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
f286([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1)])
{"bounds":[-5,-4,3,3],"end":[3,2],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":31}

287

def f287(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} if any((start in edge for edge in edges)) 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:
                    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
f287([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

288

def f288(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]
    increases = 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': increases}
    output = dict()
    output.update(returnvalue)
    return output
f288([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

289

def f289(left, right, excluded):
    left = list(left)

    def tidy(value):
        return str(value).strip(' \n').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f289(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

290

def f290(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)
    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)
    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', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

291

def f291(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)
    distance = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < limit:
            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
                    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
f291([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

292

def f292(left, right, excluded):
    left = list(left)

    def canon(value):
        return str(value).strip().upper()[:12]
    excluded = {canon(value) for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right if canon(value) != ''} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f292(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

293

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

294

def f294(left, right, excluded):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \n').upper()
    excluded = {str(value).upper() for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right if normalize(value) != ''} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f294(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

295

def f295(board):
    board = list(board)
    known = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(min(len(board[row]), 10)):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            work = [(row, col)]
            known.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        work.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f295(['.#.##.', '.#..##', '#....#', '...#.#', '##....', '.#####'])
{"anchors":[[4,0],[0,3],[0,1],[2,0],[3,3]],"count":5,"filled":17,"sizes":[7,6,2,1,1]}

296

def f296(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        children[a].append(b)
        indegree[b] += 1
    initial = dict(indegree)
    complete = set()
    sequence = []
    rounds = []
    while len(complete) < len(nodes):
        available = sorted((node for node in nodes if indegree[node] == 0 and node not in complete), reverse=len(nodes) > 20)
        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]:
                indegree[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
f296(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db"],["api","jobs","proxy"],["ui","worker"]],"count":8,"order":["auth","cache","db","api","jobs","proxy","ui","worker"],"roots":["auth","cache","db"]}

297

def f297(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
f297([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

298

def f298(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        if name0 not in ratemap or rate0 <= rate0 + 0:
            ratemap[name0] = rate0
    combined = []
    for key, count in left:
        if key in ratemap:
            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
f298([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

299

def f299(left, right, banned):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \n').upper()
    banned = {str(value).upper() for value in banned}
    a = {normalize(value) for value in left} - banned
    b = {normalize(value) for value in right} - banned
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f299(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

300

def f300(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f300([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

301

def f301(left, right, excluded):
    left = list(left)

    def tidy(value):
        return ' '.join(str(value).split()).upper()
    excluded = {tidy(value) for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right if tidy(value) != ''} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f301(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivory', 'BLUEx', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUEX","CYAN","DELTA","FROST","HELIUM","IVORY"],"both":["AMBER","HELIUM","IVORY"],"left":["CYAN","DELTA"],"right":["BLUEX","FROST"],"score":16}

302

def f302(board):
    board = list(board)
    visited = set()
    pieces = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[0])):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            work = [(row, col)]
            visited.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        work.append(nxt)
            pieces.append((len(cells), min(cells)))
    pieces.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
    output = dict()
    output.update(returnvalue)
    return output
f302(['.#..#.', '.#..##', '#....#', '...#.#', '##....', '..####'])
{"anchors":[[0,4],[5,2],[0,1],[4,0],[2,0],[3,3]],"count":6,"filled":15,"sizes":[5,4,2,2,1,1]}

303

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

304

def f304(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)
    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[:1] if any((str(node).isupper() for node in nodes)) else available
        rounds.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f304(['cache', 'ui', 'jobs', 'db', 'proxy', 'api', 'auth', 'worker'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy')])
{"batches":[["auth","cache","db","ui"],["api","jobs","proxy"],["worker"]],"count":8,"order":["auth","cache","db","ui","api","jobs","proxy","worker"],"roots":["auth","cache","db","ui"]}

305

def f305(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        children.setdefault(a, []).append(b)
    steps = {start: 0}
    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)
    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
f305([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G')], '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"]}

306

def f306(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[:20]:
        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', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

307

def f307(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 += 1
            point = (x, y)
            if point in found and list(point) not in crossings:
                crossings.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': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f307([('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3), ('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 2)])
{"bounds":[-5,-4,5,3],"end":[5,3],"far":8,"revisits":[[-2,0],[-1,0],[-4,-3],[-3,-3],[-2,-3]],"steps":32}

308

def f308(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({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output
f308([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

309

def f309(rows, keep, prices):
    rows = list(rows)
    selected = []
    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:
            charge = value * abs(prices[group])
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            grand += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f309([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

310

def f310(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[:64]) if value >= limit]
    increases = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f310([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 4, 61)
{"best":80,"hits":[2,3,4,5,6,7,8,9,10,11],"rises":8,"sums":[37,49,61,70,74,78,68,73,80,66,78,65]}

311

def f311(rows, keep, factors):
    rows = list(rows)
    selected = []
    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:
            cost = value * factors[group]
            selected.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            sumvalue += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': sumvalue, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f311([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

312

def f312(left, right, ignored):
    left = list(left)

    def normalize(value):
        return str(value).strip(' \n').upper()
    ignored = {str(value).upper() for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right} - ignored
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f312(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

313

def f313(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices and rate0 != 0:
            prices[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    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
f313([('AN', 3), ('BR', 17), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 12), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["BR",121],["GQ",110],["FP",92],["EV",58],["DL",51]],"missing":[],"total":503}

314

def f314(left, right, excluded):
    left = list(left)

    def canon(value):
        return str(value).strip(' ').upper()
    excluded = {str(value).upper() for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f314(['delta', 'cyan ', 'Ember', 'ivory', 'helium', ' Amber', 'Ember'], ['ivoryx', 'BLUE', 'Ember', 'helium', ' Amber', 'frost', 'Ember'], ['EMBER'])
{"all":["AMBER","BLUE","CYAN","DELTA","FROST","HELIUM","IVORY","IVORYX"],"both":["AMBER","HELIUM"],"left":["CYAN","DELTA","IVORY"],"right":["BLUE","FROST","IVORYX"],"score":11}

315

def f315(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep and value != 0:
            cost = value * prices[group]
            selected.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f315([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":319,"edge":45,"north":469,"south":285},"top":["AN69","AN21","DL47"],"total":1118}

316

def f316(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 and count > 0:
            matched.append((key, count * factors[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    unmatched = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output
f316([('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7), ('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)], [('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7), ('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)], 2)
{"count":8,"items":[["GQ",128],["FP",92],["BR",86],["EV",58],["DL",51]],"missing":[],"total":486}

317

def f317(rows, keep, prices):
    rows = list(rows)
    kept = []
    buckets = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            charge = value * prices[group]
            kept.append((code, charge))
            buckets[group] = buckets.get(group, 0) + charge
            grand += charge
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': buckets, 'top': [code for code, charge in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output
f317([('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11), ('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":11,"groups":{"core":286,"edge":45,"north":469,"south":305},"top":["AN69","AN21","DL47"],"total":1105}

318

def f318(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 sorted(children.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    listing = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': listing, 'depth': distance, 'frontier': furthest, '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', 'E')], 'A', 3)
{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":1,"F":2,"G":2,"H":3},"frontier":["H"],"order":["A","B","C","E","D","F","G","H"]}

319

def f319(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]
    increases = 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': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f319([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

320

def f320(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(min(64, len(values) - size + 1)):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals) if value >= limit]
    increases = sum((1 for pos in range(1, 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
f320([7, 8, 9, 13, 19, 20, 18, 17, 23, 10, 23, 24, 9, 22, 10], 6, 61)
{"best":115,"hits":[0,1,2,3,4,5,6,7,8,9],"rises":6,"sums":[76,87,96,110,107,111,115,106,111,98]}

Final Query

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

import json, re
from collections import deque
out = {}
left = list((('AN', 3), ('BR', 12), ('CX', 3), ('DL', 7)) + (('EV', 7), ('FP', 9), ('GQ', 14), ('HR', 8)))
right = list((('AN', 5), ('BR', 7), ('CX', 6), ('DL', 7)) + (('EV', 8), ('FP', 10), ('GQ', 9), ('HR', 4)))
fee = 2
joined = []
for key, count in left:
    matches = [rate for name, rate in right if name == key]
    if matches:
        joined.append([key, count * matches[0] + fee])
joined.sort(key=lambda item: (-item[1], item[0]))
rightkeys = {key for key, rate in right}
record = {'aa': joined[:5], 'bb': sum((item[1] for item in joined)), 'cc': sorted((key for key, count in left if key not in rightkeys)), 'dd': len(joined)}
clue = record['bb']
keep = list(('ready',) + ('checked',))
rates = dict((('north', 7),) + (('south', 5), ('core', 11), ('edge', 3)))
route = clue
cases = {
    503: list((('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11)) + (('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 22), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 22), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3))),
    486: list((('AN10', 'south', 'ready', 15), ('DL47', 'north', 'ready', 20), ('AN84', 'edge', 'ready', 15), ('AN21', 'north', 'ready', 23), ('AN58', 'south', 'checked', 20), ('AN95', 'north', 'ready', 11)) + (('CX32', 'edge', 'void', 20), ('AN69', 'core', 'ready', 19), ('CX06', 'south', 'hold', 7), ('BR43', 'core', 'void', 14), ('CX80', 'south', 'ready', 26), ('CX17', 'core', 'ready', 7), ('BR54', 'north', 'checked', 10), ('DL91', 'north', 'ready', 3))),
}
rows = cases[route]
chosen = [(code, group, value) for code, group, state, value in rows if state in keep]
priced = [(code, group, value * rates[group]) for code, group, value in chosen]
groups = {}
for code, group, price in priced:
    groups[group] = groups.get(group, 0) + price
ranked = sorted(priced, key=lambda row: (-row[2], row[0]))
record = {'aa': [row[0] for row in ranked[:3]], 'bb': sum((row[2] for row in priced)), 'cc': len(priced), 'dd': groups}
stamp = record['bb']
values = list((7, 8, 9, 13, 19, 20, 18, 17) + (23, 10, 23, 24, 9, 22, 10))
limit = 61
route = clue
cases = {
    486: 6,
    503: 4,
}
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}
ticket = record['bb']
nodes = list(('cache', 'ui', 'jobs', 'db') + ('proxy', 'api', 'auth', 'worker'))
options = {
    486: ('near', stamp),
    503: ('far', ticket),
}
route = options[clue]
cases = {
    ('near', 1105): list((('auth', 'api'), ('db', 'api'), ('api', 'ui')) + (('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'))),
    ('near', 1118): list((('auth', 'api'), ('db', 'api'), ('cache', 'api')) + (('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'))),
    ('far', 115): list((('auth', 'api'), ('db', 'api'), ('cache', 'api')) + (('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'))),
    ('far', 80): list((('auth', 'api'), ('db', 'api'), ('cache', 'api')) + (('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'))),
}
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'][3]
route = ticket
cases = {
    115: list((('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3)) + (('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('S', 1))),
    80: list((('W', 3), ('E', 2), ('S', 2), ('W', 1), ('S', 1), ('W', 3), ('E', 3)) + (('E', 2), ('S', 1), ('W', 1), ('E', 2), ('N', 2), ('E', 2), ('N', 3), ('N', 2), ('E', 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}
permit = record['ee']
route = (badge, permit)
cases = {
    ('ui', 32): list(('.#.##.', '.#..##', '#....#', '...#.#') + ('##....', '.#####')),
    ('ui', 31): list(('.#.##.', '.#..##', '#....#', '...#.#') + ('##....', '.#####')),
    ('api', 32): list(('.#.##.', '.#..##', '#....#', '...#.#') + ('##....', '.#####')),
    ('api', 31): list(('.#..#.', '.#..##', '#....#', '...#.#') + ('##....', '..####')),
}
board = cases[route]
cells = [(row, col) for row in range(len(board)) for col in range(len(board[row])) if board[row][col] == '#']
parent = {cell: cell for cell in cells}

def root(cell):
    while parent[cell] != cell:
        parent[cell] = parent[parent[cell]]
        cell = parent[cell]
    return cell

def merge(a, b):
    a = root(a)
    b = root(b)
    if a != b:
        parent[b] = a
for row, col in cells:
    for other in ((row - 1, col), (row, col - 1)):
        if other in parent:
            merge((row, col), other)
groups = {}
for cell in cells:
    groups.setdefault(root(cell), []).append(cell)
parts = [(len(group), min(group)) for group in groups.values()]
parts.sort(key=lambda item: (-item[0], item[1]))
record = {'aa': [part[0] for part in parts], 'bb': [list(part[1]) for part in parts], 'cc': len(cells), 'dd': len(parts)}
signal = record['cc']
left = list(('delta', 'cyan ', 'Ember') + ('ivory', 'helium', ' Amber', 'Ember'))
blocked = ['EMBER']
route = signal
cases = {
    15: list(('ivoryx', 'BLUE', 'Ember') + ('helium', ' Amber', 'frost', 'Ember')),
    17: list(('ivory', 'BLUEx', 'Ember') + ('helium', ' Amber', 'frost', 'Ember')),
}
right = cases[route]
a = set()
b = set()
ban = set()
for value in blocked:
    ban.add(value.strip().upper())
for value in left:
    value = value.strip().upper()
    if value not in ban:
        a.add(value)
for value in right:
    value = value.strip().upper()
    if value not in ban:
        b.add(value)
both = a.intersection(b)
record = {'aa': sorted(both), 'bb': sorted(a.difference(b)), 'cc': sorted(b.difference(a)), 'dd': sorted(a.union(b)), 'ee': sum(map(len, both))}
token = record['ee']
start = 'A'
limit = 3
route = token
cases = {
    16: list((('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E')) + (('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'E'))),
    11: list((('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E')) + (('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('F', 'G'))),
}
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)}
out['aa'] = record['aa']
out['bb'] = record['bb']
out['cc'] = record['cc']
out['dd'] = record['dd']
print(json.dumps(out, separators=(",", ":"), sort_keys=True))