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

001

def f1(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]
    growth = 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': growth}
    output = dict()
    output.update(returnvalue)
    return output
f1([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

002

def f2(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[:64]) 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
f2([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

003

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

004

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

005

def f5(board):
    board = list(board)
    visited = set()
    pieces = []
    for row in range(len(board)):
        for col in range(min(len(board[row]), 10)):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            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
f5(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

006

def f6(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = right
    breaks = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        breaks.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f6([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

007

def f7(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in wordmap.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f7(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

008

def f8(board):
    board = list(board)
    known = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[0])):
            if 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)
            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
f8(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

009

def f9(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f9(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

010

def f10(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    gaps = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        gaps.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f10([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

011

def f11(board):
    board = list(board)
    known = 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 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)
                        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
f11(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

012

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

013

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

014

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

015

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

016

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

017

def f17(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f17(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

018

def f18(board):
    board = list(board)
    found = set()
    regions = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            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)
            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
f18(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

019

def f19(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = 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
f19([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1)])
{"bounds":[-8,-2,1,1],"end":[-3,-1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":32}

020

def f20(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        frequency[word] = min(9, frequency.get(word, 0) + 1)
    sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in frequency.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f20(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

021

def f21(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = right
    spaces = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        spaces.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': min(100, max((right - left for left, right in combined)))}
    output = dict()
    output.update(returnvalue)
    return output
f21([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

022

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

023

def f23(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals) if value >= limit]
    ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f23([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

024

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

025

def f25(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
    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': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f25([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

026

def f26(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)
                        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
f26(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

027

def f27(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
f27(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

028

def f28(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        frequency[word] = min(9, frequency.get(word, 0) + 1)
    sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f28(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

029

def f29(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in tallies.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f29(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

030

def f30(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)
                        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
f30(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

031

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

032

def f32(board):
    board = list(board)
    visited = 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 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)
            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
f32(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

033

def f33(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 = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in repeats:
                repeats.append(list(point))
            visited.add(point)
            far = min(64, max(far, abs(x) + abs(y)))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f33([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2)])
{"bounds":[-8,-2,1,1],"end":[-4,1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":33}

034

def f34(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x = max(-64, min(64, 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
f34([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2)])
{"bounds":[-8,-2,1,1],"end":[-4,1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":33}

035

def f35(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted((pair for pair in spans if pair[0] <= pair[1])):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    gaps = []
    for pos in range(1, min(50, len(combined))):
        left = combined[pos][0]
        gaps.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((min(100, right - left) for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f35([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

036

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

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

037

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

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

038

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

039

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

    def normalize(value):
        return ' '.join(str(value).split()).upper()
    excluded = {str(value).upper() for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    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
f39(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

040

def f40(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals[:64]) if value >= limit and (limit >= 0 or pos > 0)]
    increases = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f40([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

041

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

042

def f42(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} if any((start in edge for edge in edges)) else {}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < limit:
            for nxt in (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)
    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
f42([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'F', 3)
{"count":5,"depth":{"B":2,"D":3,"E":3,"F":0,"H":1},"frontier":["D","E"],"order":["F","H","B","D","E"]}

043

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

044

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

045

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

    def normalize(value):
        return str(value).strip(' \r').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
    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
f45(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

046

def f46(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
        if not result or left > result[-1][1] + gap % 5:
            result.append([left, right])
        else:
            result[-1][1] = right
    gaps = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        gaps.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f46([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

047

def f47(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 = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in returns:
                returns.append(list(point))
            known.add(point)
            far = max(far, 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
f47([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2)])
{"bounds":[-8,-2,1,1],"end":[-4,1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":33}

048

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

049

def f49(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(series) if value >= limit]
    growth = sum((1 for pos in range(1, min(65, len(series))) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': indexes, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f49([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

050

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

051

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

052

def f52(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + max(0, gap) + 1:
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    spaces = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        spaces.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f52([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

053

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

054

def f54(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] < min(limit, 3):
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    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
f54([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'C', 3)
{"count":7,"depth":{"A":3,"B":3,"C":0,"E":1,"F":1,"G":2,"H":2},"frontier":["A","B"],"order":["C","E","F","G","H","A","B"]}

055

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

056

def f56(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f56([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

057

def f57(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            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
f57(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

058

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

059

def f59(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(series[:64]) if value >= limit]
    increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max([0] + series), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f59([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

060

def f60(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
        if not segments or left > segments[-1][1] + gap:
            segments.append([left, right])
        else:
            segments[-1][1] = max(segments[-1][1], right)
    gaps = []
    for pos in range(1, len(segments)):
        left = segments[pos][0]
        gaps.append(left - segments[pos - 1][1])
    returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in segments)))}
    output = dict()
    output.update(returnvalue)
    return output
f60([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

061

def f61(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 and (limit >= 0 or pos > 0)]
    growth = sum((1 for pos in range(1, min(65, len(series))) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f61([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

062

def f62(board):
    board = list(board)
    found = set()
    pieces = []
    for row in range(len(board)):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in found:
                continue
            cells = []
            work = [(row, col)]
            found.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        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
f62(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

063

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

064

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

065

def f65(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    positions = [pos for pos, value in enumerate(windows) if value >= limit]
    growth = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': positions, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f65([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

066

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

067

def f67(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in wordmap.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f67(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

068

def f68(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f68(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

069

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

070

def f70(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
        if not combined or left > combined[-1][1] + gap % 5:
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    gaps = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        gaps.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f70([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

071

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

    def normalize(value):
        return ' '.join(str(value).split()).upper()
    banned = {normalize(value) for value in banned}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - 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
f71(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

072

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

073

def f73(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 = []
            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)
                        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
f73(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

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])))
    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
f74([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

075

def f75(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f75(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

076

def f76(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 3 + (count - 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 = 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': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f76([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1)])
{"bounds":[-8,-2,1,1],"end":[-3,-1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":32}

077

def f77(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used = 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
f77([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1)])
{"bounds":[-8,-2,1,1],"end":[-3,-1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":32}

078

def f78(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f78(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

079

def f79(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 = []
            work = [(row, col)]
            known.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        work.append(nxt)
            components.append((len(cells), min(cells)))
    components.sort(key=lambda item: (-item[0], item[1]))
    returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
    output = dict()
    output.update(returnvalue)
    return output
f79(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

080

def f80(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if levels[cur] < limit:
            for nxt in 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
f80([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'F', 3)
{"count":5,"depth":{"B":2,"D":3,"E":3,"F":0,"H":1},"frontier":["D","E"],"order":["F","H","B","D","E"]}

081

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

082

def f82(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(totals), 'hits': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f82([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

083

def f83(board):
    board = list(board)
    visited = set()
    pieces = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            work = [(row, col)]
            visited.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        if len(visited) >= 100:
                            continue
                        work.append(nxt)
            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
f83(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

084

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

085

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

    def normalize(value):
        return str(value).strip(' ').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right if normalize(value) != ''} - excluded
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f85(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

086

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

087

def f87(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) for word in stop}
    items = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in tallies.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f87(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

088

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

089

def f89(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f89([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

090

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

    def tidy(value):
        return str(value).strip(' ').upper()
    banned = {str(value).strip() 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((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f90(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

091

def f91(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in frequency.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f91(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

092

def f92(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals) if value >= limit]
    increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f92([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

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

094

def f94(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in returns:
                returns.append(list(point))
            found.add(point)
            far = max(far, 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
f94([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1)])
{"bounds":[-8,-2,1,1],"end":[-3,-1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":32}

095

def f95(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)
                        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
f95(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

096

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

097

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

    def tidy(value):
        return str(value).strip(' ').upper()[:12]
    excluded = {tidy(value) for value in excluded}
    a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    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
f97(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

098

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

099

def f99(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in tallies.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in tallies.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f99(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

100

def f100(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]
    increases = sum((1 for pos in range(1, min(65, 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
f100([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

101

def f101(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]))
    positions = [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': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f101([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

102

def f102(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(min(64, len(values) - size + 1)):
        totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(totals[:64]) 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': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f102([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

103

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

104

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

    def normalize(value):
        return str(value).strip(' \n').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
    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
f104(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

105

def f105(board):
    board = list(board)
    visited = set()
    pieces = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            work = [(row, col)]
            visited.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
                        visited.add(nxt)
                        work.append(nxt)
            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
f105(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

106

def f106(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap + 1:
            combined.append([left, right])
        else:
            combined[-1][1] = right
    breaks = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        breaks.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f106([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

107

def f107(board):
    board = list(board)
    visited = 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 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)
            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
f107(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

108

def f108(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = max(far, 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
f108([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2)])
{"bounds":[-8,-2,1,1],"end":[-4,1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":33}

109

def f109(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(series) if value >= limit]
    increases = sum((1 for pos in range(1, min(65, len(series))) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f109([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

110

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

111

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

112

def f112(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
    ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f112([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

113

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

114

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

115

def f115(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in tallies.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f115(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

116

def f116(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in tallies.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f116(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

117

def f117(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = max(0, combined[-1][1], right)
    breaks = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        breaks.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((min(100, right - left) for left, right in combined)), 'holes': breaks, 'longest': min(100, max((right - left for left, right in combined)))}
    output = dict()
    output.update(returnvalue)
    return output
f117([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

118

def f118(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop or len(word) > 12:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in tallies.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f118(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

119

def f119(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f119(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

120

def f120(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted((pair for pair in spans if pair[0] <= pair[1])):
        if not result or left > result[-1][1] + gap:
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    breaks = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        breaks.append(min(100, left - result[pos - 1][1]))
    returnvalue = {'segments': result, 'cover': sum((min(100, right - left) for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f120([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

121

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

122

def f122(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])))
    indexes = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f122([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

123

def f123(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms[:64]:
        if word in stop or len(word) > 12:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in frequency.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f123(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

124

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

125

def f125(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans, key=lambda pair: pair[0]):
        if not result or left > result[-1][1] + gap:
            result.append([left, right])
        else:
            result[-1][1] = max(0, result[-1][1], right)
    gaps = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        gaps.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in result)))}
    output = dict()
    output.update(returnvalue)
    return output
f125([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

126

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

127

def f127(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[: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': positions, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f127([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

128

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

    def canon(value):
        return str(value).strip(' \r').upper()[:12]
    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
    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
f128(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

129

def f129(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]))
    matches = [pos for pos, value in enumerate(series) if value >= limit]
    ups = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f129([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

130

def f130(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in frequency.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f130(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

131

def f131(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}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    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
f131([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'C', 3)
{"count":7,"depth":{"A":3,"B":3,"C":0,"E":1,"F":1,"G":2,"H":2},"frontier":["A","B"],"order":["C","E","F","G","H","A","B"]}

132

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

133

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

134

def f134(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:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    result = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': result, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f134([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'C', 3)
{"count":7,"depth":{"A":3,"B":3,"C":0,"E":1,"F":1,"G":2,"H":2},"frontier":["A","B"],"order":["C","E","F","G","H","A","B"]}

135

def f135(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
        if not combined or left > combined[-1][1] + gap % 5:
            combined.append([left, right])
        else:
            combined[-1][1] = right
    gaps = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        gaps.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f135([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

136

def f136(board):
    board = list(board)
    known = set()
    regions = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if board[row][col] != '#' or (row, col) in 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)
            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
f136(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

137

def f137(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
    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
f137(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

138

def f138(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in wordmap.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f138(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

139

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

    def tidy(value):
        return str(value).strip().upper()
    ignored = {str(value).upper() for value in ignored}
    a = {tidy(value) for value in left} - ignored
    b = {tidy(value) for value in right} - ignored
    both = a & b
    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
f139(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

140

def f140(board):
    board = list(board)
    visited = set()
    regions = []
    for row in range(len(board)):
        for col in range(len(board[0])):
            if col >= 12 or board[row][col] != '#' or (row, col) in visited:
                continue
            cells = []
            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)
            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
f140(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

141

def f141(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f141(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

142

def f142(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    incoming = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        children[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    complete = set()
    sequence = []
    groups = []
    while len(complete) < len(nodes) and len(complete) < 20:
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
        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 children[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output
f142(['cache', 'jobs', 'auth', 'db', 'worker', 'api', 'ui', 'proxy'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('cache', 'db')])
{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

143

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

144

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

    def normalize(value):
        return str(value).strip(' \n').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
f144(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

145

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

146

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

147

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

148

def f148(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        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 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
f148([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1)])
{"bounds":[-8,-2,1,1],"end":[-3,-1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":32}

149

def f149(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans):
        if not segments or left > segments[-1][1] + gap % 5:
            segments.append([left, right])
        else:
            segments[-1][1] = max(0, segments[-1][1], right)
    breaks = []
    for pos in range(1, len(segments)):
        left = segments[pos][0]
        breaks.append(left - segments[pos - 1][1])
    returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
    output = dict()
    output.update(returnvalue)
    return output
f149([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

150

def f150(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': min(256, max(series)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f150([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

151

def f151(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = max(0, combined[-1][1], right)
    gaps = []
    for pos in range(1, min(50, len(combined))):
        left = combined[pos][0]
        gaps.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in combined)))}
    output = dict()
    output.update(returnvalue)
    return output
f151([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

152

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

153

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

    def canon(value):
        return str(value).strip(' \n').upper()
    banned = {str(value).upper() for value in banned}
    a = {canon(value) for value in left} - banned
    b = {canon(value) for value in right if canon(value) != ''} - 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
f153(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

154

def f154(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
        if not combined or left > combined[-1][1] + max(0, gap):
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    breaks = []
    for pos in range(1, min(50, len(combined))):
        left = combined[pos][0]
        breaks.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f154([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

155

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

156

def f156(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)
                        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
f156(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

157

def f157(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
f157(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

158

def f158(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap + 1:
            combined.append([left, right])
        else:
            combined[-1][1] = max(0, combined[-1][1], right)
    breaks = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        breaks.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f158([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

159

def f159(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 = []
            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
f159(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

160

def f160(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 if tidy(value) != tidy(value) or tidy(value) != ''} - ignored
    b = {tidy(value) for value in right if tidy(value) != ''} - ignored
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f160(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

161

def f161(board):
    board = list(board)
    known = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if col >= 12 or board[row][col] != '#' or (row, col) in known:
                continue
            cells = []
            work = [(row, col)]
            known.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
                        known.add(nxt)
                        if len(known) >= 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
f161(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

162

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

    def normalize(value):
        return str(value).strip().upper()
    excluded = {str(value).upper() for value in excluded}
    a = {normalize(value) for value in left} - 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
f162(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

163

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

    def normalize(value):
        return str(value).strip(' \r').upper()
    ignored = {normalize(value) for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right if normalize(value) != ''} - ignored
    both = a & b
    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
f163(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

164

def f164(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
f164([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

165

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

166

def f166(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans):
        if not segments or left > segments[-1][1] + max(0, gap) + 1:
            segments.append([left, right])
        else:
            segments[-1][1] = right
    breaks = []
    for pos in range(1, len(segments)):
        left = segments[pos][0]
        breaks.append(left - segments[pos - 1][1])
    returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
    output = dict()
    output.update(returnvalue)
    return output
f166([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

167

def f167(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(spans):
        if not combined or left > combined[-1][1] + gap % 5 + 1:
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    spaces = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        spaces.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f167([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

168

def f168(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} - 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
f168(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

169

def f169(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in returns:
                returns.append(list(point))
            known.add(point)
            far = 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
f169([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2)])
{"bounds":[-8,-2,1,1],"end":[-4,1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":33}

170

def f170(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):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in repeats:
                repeats.append(list(point))
            known.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f170([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1)])
{"bounds":[-8,-2,1,1],"end":[-3,-1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":32}

171

def f171(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop or len(word) < 2:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in wordmap.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': heads, 'size': min(256, sum((len(word) * count for word, count in wordmap.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f171(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

172

def f172(board):
    board = list(board)
    found = 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 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
f172(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

173

def f173(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    sorteditems = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in wordmap.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': wordmap, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f173(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

174

def f174(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 = []
            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)
            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":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

175

def f175(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(series) if value >= limit and (limit >= 0 or pos > 0)]
    growth = sum((1 for pos in range(1, min(65, len(series))) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': indexes, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f175([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

176

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

    def tidy(value):
        return ' '.join(str(value).split()).upper()
    excluded = {str(value).strip() for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    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
f176(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

177

def f177(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f177(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

178

def f178(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    positions = [pos for pos, value in enumerate(series) if value >= limit]
    increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f178([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

179

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

180

def f180(board):
    board = list(board)
    visited = set()
    regions = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[0])):
            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)
            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
f180(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

181

def f181(board):
    board = list(board)
    visited = set()
    pieces = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[row])):
            if 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
f181(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

182

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

183

def f183(board):
    board = list(board)
    visited = 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 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
f183(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

184

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

    def tidy(value):
        return ' '.join(str(value).split()).upper()
    excluded = {str(value).strip() for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    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
f184(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

185

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

186

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

187

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

188

def f188(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans):
        if not segments or left > segments[-1][1] + gap % 5:
            segments.append([left, right])
        else:
            segments[-1][1] = right
    breaks = []
    for pos in range(1, len(segments)):
        left = segments[pos][0]
        breaks.append(left - segments[pos - 1][1])
    returnvalue = {'segments': segments, 'cover': sum((min(100, right - left) for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
    output = dict()
    output.update(returnvalue)
    return output
f188([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

189

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

190

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

191

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

192

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

193

def f193(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    positions = [pos for pos, value in enumerate(windows) if value >= limit]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f193([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

194

def f194(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in frequency.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f194(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

195

def f195(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:
                    distance[nxt] = distance[cur] + 1
                    work.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[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f195([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'F', 3)
{"count":5,"depth":{"B":2,"D":3,"E":3,"F":0,"H":1},"frontier":["D","E"],"order":["F","H","B","D","E"]}

196

def f196(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals[:64]) 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
f196([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

197

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

    def tidy(value):
        return str(value).strip(' ').upper()
    ignored = {tidy(value) for value in ignored}
    a = {tidy(value) for value in left} - ignored
    b = {tidy(value) for value in right} - ignored
    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
f197(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

198

def f198(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    positions = [pos for pos, value in enumerate(windows[:64]) if value >= limit and (limit >= 0 or pos > 0)]
    ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': positions, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f198([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

199

def f199(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f199(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

200

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

201

def f201(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans):
        if not segments or left > segments[-1][1] + gap % 5:
            segments.append([left, right])
        else:
            segments[-1][1] = max(segments[-1][1], right)
    gaps = []
    for pos in range(1, len(segments)):
        left = segments[pos][0]
        gaps.append(left - segments[pos - 1][1])
    returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
    output = dict()
    output.update(returnvalue)
    return output
f201([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

202

def f202(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans):
        if not segments or left > segments[-1][1] + gap + 1:
            segments.append([left, right])
        else:
            segments[-1][1] = max(segments[-1][1], right)
    spaces = []
    for pos in range(1, len(segments)):
        left = segments[pos][0]
        spaces.append(left - segments[pos - 1][1])
    returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': max((right - left for left, right in segments))}
    output = dict()
    output.update(returnvalue)
    return output
f202([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

203

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

204

def f204(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
        if not result or left > result[-1][1] + gap:
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    breaks = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        breaks.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': min(100, max((right - left for left, right in result)))}
    output = dict()
    output.update(returnvalue)
    return output
f204([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

205

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

206

def f206(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + gap:
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    spaces = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        spaces.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': spaces, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f206([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

207

def f207(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(windows) if value >= limit]
    growth = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f207([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

208

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

209

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

    def tidy(value):
        return str(value).strip().upper()
    excluded = {str(value).upper() for value in excluded}
    a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    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
f209(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

210

def f210(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)
                        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
f210(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

211

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

    def normalize(value):
        return str(value).strip(' ').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
f211(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

212

def f212(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)
                        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
f212(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

213

def f213(board):
    board = list(board)
    known = 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 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
f213(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

214

def f214(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(set(spans)):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = right
    spaces = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        spaces.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': min(100, max((right - left for left, right in combined)))}
    output = dict()
    output.update(returnvalue)
    return output
f214([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

215

def f215(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(totals) if value >= limit and (limit >= 0 or pos > 0)]
    increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f215([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

216

def f216(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f216(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

217

def f217(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]
    ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f217([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

218

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

    def normalize(value):
        return ' '.join(str(value).split()).upper()[:12]
    banned = {normalize(value) for value in banned}
    a = {normalize(value) for value in left} - banned
    b = {normalize(value) for value in right if normalize(value) != ''} - banned
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f218(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

219

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

220

def f220(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in tallies.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f220(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

221

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

222

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

223

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

224

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

225

def f225(board):
    board = list(board)
    visited = set()
    regions = []
    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)
                        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
f225(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

226

def f226(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop or len(word) < 2:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in tallies.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f226(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

227

def f227(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    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()
    listing = []
    rounds = []
    while len(finished) < len(nodes):
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
        if not available:
            break
        current = available
        rounds.append(current)
        for node in current:
            finished.add(node)
            listing.append(node)
        for node in current:
            for nxt in children[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': listing, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output
f227(['cache', 'jobs', 'auth', 'db', 'worker', 'api', 'ui', 'proxy'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}

228

def f228(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
        if not result or left > result[-1][1] + gap + 1:
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    gaps = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        gaps.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f228([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

229

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

    def tidy(value):
        return str(value).strip(' \r').upper()
    ignored = {str(value).strip() 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((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f229(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

230

def f230(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, 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
f230([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

231

def f231(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        tallies[word] = min(9, tallies.get(word, 0) + 1)
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f231(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

232

def f232(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f232(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

233

def f233(board):
    board = list(board)
    found = 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 found:
                continue
            cells = []
            work = [(row, col)]
            found.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        work.append(nxt)
            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
f233(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

234

def f234(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] < min(limit, 3):
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    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
f234([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'C', 3)
{"count":7,"depth":{"A":3,"B":3,"C":0,"E":1,"F":1,"G":2,"H":2},"frontier":["A","B"],"order":["C","E","F","G","H","A","B"]}

235

def f235(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)
    steps = {start: 0} if any((start in edge for edge in edges)) else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < limit:
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    queue.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
f235([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'F', 3)
{"count":5,"depth":{"B":2,"D":3,"E":3,"F":0,"H":1},"frontier":["D","E"],"order":["F","H","B","D","E"]}

236

def f236(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)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output
f236([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'C', 3)
{"count":7,"depth":{"A":3,"B":3,"C":0,"E":1,"F":1,"G":2,"H":2},"frontier":["A","B"],"order":["C","E","F","G","H","A","B"]}

237

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

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

238

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

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

239

def f239(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop or len(word) < 2:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f239(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

240

def f240(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f240(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

241

def f241(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, 64)):
            x = max(-64, min(64, x + dx))
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in repeats:
                repeats.append(list(point))
            found.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f241([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2)])
{"bounds":[-8,-2,1,1],"end":[-4,1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":33}

242

def f242(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 if normalize(value) != ''} - ignored
    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(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

243

def f243(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 = []
            work = [(row, col)]
            found.add((row, col))
            while work:
                cur = work.pop()
                cells.append(cur)
                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nxt = (cur[0] + dr, cur[1] + dc)
                    if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
                        found.add(nxt)
                        if len(found) >= 100:
                            continue
                        work.append(nxt)
            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
f243(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

244

def f244(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(set(spans)):
        if not segments or left > segments[-1][1] + gap % 5 + 1:
            segments.append([left, right])
        else:
            segments[-1][1] = max(segments[-1][1], right)
    spaces = []
    for pos in range(1, len(segments)):
        left = segments[pos][0]
        spaces.append(left - segments[pos - 1][1])
    returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': max((right - left for left, right in segments))}
    output = dict()
    output.update(returnvalue)
    return output
f244([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

245

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

246

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

247

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

248

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

249

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

250

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

251

def f251(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)
    result = list(steps)
    lastlevel = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': result, 'depth': steps, 'frontier': lastlevel, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output
f251([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')], 'F', 3)
{"count":5,"depth":{"B":2,"D":3,"E":3,"F":0,"H":1},"frontier":["D","E"],"order":["F","H","B","D","E"]}

252

def f252(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} - 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
f252(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

253

def f253(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]
    increases = sum((1 for pos in range(1, min(65, len(series))) if series[pos] >= series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f253([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

254

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

255

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

256

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

257

def f257(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]
    ups = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
    returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f257([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

258

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

259

def f259(board):
    board = list(board)
    found = 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 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)
                        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
f259(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

260

def f260(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z' or (char == "'" and word):
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        tallies[word] = min(9, tallies.get(word, 0) + 1)
    sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in tallies.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f260(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

261

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

262

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

263

def f263(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + gap:
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    breaks = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        breaks.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f263([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

264

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

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

265

def f265(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop or len(word) < 2:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in tallies.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in tallies.items())))}
    output = dict()
    output.update(returnvalue)
    return output
f265(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

266

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

267

def f267(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in found and list(point) not in repeats:
                repeats.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': repeats[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output
f267([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1)])
{"bounds":[-8,-2,1,1],"end":[-3,-1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":32}

268

def f268(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += 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
f268([('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2), ('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1)])
{"bounds":[-8,-2,1,1],"end":[-3,-1],"far":9,"revisits":[[0,-2],[-1,-2],[-2,-2],[-2,0],[-7,1]],"steps":32}

269

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

270

def f270(board):
    board = list(board)
    visited = set()
    components = []
    for row in range(min(len(board), 10 + (len(board) - len(board)))):
        for col in range(len(board[0])):
            if 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
f270(['...#..', '#.###.', '#####.', '##..##', '#..#.#', '##..##'])
{"anchors":[[0,3],[4,3]],"count":2,"filled":21,"sizes":[20,1]}

271

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

272

def f272(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(windows) if value >= limit]
    ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output
f272([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

273

def f273(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(windows) 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([0] + windows), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f273([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

274

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

275

def f275(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
        if not combined or left > combined[-1][1] + max(0, gap):
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    spaces = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        spaces.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f275([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

276

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

277

def f277(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
        if not segments or left > segments[-1][1] + gap:
            segments.append([left, right])
        else:
            segments[-1][1] = max(segments[-1][1], right)
    spaces = []
    for pos in range(1, min(50, len(segments))):
        left = segments[pos][0]
        spaces.append(left - segments[pos - 1][1])
    returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': max((right - left for left, right in segments))}
    output = dict()
    output.update(returnvalue)
    return output
f277([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

278

def f278(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + gap:
            result.append([left, right])
        else:
            result[-1][1] = max(0, result[-1][1], right)
    gaps = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        gaps.append(min(100, left - result[pos - 1][1]))
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in result)))}
    output = dict()
    output.update(returnvalue)
    return output
f278([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

279

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

    def canon(value):
        return str(value).strip().upper()[:12]
    ignored = {str(value).upper() for value in ignored}
    a = {canon(value) for value in left} - ignored
    b = {canon(value) for value in right if canon(value) != ''} - ignored
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f279(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

280

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

    def tidy(value):
        return str(value).strip(' \r').upper()
    banned = {tidy(value) for value in banned}
    a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - banned
    b = {tidy(value) for value in right if tidy(value) != ''} - 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
f280(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

281

def f281(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {str(word) for word in stop}
    terms = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in wordmap.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f281(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

282

def f282(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]
    increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f282([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

283

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

284

def f284(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
    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
f284(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

285

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

    def normalize(value):
        return str(value).strip().upper()[:12]
    excluded = {str(value).upper() for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output
f285(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

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

287

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

288

def f288(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
        if not combined or left > combined[-1][1] + gap % 5:
            combined.append([left, right])
        else:
            combined[-1][1] = max(0, combined[-1][1], right)
    breaks = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        breaks.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f288([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

289

def f289(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = right
    gaps = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        gaps.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f289([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

290

def f290(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(set(spans)):
        if not combined or left > combined[-1][1] + gap + 1:
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    gaps = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        gaps.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
    output = dict()
    output.update(returnvalue)
    return output
f290([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

291

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

292

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

293

def f293(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    heads = {}
    for word, count in tallies.items():
        heads[word[0]] = heads.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f293(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

294

def f294(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + max(0, gap):
            result.append([left, right])
        else:
            result[-1][1] = right
    spaces = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        spaces.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': spaces, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f294([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

295

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

296

def f296(spans, gap):
    spans = list(spans)
    combined = []
    for left, right in sorted(set(spans)):
        if not combined or left > combined[-1][1] + gap:
            combined.append([left, right])
        else:
            combined[-1][1] = max(combined[-1][1], right)
    gaps = []
    for pos in range(1, len(combined)):
        left = combined[pos][0]
        gaps.append(left - combined[pos - 1][1])
    returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in combined)))}
    output = dict()
    output.update(returnvalue)
    return output
f296([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

297

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

298

def f298(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)
                        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
f298(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

299

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

    def tidy(value):
        return str(value).strip(' \r').upper()[:12]
    excluded = {tidy(value) for value in excluded}
    a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    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
f299(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

300

def f300(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(set(spans)):
        if not result or left > result[-1][1] + gap % 5:
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    gaps = []
    for pos in range(1, min(50, len(result))):
        left = result[pos][0]
        gaps.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f300([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

301

def f301(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(windows) 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': indexes, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output
f301([24, 11, 20, 16, 22, 6, 26, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":75,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":6,"sums":[71,69,64,70,73,71,75,64,67,55,65,74]}

302

def f302(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
        if not result or left > result[-1][1] + gap % 5:
            result.append([left, right])
        else:
            result[-1][1] = max(result[-1][1], right)
    gaps = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        gaps.append(min(100, left - result[pos - 1][1]))
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f302([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

303

def f303(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
    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
f303(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

304

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

305

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

    def normalize(value):
        return str(value).strip(' \n').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
    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
f305(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivory', 'GARNETx', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","GARNETX","HELIUM","IVORY"],"both":["BLUE","EMBER","IVORY"],"left":["GARNET","HELIUM"],"right":["AMBER","FROST","GARNETX"],"score":14}

306

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

307

def f307(board):
    board = list(board)
    visited = set()
    regions = []
    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)
            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
f307(['...#..', '#.###.', '#####.', '.#..##', '#..#..', '##..##'])
{"anchors":[[0,3],[4,0],[5,4],[4,3]],"count":4,"filled":19,"sizes":[13,3,2,1]}

308

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

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

309

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

310

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

311

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

312

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

    def normalize(value):
        return str(value).strip(' \n').upper()
    banned = {str(value).strip() for value in banned}
    a = {normalize(value) for value in left} - banned
    b = {normalize(value) for value in right} - banned
    both = a & b
    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
f312(['Ember', 'BLUE', 'helium', 'GARNET', 'ivory', 'cyan ', 'cyan '], ['BLUE', 'frost', ' Amber', 'ivoryx', 'GARNET', 'Ember', 'cyan '], ['CYAN'])
{"all":["AMBER","BLUE","EMBER","FROST","GARNET","HELIUM","IVORY","IVORYX"],"both":["BLUE","EMBER","GARNET"],"left":["HELIUM","IVORY"],"right":["AMBER","FROST","IVORYX"],"score":15}

313

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

314

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

315

def f315(spans, gap):
    spans = list(spans)
    segments = []
    for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
        if not segments or left > segments[-1][1] + gap:
            segments.append([left, right])
        else:
            segments[-1][1] = max(segments[-1][1], right)
    gaps = []
    for pos in range(1, len(segments)):
        left = segments[pos][0]
        gaps.append(min(100, left - segments[pos - 1][1]))
    returnvalue = {'segments': segments, 'cover': sum((min(100, right - left) for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
    output = dict()
    output.update(returnvalue)
    return output
f315([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 3)
{"cover":39,"holes":[6,8,4,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,54],[60,66]]}

316

def f316(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f316(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

317

def f317(spans, gap):
    spans = list(spans)
    result = []
    for left, right in sorted(spans):
        if not result or left > result[-1][1] + max(0, gap) + 1:
            result.append([left, right])
        else:
            result[-1][1] = max(0, result[-1][1], right)
    breaks = []
    for pos in range(1, len(result)):
        left = result[pos][0]
        breaks.append(left - result[pos - 1][1])
    returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
    output = dict()
    output.update(returnvalue)
    return output
f317([(3, 7), (6, 9), (15, 21), (19, 21), (29, 35), (34, 40), (44, 46), (49, 54), (60, 66)], 0)
{"cover":36,"holes":[6,8,4,3,6],"longest":11,"segments":[[3,9],[15,21],[29,40],[44,46],[49,54],[60,66]]}

318

def f318(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z' or (char == "'" and word):
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop:
            continue
        tallies[word] = min(9, tallies.get(word, 0) + 1)
    sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f318(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['cyan', 'delta'])
{"counts":{"amber":2,"blue":4,"ember":6,"frost":4,"garnet":2,"helium":3},"initials":{"a":2,"b":4,"e":6,"f":4,"g":2,"h":3},"size":106,"top":["ember","blue","frost","helium","amber"]}

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]))
    matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output
f319([24, 11, 20, 16, 27, 6, 24, 19, 20, 10, 15, 22, 8, 20, 24], 4, 64)
{"best":76,"hits":[0,1,2,3,4,5,6,7,8,10,11],"rises":7,"sums":[71,74,69,73,76,69,73,64,67,55,65,74]}

320

def f320(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output
f320(['Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan', 'Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'], ['helium', 'amber'])
{"counts":{"blue":4,"cyan":6,"delta":4,"ember":6,"frost":4,"garnet":2},"initials":{"b":4,"c":6,"d":4,"e":6,"f":4,"g":2},"size":122,"top":["cyan","ember","blue","delta","frost"]}

Final Query

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

import json, re
from collections import deque
out = {}
left = list(('Ember', 'BLUE', 'helium') + ('GARNET', 'ivory', 'cyan ', 'cyan '))
right = list(('BLUE', 'frost', ' Amber') + ('ivoryx', 'GARNET', 'Ember', 'cyan '))
blocked = ['CYAN']
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))}
badge = record['ee']
values = list((24, 11, 20, 16, 22, 6) + (26, 19, 20, 10, 15, 22, 8, 20, 24))
width = 4
limit = 64
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}
permit = record['bb']
lines = list(('Ember, ember. blue cyan', 'Delta, frost. blue ember frost', 'Cyan, helium. cyan amber', 'Garnet, ember. helium cyan cyan') + ('Frost, helium. garnet blue', 'Delta, amber. frost blue ember', 'Ember, cyan. delta delta'))
route = badge
cases = {
    14: list(('cyan',) + ('delta',)),
    15: list(('helium',) + ('amber',)),
}
stop = cases[route]
normalized = set()
for item in stop:
    normalized.add(item.lower())
stop = normalized
words = []
for line in lines:
    words.extend(re.findall('[a-z]+', line.lower()))
words = [word for word in words if word not in stop]
counts = {}
initials = {}
for word in words:
    counts[word] = counts.get(word, 0) + 1
    initials[word[0]] = initials.get(word[0], 0) + 1
top = sorted(counts, key=lambda word: (-counts[word], word))[:5]
record = {'aa': top, 'bb': counts, 'cc': initials, 'dd': sum((len(word) for word in words))}
signal = record['dd']
spans = list(((3, 7), (6, 9), (15, 21), (19, 21)) + ((29, 35), (34, 40), (44, 46), (49, 54), (60, 66)))
route = permit
cases = {
    75: 0,
    76: 3,
}
gap = cases[route]
spans.sort(key=lambda pair: (pair[0], pair[1]))
parts = []
pos = 0
while pos < len(spans):
    left, right = spans[pos]
    pos += 1
    while pos < len(spans) and spans[pos][0] <= right + gap:
        right = max(right, spans[pos][1])
        pos += 1
    parts.append([left, right])
holes = [parts[pos][0] - parts[pos - 1][1] for pos in range(1, len(parts))]
record = {'aa': parts, 'bb': holes, 'cc': sum((part[1] - part[0] for part in parts)), 'dd': max((part[1] - part[0] for part in parts))}
token = record['cc']
route = (badge, permit)
cases = {
    (14, 76): list((('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2)) + (('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2))),
    (14, 75): list((('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2)) + (('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2))),
    (15, 76): list((('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2)) + (('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('N', 2))),
    (15, 75): list((('S', 2), ('E', 1), ('W', 3), ('E', 1), ('W', 3), ('N', 2), ('E', 2)) + (('S', 1), ('N', 2), ('W', 3), ('W', 3), ('E', 3), ('E', 1), ('S', 3), ('N', 1), ('E', 1))),
}
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}
memo = record['ee']
edges = list((('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G')) + (('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B')))
limit = 3
route = (signal, memo)
cases = {
    (122, 32): 'C',
    (122, 33): 'F',
    (106, 32): 'F',
    (106, 33): 'F',
}
start = 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)}
clue = record['dd']
route = (token, clue)
cases = {
    (39, 5): list(('...#..', '#.###.', '#####.') + ('##..##', '#..#.#', '##..##')),
    (39, 7): list(('...#..', '#.###.', '#####.') + ('##..##', '#..#.#', '##..##')),
    (36, 5): list(('...#..', '#.###.', '#####.') + ('##..##', '#..#.#', '##..##')),
    (36, 7): list(('...#..', '#.###.', '#####.') + ('.#..##', '#..#..', '##..##')),
}
board = cases[route]
cells = [(row, col) for row in range(len(board)) for col in range(len(board[row])) if board[row][col] == '#']
parent = {cell: cell for cell in cells}

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

def merge(a, b):
    a = root(a)
    b = root(b)
    if a != b:
        parent[b] = a
for row, col in cells:
    for other in ((row - 1, col), (row, col - 1)):
        if other in parent:
            merge((row, col), other)
groups = {}
for cell in cells:
    groups.setdefault(root(cell), []).append(cell)
parts = [(len(group), min(group)) for group in groups.values()]
parts.sort(key=lambda item: (-item[0], item[1]))
record = {'aa': [part[0] for part in parts], 'bb': [list(part[1]) for part in parts], 'cc': len(cells), 'dd': len(parts)}
stamp = record['cc']
nodes = list(('cache', 'jobs', 'auth') + ('db', 'worker', 'api', 'ui', 'proxy'))
route = stamp
cases = {
    19: list((('auth', 'api'), ('db', 'api'), ('cache', 'api')) + (('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('db', 'auth'))),
    21: list((('auth', 'api'), ('db', 'api'), ('cache', 'api')) + (('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('proxy', 'ui'), ('cache', 'db'))),
}
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)}
out['aa'] = record['aa']
out['bb'] = record['bb']
out['cc'] = record['cc']
out['dd'] = record['dd']
print(json.dumps(out, separators=(",", ":"), sort_keys=True))