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

001

def f1(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value >= limit]
    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

Example call:

f1([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

002

def f2(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * prices[group]
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f2([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

003

def f3(nodes, edges):
    nodes = list(nodes)
    needs = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        nextmap[a].append(b)
        needs[b] += 1
    initial = dict(needs)
    finished = set()
    result = []
    groups = []
    while len(finished) < len(nodes) and len(finished) < 20:
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in finished))
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            finished.add(node)
            result.append(node)
        for node in current:
            for nxt in nextmap[node]:
                needs[nxt] -= 1
    returnvalue = {'order': result, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f3(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

004

def f4(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        routes.setdefault(a, []).append(b)
    steps = {start: 0} if limit > 0 or limit < 0 else {}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    pending.append(nxt)
    result = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': result, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f4([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

005

def f5(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < 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)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': listing, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f5([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

006

def f6(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices or rate0 <= rate0 + 0:
            prices[name0] = rate0
    matched = []
    for key, count in left:
        if key in prices and count > 0:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f6([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

007

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

    def normalize(value):
        return str(value).strip().upper()
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f7(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

008

def f8(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 or len(word) < 2:
            continue
        tallies[word] = min(9, tallies.get(word, 0) + 1)
    ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f8(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

009

def f9(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(totals) if value >= limit]
    increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f9([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

010

def f10(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(totals) if value >= limit]
    growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f10([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

011

def f11(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 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

Example call:

f11([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

012

def f12(rows, keep, factors):
    rows = list(rows)
    kept = []
    groupmap = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * factors[group]
            kept.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            grand += cost
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': groupmap, 'top': list(dict.fromkeys((code for code, cost in kept)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f12([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

013

def f13(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            cost = value * prices[group]
            selected.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f13([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

014

def f14(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep:
            cost = value * factors[group]
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            grand += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f14([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

015

def f15(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 % 100):
            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

Example call:

f15([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

016

def f16(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep:
            charge = value * prices[group]
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f16([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

017

def f17(rows, keep, prices):
    rows = list(rows)
    matches = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * abs(prices[group])
            matches.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            sumvalue += cost
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f17([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

018

def f18(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    items = []
    for key, count in left[:20]:
        if key in ratemap:
            items.append((key, count * ratemap[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len({key for key, value in items})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f18([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

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:
        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, min(20, abs(x) + abs(y)))
            lowx, highx = (max(-64, min(lowx, x)), min(64, max(highx, x)))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f19([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

020

def f20(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * prices[group]
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            grand += cost
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': grand, 'groups': totals, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f20([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

021

def f21(rows, keep, factors):
    rows = list(rows)
    matches = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * factors[group]
            matches.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            amount += cost
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': amount, 'groups': groupmap, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f21([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

022

def f22(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    positions = [pos for pos, value in enumerate(windows) if value >= limit]
    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

Example call:

f22([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

023

def f23(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    indegree = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        children[a].append(b)
        indegree[b] += 1
    initial = dict(indegree)
    finished = set()
    result = []
    groups = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
        if not nextbatch:
            break
        current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        groups.append(current)
        for node in current:
            finished.add(node)
            result.append(node)
        for node in current:
            for nxt in children[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': result, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f23(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

024

def f24(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

Example call:

f24(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

025

def f25(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    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

Example call:

f25(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

026

def f26(rows, keep, factors):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            charge = value * abs(factors[group])
            selected.append((code, charge))
            buckets[group] = buckets.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, charge in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f26([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

027

def f27(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in found and list(point) not in returns:
                returns.append(list(point))
            found.add(point)
            far = 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

Example call:

f27([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

028

def f28(rows, keep, prices):
    rows = list(rows)
    kept = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            charge = value * abs(prices[group])
            kept.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, charge in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f28([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

029

def f29(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]
    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

Example call:

f29([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

030

def f30(rows, keep, prices):
    rows = list(rows)
    matches = []
    totals = {}
    amount = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep and value != 0:
            cost = value * prices[group]
            matches.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': amount, 'groups': totals, 'top': list(dict.fromkeys((code for code, cost in matches)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f30([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

031

def f31(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((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(totals) if value >= limit]
    ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': indexes, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f31([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

032

def f32(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors:
            factors[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in factors:
            matched.append((key, count * factors[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted({key for key, count in left if key not in factors})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f32([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

033

def f33(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 (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    result = list(distance)
    edge = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': result, 'depth': distance, 'frontier': edge, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f33([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

034

def f34(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 {}
    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)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': listing, 'depth': distance, 'frontier': furthest[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f34([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

035

def f35(rows, keep, ratemap):
    rows = list(rows)
    matches = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * abs(ratemap[group])
            matches.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            sumvalue += cost
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': sumvalue, 'groups': buckets, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f35([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

036

def f36(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap or rate0 <= rate0 + 0:
            ratemap[name0] = rate0
    matched = []
    for key, count in left:
        if key in ratemap:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in ratemap})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f36([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

037

def f37(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    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

Example call:

f37(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

038

def f38(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges:
        routes.setdefault(a, []).append(b)
    distance = {start: 0} if any((start in edge for edge in edges)) else {}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < 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)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': result, 'depth': distance, 'frontier': furthest[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f38([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

039

def f39(rows, keep, prices):
    rows = list(rows)
    kept = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * prices[group]
            kept.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            sumvalue += cost
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': sumvalue, 'groups': buckets, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f39([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

040

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

    def canon(value):
        return ' '.join(str(value).split()).upper()
    excluded = {str(value).strip() for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f40(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

041

def f41(rows, keep, ratemap):
    rows = list(rows)
    kept = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            score = value * ratemap[group]
            kept.append((code, score))
            totals[group] = totals.get(group, 0) + score
            grand += score
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': totals, 'top': list(dict.fromkeys((code for code, score in kept)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f41([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

042

def f42(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        routes[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    complete = set()
    result = []
    layers = []
    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
        layers.append(current)
        for node in current:
            complete.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 rootsource[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f42(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

043

def f43(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

Example call:

f43([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

044

def f44(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(series) if value >= limit and (limit >= 0 or pos > 0)]
    increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f44([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

045

def f45(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    positions = [pos for pos, value in enumerate(windows) if value >= limit]
    growth = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': positions, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f45([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

046

def f46(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f46([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

047

def f47(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)
    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))
        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]:
                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

Example call:

f47(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

048

def f48(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):
            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 = (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

Example call:

f48([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

049

def f49(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        routes[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    handled = set()
    sequence = []
    layers = []
    while len(handled) < len(nodes):
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            handled.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[node]:
                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

Example call:

f49(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

050

def f50(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
    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

Example call:

f50(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

051

def f51(nodes, edges):
    nodes = list(nodes)
    needs = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        nextmap[a].append(b)
        needs[b] += 1
    initial = dict(needs)
    complete = set()
    sequence = []
    groups = []
    while len(complete) < len(nodes):
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in nextmap[node]:
                needs[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f51(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

052

def f52(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()
    listing = []
    groups = []
    while len(complete) < len(nodes):
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
        if not available:
            break
        current = available[:1] if any((str(node).isupper() for node in nodes)) else available
        groups.append(current)
        for node in current:
            complete.add(node)
            listing.append(node)
        for node in current:
            for nxt in nextmap[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f52(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

053

def f53(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0} if limit > 0 or limit < 0 else {}
    pending = [start]
    while pending:
        cur = pending.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
                    pending.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

Example call:

f53([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

054

def f54(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 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

Example call:

f54(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

055

def f55(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges[:16]:
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(children.get(cur, [])):
                if nxt not in distance and (not nxt.startswith('Z')):
                    distance[nxt] = distance[cur] + 1
                    pending.append(nxt)
    sequence = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f55([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

056

def f56(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

Example call:

f56(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

057

def f57(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 or len(word) < 2:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f57(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

058

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

    def normalize(value):
        return str(value).strip(' \r').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
    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

Example call:

f58(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

059

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

    def normalize(value):
        return str(value).strip(' \r').upper()
    ignored = {str(value).strip() for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right} - ignored
    both = a & b
    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

Example call:

f59(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

060

def f60(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(min(count, 3 + (count - count))):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in repeats:
                repeats.append(list(point))
            visited.add(point)
            far = max(far, 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

Example call:

f60([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

061

def f61(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap or rate0 <= rate0 + 0:
            ratemap[name0] = rate0
    matched = []
    for key, count in left:
        if key in ratemap:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f61([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

062

def f62(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 += 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

Example call:

f62([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

063

def f63(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, []))[:20]:
                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

Example call:

f63([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

064

def f64(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    incoming = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        nextmap[a].append(b)
        incoming[b] += 1
    startdegree = dict(incoming)
    finished = set()
    sequence = []
    rounds = []
    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
        rounds.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in nextmap[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f64(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

065

def f65(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(series) if value >= limit]
    ups = 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': ups}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f65([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

066

def f66(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in 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

Example call:

f66([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

067

def f67(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, 64)):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (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

Example call:

f67([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

068

def f68(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value > limit]
    growth = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f68([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

069

def f69(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(totals) if value >= limit]
    growth = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': indexes, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f69([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

070

def f70(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    result = list(levels)
    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

Example call:

f70([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

071

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

    def canon(value):
        return str(value).strip(' \n').upper()
    excluded = {canon(value) for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f71(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

072

def f72(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges[:16]:
        children.setdefault(a, []).append(b)
    levels = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    pending.append(nxt)
    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

Example call:

f72([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

073

def f73(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    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

Example call:

f73(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

074

def f74(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices and rate0 != 0:
            prices[name0] = rate0
    items = []
    for key, count in left:
        if key in prices:
            items.append((key, count * prices[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f74([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

075

def f75(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:
        a, b = (before, after)
        routes[a].append(b)
        needs[b] += 1
    startdegree = dict(needs)
    handled = set()
    result = []
    rounds = []
    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[:1] if any((str(node).isupper() for node in nodes)) else available
        rounds.append(current)
        for node in current:
            handled.add(node)
            result.append(node)
        for node in current:
            for nxt in routes[node]:
                needs[nxt] -= 1
    returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f75(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

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)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, 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

Example call:

f76([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

077

def f77(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:
        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

Example call:

f77(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

078

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

Example call:

f78([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

079

def f79(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': max(windows), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f79([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

080

def f80(rows, keep, prices):
    rows = list(rows)
    matches = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * prices[group]
            matches.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            amount += cost
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': buckets, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f80([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

081

def f81(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    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

Example call:

f81([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

082

def f82(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f82([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

083

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

    def canon(value):
        return str(value).strip(' \r').upper()
    excluded = {canon(value) for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f83(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

084

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

    def normalize(value):
        return ' '.join(str(value).split()).upper()
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f84(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

085

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

    def normalize(value):
        return str(value).strip(' \n').upper()
    ignored = {normalize(value) for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right if normalize(value) != ''} - ignored
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f85(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

086

def f86(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f86([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

087

def f87(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        children.setdefault(a, []).append(b)
    steps = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < min(limit, 3):
            for nxt in sorted(children.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

Example call:

f87([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

088

def f88(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors and rate0 != 0:
            factors[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in factors:
            matched.append((key, count * factors[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in factors})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f88([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

089

def f89(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors:
            factors[name0] = rate0
    items = []
    for key, count in left[:20]:
        if key in factors and count > 0:
            items.append((key, count * factors[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f89([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

090

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

Example call:

f90([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

091

def f91(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in tallies.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f91(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

092

def f92(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    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

Example call:

f92(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

093

def f93(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    needs = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        children[a].append(b)
        needs[b] += 1
    rootsource = dict(needs)
    finished = set()
    result = []
    layers = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in finished))
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            finished.add(node)
            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 rootsource[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f93(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

094

def f94(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
    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

Example call:

f94(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

095

def f95(rows, keep, factors):
    rows = list(rows)
    kept = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep} and value >= 0:
            cost = value * factors[group]
            kept.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f95([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

096

def f96(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in repeats:
                repeats.append(list(point))
            visited.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (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

Example call:

f96([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

097

def f97(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, 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

Example call:

f97([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

098

def f98(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        children.setdefault(a, []).append(b)
    steps = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < 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)
    result = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': result, 'depth': steps, 'frontier': furthest[:3], 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f98([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

099

def f99(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]
    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

Example call:

f99([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

100

def f100(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    combined = []
    for key, count in left:
        if key in ratemap:
            combined.append((key, count * ratemap[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    unmatched = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': unmatched, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f100([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

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]))
    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

Example call:

f101([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

102

def f102(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        routes[a].append(b)
        incoming[b] += 1
    initial = dict(incoming)
    handled = set()
    listing = []
    groups = []
    while len(handled) < len(nodes):
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        groups.append(current)
        for node in current:
            handled.add(node)
            listing.append(node)
        for node in current:
            for nxt in routes[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f102(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

103

def f103(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit and (limit >= 0 or pos > 0)]
    ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f103([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

104

def f104(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        children[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    handled = set()
    listing = []
    layers = []
    while len(handled) < len(nodes):
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
        if not nextbatch:
            break
        current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        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 rootsource[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f104(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

105

def f105(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * abs(factors[group])
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f105([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

106

def f106(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    items = []
    for key, count in left[:20]:
        if key in ratemap:
            items.append((key, count * ratemap[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f106([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

107

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

    def tidy(value):
        return str(value).strip().upper()
    ignored = {str(value).strip() 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} - 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

Example call:

f107(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

108

def f108(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f108([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

109

def f109(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
    initial = dict(incoming)
    complete = set()
    result = []
    rounds = []
    while len(complete) < len(nodes) and len(complete) < 20:
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        rounds.append(current)
        for node in current:
            complete.add(node)
            result.append(node)
        for node in current:
            for nxt in routes[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f109(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

110

def f110(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f110([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

111

def f111(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep:
            charge = value * abs(ratemap[group])
            selected.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': groupmap, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f111([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

112

def f112(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

Example call:

f112([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

113

def f113(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)
    complete = set()
    result = []
    layers = []
    while len(complete) < len(nodes) and len(complete) < 20:
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        layers.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': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f113(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

114

def f114(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        nextmap[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    handled = set()
    result = []
    groups = []
    while len(handled) < len(nodes) and len(handled) < 20:
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            handled.add(node)
            result.append(node)
        for node in current:
            for nxt in nextmap[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': result, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f114(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

115

def f115(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        nextmap.setdefault(a, []).append(b)
    steps = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    sequence = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f115([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

116

def f116(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in repeats:
                repeats.append(list(point))
            found.add(point)
            far = max(far, min(20, abs(x) + abs(y)))
            lowx, highx = (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

Example call:

f116([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

117

def f117(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
    indexes = [pos for pos, value in enumerate(totals[:64]) if value >= limit]
    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

Example call:

f117([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

118

def f118(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 3 + (count - count))):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in repeats:
                repeats.append(list(point))
            found.add(point)
            far = 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

Example call:

f118([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

119

def f119(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value >= limit]
    growth = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f119([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

120

def f120(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
    startdegree = dict(needs)
    finished = set()
    listing = []
    layers = []
    while len(finished) < len(nodes) and len(finished) < 20:
        available = sorted((node for node in nodes if needs[node] == 0 and node not in finished), reverse=len(nodes) > 20)
        if not available:
            break
        current = available
        layers.append(current)
        for node in current:
            finished.add(node)
            listing.append(node)
        for node in current:
            for nxt in routes[node]:
                needs[nxt] -= 1
    returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f120(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

121

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

    def tidy(value):
        return ' '.join(str(value).split()).upper()
    excluded = {tidy(value) for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - 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

Example call:

f121(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

122

def f122(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    matched = []
    for key, count in left:
        if key in ratemap and count > 0:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted({key for key, count in left if key not in ratemap})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f122([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

123

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

    def tidy(value):
        return ' '.join(str(value).split()).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

Example call:

f123(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

124

def f124(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
    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

Example call:

f124(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

125

def f125(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
    initial = dict(incoming)
    complete = set()
    sequence = []
    groups = []
    while len(complete) < len(nodes):
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f125(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

126

def f126(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} - ignored
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f126(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

127

def f127(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 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

Example call:

f127(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

128

def f128(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += dy
            used = 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

Example call:

f128([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

129

def f129(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f129([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

130

def f130(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        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)
    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

Example call:

f130([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

131

def f131(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < limit:
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    pending.append(nxt)
    sequence = list(distance)
    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

Example call:

f131([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

132

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

    def normalize(value):
        return str(value).strip(' \r').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f132(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

133

def f133(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
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f133(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

134

def f134(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
    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

Example call:

f134(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

135

def f135(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f135([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

136

def f136(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] < min(limit, 3):
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    pending.append(nxt)
    sequence = list(levels)
    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

Example call:

f136([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

137

def f137(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = 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

Example call:

f137([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

138

def f138(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, 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

Example call:

f138([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

139

def f139(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

Example call:

f139([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

140

def f140(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
    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

Example call:

f140(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

141

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

    def normalize(value):
        return str(value).strip(' ').upper()[:12]
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right if normalize(value) != ''} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f141(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

142

def f142(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in prices and count > 0:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f142([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

143

def f143(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 or len(word) > 12:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f143(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

144

def f144(lines, stop):
    lines = list(lines)
    wordmap = {}
    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 or len(word) < 2:
            continue
        wordmap[word] = min(9, 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

Example call:

f144(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

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[: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

Example call:

f145([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

146

def f146(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop or len(word) < 2:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f146(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

147

def f147(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value >= limit]
    increases = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f147([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

148

def f148(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] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f148(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

149

def f149(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        routes[a].append(b)
        incoming[b] += 1
    startdegree = dict(incoming)
    complete = set()
    sequence = []
    layers = []
    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=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in routes[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f149(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

150

def f150(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in found and list(point) not in repeats:
                repeats.append(list(point))
            found.add(point)
            far = max(far, 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

Example call:

f150([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

151

def f151(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items[:64]:
        if word in stop or len(word) > 12:
            continue
        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

Example call:

f151(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

152

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

    def canon(value):
        return str(value).strip(' ').upper()
    ignored = {str(value).upper() for value in ignored}
    a = {canon(value) for value in left} - ignored
    b = {canon(value) for value in right} - ignored
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f152(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

153

def f153(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
    rootsource = dict(indegree)
    handled = set()
    sequence = []
    layers = []
    while len(handled) < len(nodes) and len(handled) < 20:
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in handled), reverse=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 routes[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f153(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

154

def f154(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    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

Example call:

f154(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

155

def f155(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] = min(9, 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': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f155(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

156

def f156(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices or rate0 <= rate0 + 0:
            prices[name0] = rate0
    items = []
    for key, count in left[:20]:
        if key in prices:
            items.append((key, count * prices[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    unmatched = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': unmatched, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f156([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

157

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

    def normalize(value):
        return str(value).strip().upper()[:12]
    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((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f157(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

158

def f158(rows, keep, factors):
    rows = list(rows)
    matches = []
    groupmap = {}
    grand = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * factors[group]
            matches.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            grand += cost
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': grand, 'groups': groupmap, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f158([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

159

def f159(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f159(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

160

def f160(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
    growth = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f160([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

161

def f161(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    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

Example call:

f161([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

162

def f162(rows, keep, factors):
    rows = list(rows)
    matches = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * factors[group]
            matches.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            sumvalue += cost
    matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(matches), 'total': sumvalue, 'groups': groupmap, 'top': list(dict.fromkeys((code for code, cost in matches)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f162([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

163

def f163(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0} if any((start in edge for edge in edges)) else {}
    work = [start]
    while work:
        cur = work.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in distance and (not nxt.startswith('Z')):
                    distance[nxt] = distance[cur] + 1
                    work.append(nxt)
    sequence = list(distance)
    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

Example call:

f163([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

164

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

Example call:

f164([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

165

def f165(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    items = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z' or (char == "'" and word):
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in frequency.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f165(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

166

def f166(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
    rootsource = dict(indegree)
    finished = set()
    sequence = []
    groups = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), 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)
            sequence.append(node)
        for node in current:
            for nxt in routes[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f166(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

167

def f167(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[:64]:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f167(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

168

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

    def normalize(value):
        return ' '.join(str(value).split()).upper()
    excluded = {normalize(value) for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right if normalize(value) != ''} - excluded
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f168(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

169

def f169(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) and len(finished) < 20:
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
        if not nextbatch:
            break
        current = nextbatch
        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

Example call:

f169(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

170

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

    def tidy(value):
        return str(value).strip(' ').upper()
    excluded = {str(value).strip() for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    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

Example call:

f170(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

171

def f171(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        nextmap[a].append(b)
        incoming[b] += 1
    rootsource = dict(incoming)
    finished = set()
    listing = []
    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))
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            finished.add(node)
            listing.append(node)
        for node in current:
            for nxt in nextmap[node]:
                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

Example call:

f171(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

172

def f172(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 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': min(256, max(totals)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f172([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

173

def f173(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    indegree = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        children[a].append(b)
        indegree[b] += 1
    initial = dict(indegree)
    finished = set()
    result = []
    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), reverse=any((str(node).isupper() for node in nodes)))
        if not nextbatch:
            break
        current = nextbatch
        rounds.append(current)
        for node in current:
            finished.add(node)
            result.append(node)
        for node in current:
            for nxt in children[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f173(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

174

def f174(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            charge = value * prices[group]
            selected.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            sumvalue += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f174([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

175

def f175(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap or rate0 <= rate0 + 0:
            ratemap[name0] = rate0
    items = []
    for key, count in left:
        if key in ratemap:
            items.append((key, count * ratemap[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in ratemap})
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f175([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

176

def f176(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
    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

Example call:

f176(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

177

def f177(rows, keep, factors):
    rows = list(rows)
    selected = []
    buckets = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(factors[group])
            selected.append((code, charge))
            buckets[group] = buckets.get(group, 0) + charge
            grand += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': grand, 'groups': buckets, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f177([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

178

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

Example call:

f178([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

179

def f179(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y += 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

Example call:

f179([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

180

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

    def canon(value):
        return ' '.join(str(value).split()).upper()
    excluded = {str(value).upper() for value in excluded}
    a = {canon(value) for value in left} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f180(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

181

def f181(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += 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 = 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

Example call:

f181([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

182

def f182(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * prices[group]
            selected.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            grand += cost
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': grand, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f182([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

183

def f183(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * prices[group]
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            sumvalue += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f183([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

184

def f184(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(values[pos:pos + size]))
    positions = [pos for pos, value in enumerate(series[:64]) if value >= limit]
    ups = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max([0] + series), 'hits': positions, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f184([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

185

def f185(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * prices[group]
            selected.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            grand += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': groupmap, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f185([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

186

def f186(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value >= limit]
    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

Example call:

f186([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

187

def f187(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
    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

Example call:

f187(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

188

def f188(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    indegree = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        nextmap[a].append(b)
        indegree[b] += 1
    startdegree = dict(indegree)
    complete = set()
    sequence = []
    layers = []
    while len(complete) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in complete))
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in nextmap[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f188(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

189

def f189(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap and rate0 != 0:
            ratemap[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in ratemap:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f189([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

190

def f190(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in repeats:
                repeats.append(list(point))
            visited.add(point)
            far = max(far, 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

Example call:

f190([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

191

def f191(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    positions = [pos for pos, value in enumerate(windows) if value >= limit]
    ups = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': positions, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f191([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

192

def f192(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} - 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

Example call:

f192(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

193

def f193(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[:64]:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f193(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

194

def f194(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices or rate0 <= rate0 + 0:
            prices[name0] = rate0
    items = []
    for key, count in left:
        if key in prices:
            items.append((key, count * prices[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len({key for key, value in items})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f194([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

195

def f195(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges[:16]:
        children.setdefault(a, []).append(b)
    steps = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < limit:
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps and (not nxt.startswith('Z')):
                    steps[nxt] = steps[cur] + 1
                    work.append(nxt)
    sequence = list(steps)
    lastlevel = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': lastlevel, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f195([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

196

def f196(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors:
            factors[name0] = rate0
    combined = []
    for key, count in left:
        if key in factors:
            combined.append((key, count * factors[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': leftover, 'count': len(combined)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f196([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

197

def f197(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[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f197([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

198

def f198(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[: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]))
    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

Example call:

f198(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

199

def f199(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)
    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

Example call:

f199(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

200

def f200(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    starts = {}
    for word, count in frequency.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f200(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

201

def f201(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        children.setdefault(a, []).append(b)
    levels = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in sorted(children.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    pending.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

Example call:

f201([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

202

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

    def canon(value):
        return str(value).strip().upper()[:12]
    ignored = {canon(value) 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((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f202(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

203

def f203(rows, keep, factors):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * factors[group]
            selected.append((code, score))
            buckets[group] = buckets.get(group, 0) + score
            amount += score
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, score in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f203([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

204

def f204(nodes, edges):
    nodes = list(nodes)
    incoming = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        nextmap[a].append(b)
        incoming[b] += 1
    startdegree = dict(incoming)
    handled = set()
    sequence = []
    groups = []
    while len(handled) < len(nodes) 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

Example call:

f204(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

205

def f205(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    totals = []
    for pos in range(min(64, len(values) - size + 1)):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals) if value > limit]
    growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f205([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

206

def f206(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    combined = []
    for key, count in left[:20]:
        if key in prices and count > 0:
            combined.append((key, count * prices[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len(combined)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f206([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

207

def f207(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

Example call:

f207([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

208

def f208(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    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

Example call:

f208([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

209

def f209(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices:
            prices[name0] = rate0
    combined = []
    for key, count in left:
        if key in prices:
            combined.append((key, count * prices[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f209([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

210

def f210(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f210([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

211

def f211(rows, keep, prices):
    rows = list(rows)
    matches = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep and value != 0:
            charge = value * abs(prices[group])
            matches.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            sumvalue += charge
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, charge in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f211([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

212

def f212(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 3 + (count - count))):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in returns:
                returns.append(list(point))
            known.add(point)
            far = max(far, 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

Example call:

f212([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

213

def f213(rows, keep, factors):
    rows = list(rows)
    kept = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            charge = value * abs(factors[group])
            kept.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, charge in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f213([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

214

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

    def canon(value):
        return str(value).strip().upper()
    ignored = {canon(value) for value in ignored}
    a = {canon(value) for value in left} - ignored
    b = {canon(value) for value in right} - ignored
    both = a & b
    listing = sorted
    returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f214(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

215

def f215(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        children[a].append(b)
        indegree[b] += 1
    initial = dict(indegree)
    finished = set()
    result = []
    layers = []
    while len(finished) < len(nodes) and len(finished) < 20:
        available = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
        if not available:
            break
        current = available
        layers.append(current)
        for node in current:
            finished.add(node)
            result.append(node)
        for node in current:
            for nxt in children[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f215(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

216

def f216(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        wordmap[word] = min(9, 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

Example call:

f216(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

217

def f217(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        routes.setdefault(a, []).append(b)
    levels = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    pending.append(nxt)
    sequence = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': sequence, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f217([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

218

def f218(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * ratemap[group]
            selected.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            sumvalue += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f218([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

219

def f219(rows, keep, factors):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep and value != 0:
            score = value * factors[group]
            selected.append((code, score))
            groupmap[group] = groupmap.get(group, 0) + score
            amount += score
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': groupmap, 'top': [code for code, score in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f219([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

220

def f220(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:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f220(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

221

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

    def tidy(value):
        return str(value).strip().upper()
    excluded = {str(value).strip() for value in excluded}
    a = {tidy(value) for value in left} - excluded
    b = {tidy(value) for value in right} - excluded
    both = a & b
    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

Example call:

f221(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

222

def f222(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    combined = []
    for key, count in left:
        if key in prices:
            combined.append((key, count * prices[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f222([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

223

def f223(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(windows) if value >= limit]
    ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f223([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

224

def f224(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 = 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

Example call:

f224([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

225

def f225(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices:
            prices[name0] = rate0
    items = []
    for key, count in left:
        if key in prices and count > 0:
            items.append((key, count * prices[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    unmatched = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': unmatched, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f225([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

226

def f226(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(prices[group])
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f226([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

227

def f227(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((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f227(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

228

def f228(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        children[a].append(b)
        indegree[b] += 1
    initial = dict(indegree)
    finished = set()
    listing = []
    layers = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            finished.add(node)
            listing.append(node)
        for node in current:
            for nxt in children[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f228(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

229

def f229(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))
        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

Example call:

f229(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

230

def f230(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    matched = []
    for key, count in left:
        if key in ratemap and count > 0:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f230([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

231

def f231(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(series[:64]) if value >= limit]
    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

Example call:

f231([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

232

def f232(rows, keep, factors):
    rows = list(rows)
    matches = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * factors[group]
            matches.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': amount, 'groups': totals, 'top': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f232([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

233

def f233(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    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

Example call:

f233([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

234

def f234(rows, keep, prices):
    rows = list(rows)
    kept = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            cost = value * prices[group]
            kept.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            amount += cost
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': buckets, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f234([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

235

def f235(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (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

Example call:

f235([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

236

def f236(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
    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

Example call:

f236(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

237

def f237(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 = []
    rounds = []
    while len(handled) < len(nodes) and len(handled) < 20:
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
        if not nextbatch:
            break
        current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
        rounds.append(current)
        for node in current:
            handled.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                incoming[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f237(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

238

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

    def tidy(value):
        return ' '.join(str(value).split()).upper()[:12]
    banned = {tidy(value) for value in banned}
    a = {tidy(value) for value in left} - banned
    b = {tidy(value) for value in right} - banned
    both = a & b
    result = sorted
    returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f238(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

239

def f239(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
    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

Example call:

f239(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

240

def f240(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
    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))
        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]:
                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

Example call:

f240(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

241

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

    def normalize(value):
        return str(value).strip(' ').upper()
    excluded = {str(value).upper() for value in excluded}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    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

Example call:

f241(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

242

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

    def tidy(value):
        return str(value).strip(' \n').upper()
    banned = {str(value).upper() for value in banned}
    a = {tidy(value) for value in left} - banned
    b = {tidy(value) for value in right} - banned
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f242(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

243

def f243(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        children.setdefault(a, []).append(b)
    distance = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            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

Example call:

f243([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

244

def f244(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    nextmap = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        nextmap[a].append(b)
        indegree[b] += 1
    startdegree = dict(indegree)
    handled = set()
    sequence = []
    groups = []
    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
        groups.append(current)
        for node in current:
            handled.add(node)
            sequence.append(node)
        for node in current:
            for nxt in nextmap[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f244(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

245

def f245(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 or len(word) > 12:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in tallies.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f245(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

246

def f246(rows, keep, factors):
    rows = list(rows)
    kept = []
    totals = {}
    sumvalue = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep and value >= 0:
            cost = value * factors[group]
            kept.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            sumvalue += cost
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f246([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

247

def f247(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        if name0 not in ratemap and rate0 != 0:
            ratemap[name0] = rate0
    matched = []
    for key, count in left:
        if key in ratemap:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in ratemap})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f247([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

248

def f248(rows, keep, factors):
    rows = list(rows)
    selected = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * abs(factors[group])
            selected.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            sumvalue += cost
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': buckets, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f248([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

249

def f249(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, 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

Example call:

f249([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

250

def f250(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, 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

Example call:

f250([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

251

def f251(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * prices[group]
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f251([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

252

def f252(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    items = []
    for key, count in left:
        if key in ratemap:
            items.append((key, count * ratemap[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f252([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

253

def f253(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value > limit]
    increases = sum((1 for pos in range(1, 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

Example call:

f253([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

254

def f254(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    combined = []
    for key, count in left:
        if key in prices:
            combined.append((key, count * prices[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len(combined)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f254([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

255

def f255(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors and rate0 != 0:
            factors[name0] = rate0
    matched = []
    for key, count in left:
        if key in factors:
            matched.append((key, count * factors[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted({key for key, count in left if key not in factors})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f255([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

256

def f256(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        routes.setdefault(a, []).append(b)
    levels = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in (node for node in sorted(routes.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    work.append(nxt)
    listing = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': listing, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f256([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

257

def f257(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    indegree = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        children[a].append(b)
        indegree[b] += 1
    startdegree = dict(indegree)
    complete = set()
    listing = []
    layers = []
    while len(complete) < len(nodes):
        available = sorted((node for node in nodes if indegree[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
        if not available:
            break
        current = available
        layers.append(current)
        for node in current:
            complete.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

Example call:

f257(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

258

def f258(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[: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

Example call:

f258(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

259

def f259(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 and (not nxt.startswith('Z')):
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    sequence = list(steps)
    edge = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': edge, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f259([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

260

def f260(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right[:20]:
        if name0 not in prices:
            prices[name0] = rate0
    combined = []
    for key, count in left[:20]:
        if key in prices:
            combined.append((key, count * prices[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    unmatched = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': unmatched, 'count': len(combined)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f260([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

261

def f261(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    combined = []
    for key, count in left:
        if key in ratemap:
            combined.append((key, count * ratemap[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f261([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

262

def f262(rows, keep, factors):
    rows = list(rows)
    selected = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * factors[group]
            selected.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            sumvalue += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f262([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

263

def f263(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        nextmap.setdefault(a, []).append(b)
    steps = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < limit:
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    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

Example call:

f263([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

264

def f264(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, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f264([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

265

def f265(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)
    complete = set()
    sequence = []
    layers = []
    while len(complete) < len(nodes):
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
        if not available:
            break
        current = available
        layers.append(current)
        for node in current:
            complete.add(node)
            sequence.append(node)
        for node in current:
            for nxt in 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

Example call:

f265(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

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)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in repeats:
                repeats.append(list(point))
            visited.add(point)
            far = 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

Example call:

f266([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

267

def f267(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors:
            factors[name0] = rate0
    combined = []
    for key, count in left[:20]:
        if key in factors:
            combined.append((key, count * factors[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted({key for key, count in left if key not in factors})
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': leftover, 'count': len(combined)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f267([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

268

def f268(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    known = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 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

Example call:

f268([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

269

def f269(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)
    finished = set()
    sequence = []
    layers = []
    while len(finished) < len(nodes):
        nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
        if not nextbatch:
            break
        current = nextbatch
        layers.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in nextmap[node]:
                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

Example call:

f269(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

270

def f270(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    combined = []
    for key, count in left[:20]:
        if key in ratemap:
            combined.append((key, count * ratemap[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f270([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

271

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

Example call:

f271([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

272

def f272(nodes, edges):
    nodes = list(nodes)
    nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
    incoming = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        if before == after:
            continue
        a, b = (before, after)
        children[a].append(b)
        incoming[b] += 1
    initial = dict(incoming)
    handled = set()
    listing = []
    layers = []
    while len(handled) < len(nodes) and len(handled) < 20:
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
        if not available:
            break
        current = available
        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 initial[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f272(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

273

def f273(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices and rate0 != 0:
            prices[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    absent = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f273([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

274

def f274(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f274([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

275

def f275(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[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop or len(word) > 12:
            continue
        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

Example call:

f275(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

276

def f276(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in (edge for edge in edges if edge[0] <= edge[1]):
        children.setdefault(a, []).append(b)
    steps = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(children.get(cur, []))[:20]:
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    listing = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': listing, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f276([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

277

def f277(nodes, edges):
    nodes = list(nodes)
    indegree = {node: 0 for node in nodes}
    routes = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        routes[a].append(b)
        indegree[b] += 1
    initial = dict(indegree)
    handled = set()
    sequence = []
    groups = []
    while len(handled) < len(nodes) and len(handled) < 20:
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in handled), reverse=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 routes[node]:
                indegree[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

Example call:

f277(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

278

def f278(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
    rootsource = dict(indegree)
    handled = set()
    sequence = []
    groups = []
    while len(handled) < len(nodes) and len(handled) < 20:
        nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in handled))
        if not nextbatch:
            break
        current = nextbatch
        groups.append(current)
        for node in current:
            handled.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                indegree[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f278(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

279

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

    def normalize(value):
        return ' '.join(str(value).split()).upper()
    excluded = {str(value).strip() for value in excluded}
    a = {normalize(value) for value in left} - excluded
    b = {normalize(value) for value in right} - excluded
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f279(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

280

def f280(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(min(64, len(values) - size + 1)):
        totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
    positions = [pos for pos, value in enumerate(totals) if value >= limit]
    growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': positions, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f280([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

281

def f281(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    found = {(0, 0)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves[:20]:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x += 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

Example call:

f281([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

282

def f282(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    totals = []
    for pos in range(min(64, len(values) - size + 1)):
        totals.append(sum(values[pos:pos + size]))
    positions = [pos for pos, value in enumerate(totals) if value >= limit and (limit >= 0 or pos > 0)]
    ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': positions, 'rises': ups}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f282([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

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

Example call:

f283([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

284

def f284(values, width, limit):
    values = list(values)
    size = width
    series = []
    for pos in range(len(values) - size + 1):
        series.append(sum((max(item, 0) for item in values[pos:pos + size])))
    matches = [pos for pos, value in enumerate(series) if value > limit]
    increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max([0] + series), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f284([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

285

def f285(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) for word in stop}
    items = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop or len(word) < 2:
            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

Example call:

f285(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

286

def f286(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} if any((start in edge for edge in edges)) else {}
    work = [start]
    while work:
        cur = work.pop(0)
        if levels[cur] < limit:
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    work.append(nxt)
    result = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': result, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f286([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

287

def f287(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    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

Example call:

f287(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

288

def f288(values, width, limit):
    values = list(values)
    size = width
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals) if value >= limit]
    growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f288([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

289

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

    def normalize(value):
        return ' '.join(str(value).split()).upper()
    ignored = {str(value).strip() for value in ignored}
    a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - ignored
    b = {normalize(value) for value in right} - ignored
    both = a & b
    sequence = sorted
    returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f289(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

290

def f290(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, 64)):
            x += dx
            y = max(-64, min(64, y + dy))
            used += 1
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, 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

Example call:

f290([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

291

def f291(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
    letters = {}
    for word, count in wordmap.items():
        letters[word[0]] = letters.get(word[0], 0) + count
    returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f291(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

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)
    distance = {start: 0} if any((start in edge for edge in edges)) else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < limit:
            for nxt in (node for node in sorted(children.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

Example call:

f292([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

293

def f293(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, 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

Example call:

f293([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

294

def f294(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:
            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

Example call:

f294(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

295

def f295(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors and rate0 != 0:
            factors[name0] = rate0
    items = []
    for key, count in left:
        if key in factors and count > 0:
            items.append((key, count * factors[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    unmatched = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': unmatched, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f295([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

296

def f296(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges:
        children.setdefault(a, []).append(b)
    steps = {start: 0}
    work = [start]
    while work:
        cur = work.pop(0)
        if steps[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    work.append(nxt)
    result = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': result, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f296([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

297

def f297(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[: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

Example call:

f297(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

298

def f298(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges[:16]:
        children.setdefault(a, []).append(b)
    levels = {start: 0} if any((start in edge for edge in edges)) else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in levels and (not nxt.startswith('Z')):
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    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

Example call:

f298([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A'), ('A', 'G')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":1,"H":3},"frontier":["H"],"order":["A","B","C","G","D","E","F","H"]}

299

def f299(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges[:16]:
        routes.setdefault(a, []).append(b)
    distance = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < limit:
            for nxt in sorted(routes.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    pending.append(nxt)
    sequence = list(distance)
    lastlevel = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': lastlevel[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f299([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

300

def f300(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]))
    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

Example call:

f300(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['delta', 'ember'])

Output example:

{"counts":{"amber":1,"blue":5,"cyan":4,"frost":7,"garnet":4,"helium":4},"initials":{"a":1,"b":5,"c":4,"f":7,"g":4,"h":4},"size":124,"top":["frost","blue","cyan","garnet","helium"]}

301

def f301(nodes, edges):
    nodes = list(nodes)
    needs = {node: 0 for node in nodes}
    children = {node: [] for node in nodes}
    for before, after in edges:
        a, b = (before, after)
        children[a].append(b)
        needs[b] += 1
    initial = dict(needs)
    finished = set()
    sequence = []
    layers = []
    while len(finished) < len(nodes):
        available = sorted((node for node in nodes if needs[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
        if not available:
            break
        current = available
        layers.append(current)
        for node in current:
            finished.add(node)
            sequence.append(node)
        for node in current:
            for nxt in children[node]:
                needs[nxt] -= 1
    returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f301(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

302

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

    def canon(value):
        return ' '.join(str(value).split()).upper()
    excluded = {canon(value) for value in excluded}
    a = {canon(value) for value in left if canon(value) != canon(value) or canon(value) != ''} - excluded
    b = {canon(value) for value in right} - excluded
    both = a & b
    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

Example call:

f302(['ivory', 'cyan ', 'GARNET', 'Amberx', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","AMBERX","BLUE","CYAN","DELTA","FROST","GARNET","IVORY"],"both":["CYAN","DELTA","FROST","GARNET"],"left":["AMBERX","IVORY"],"right":["AMBER","BLUE"],"score":20}

303

def f303(rows, keep, prices):
    rows = list(rows)
    kept = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            score = value * prices[group]
            kept.append((code, score))
            totals[group] = totals.get(group, 0) + score
            amount += score
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, score in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f303([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

304

def f304(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(prices[group])
            selected.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': groupmap, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f304([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":572,"edge":75,"north":140,"south":81},"top":["CX38","AN27","DL42"],"total":868}

305

def f305(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)
    finished = set()
    listing = []
    rounds = []
    while len(finished) < len(nodes) and len(finished) < 20:
        available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
        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 rootsource[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f305(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])

Output example:

{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}

306

def f306(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(min(64, len(values) - size + 1)):
        windows.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(windows) if value >= limit]
    growth = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f306([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

307

def f307(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
    startdegree = dict(needs)
    complete = set()
    listing = []
    layers = []
    while len(complete) < len(nodes):
        nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete), reverse=len(nodes) > 20)
        if not nextbatch:
            break
        current = nextbatch
        layers.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': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(listing)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f307(['api', 'ui', 'db', 'jobs', 'auth', 'worker', 'proxy', 'cache'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'db')])

Output example:

{"batches":[["auth","cache"],["db","proxy"],["api","jobs"],["ui","worker"]],"count":8,"order":["auth","cache","db","proxy","api","jobs","ui","worker"],"roots":["auth","cache"]}

308

def f308(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = min(9, 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

Example call:

f308(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

309

def f309(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 += 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

Example call:

f309([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

310

def f310(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    returns = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count):
            x = max(-64, min(64, x + dx))
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, 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

Example call:

f310([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

311

def f311(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 % 100):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in known and list(point) not in returns:
                returns.append(list(point))
            known.add(point)
            far = max(far, 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

Example call:

f311([('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[-1,-5,2,3],"end":[-1,-5],"far":6,"revisits":[[1,3],[0,3],[0,2],[0,1],[0,0]],"steps":28}

312

def f312(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    crossings = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(min(count, 64)):
            x = max(-64, min(64, x + dx))
            y += 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

Example call:

f312([('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3), ('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 1)])

Output example:

{"bounds":[0,-3,2,3],"end":[0,-3],"far":5,"revisits":[[1,3],[0,3],[0,0],[1,0],[1,1]],"steps":29}

313

def f313(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[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    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': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f313(['Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet', 'Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'], ['amber', 'blue'])

Output example:

{"counts":{"cyan":4,"delta":1,"ember":5,"frost":7,"garnet":4,"helium":4},"initials":{"c":4,"d":1,"e":5,"f":7,"g":4,"h":4},"size":129,"top":["frost","ember","cyan","garnet","helium"]}

314

def f314(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
    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

Example call:

f314(['ivory', 'cyanx', 'GARNET', ' Amber', 'delta', 'frost', 'Ember'], [' Amber', 'BLUE', 'GARNET', 'cyan ', 'frost', 'delta', 'Ember'], ['EMBER'])

Output example:

{"all":["AMBER","BLUE","CYAN","CYANX","DELTA","FROST","GARNET","IVORY"],"both":["AMBER","DELTA","FROST","GARNET"],"left":["CYANX","IVORY"],"right":["BLUE","CYAN"],"score":21}

315

def f315(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in prices:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f315([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10)], 4)

Output example:

{"count":8,"items":[["CX",114],["BR",103],["HR",84],["DL",44],["FP",40]],"missing":[],"total":462}

316

def f316(values, width, limit):
    values = list(values)
    size = width
    windows = []
    for pos in range(len(values) - size + 1):
        windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
    positions = [pos for pos, value in enumerate(windows) if value >= limit]
    growth = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': positions, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f316([17, 4, 21, 17, 17, 15, 21, 24, 24, 10, 8, 9, 12, 20, 19], 4, 74)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[59,59,70,70,77,84,79,66,51,39,49,60]}

317

def f317(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors or rate0 <= rate0 + 0:
            factors[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in factors:
            matched.append((key, count * factors[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f317([('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5), ('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)], [('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8), ('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14)], 4)

Output example:

{"count":8,"items":[["HR",116],["BR",103],["CX",94],["DL",44],["FP",40]],"missing":[],"total":474}

318

def f318(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 0
    for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
        if state in keep and value >= 0:
            charge = value * prices[group]
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            grand += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': grand, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f318([('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18), ('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 12, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":624,"edge":75,"north":140,"south":45},"top":["CX38","AN27","DL42"],"total":884}

319

def f319(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in edges:
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if levels[cur] < min(limit, 3):
            for nxt in sorted(nextmap.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    pending.append(nxt)
    sequence = list(levels)
    furthest = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': sequence, 'depth': levels, 'frontier': furthest, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f319([('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')], 'A', 3)

Output example:

{"count":8,"depth":{"A":0,"B":1,"C":1,"D":2,"E":2,"F":2,"G":3,"H":3},"frontier":["G","H"],"order":["A","B","C","D","E","F","G","H"]}

320

def f320(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    matches = [pos for pos, value in enumerate(totals) if value >= limit 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': min(256, max(totals)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f320([17, 8, 21, 17, 17, 15, 21, 24, 24, 10, 5, 9, 12, 20, 19], 4, 76)

Output example:

{"best":84,"hits":[4,5,6],"rises":5,"sums":[63,63,70,70,77,84,79,63,48,36,46,60]}

Final Query

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

import json, re
from collections import deque
out = {}
edges = list((('A', 'C'), ('A', 'B'), ('B', 'D')) + (('B', 'E'), ('C', 'F'), ('D', 'G'), ('E', 'G'), ('F', 'H'), ('G', 'A')))
start = 'A'
limit = 3
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)}
left = list((('AN', 7), ('BR', 11), ('CX', 10), ('DL', 5)) + (('EV', 7), ('FP', 12), ('GQ', 4), ('HR', 8)))
fee = 4
route = record['aa'][3]
cases = {
    'D': list((('AN', 4), ('BR', 9), ('CX', 11), ('DL', 8)) + (('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 10))),
    'G': list((('AN', 4), ('BR', 9), ('CX', 9), ('DL', 8)) + (('EV', 3), ('FP', 3), ('GQ', 4), ('HR', 14))),
}
right = cases[route]
joined = []
for key, count in left:
    matches = [rate for name, rate in right if name == key]
    if matches:
        joined.append([key, count * matches[0] + fee])
joined.sort(key=lambda item: (-item[1], item[0]))
rightkeys = {key for key, rate in right}
record = {'aa': joined[:5], 'bb': sum((item[1] for item in joined)), 'cc': sorted((key for key, count in left if key not in rightkeys)), 'dd': len(joined)}
route = record['bb']
cases = {
    462: list((('N', 2), ('N', 1), ('E', 2), ('W', 3), ('E', 1), ('S', 3)) + (('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 3), ('S', 3), ('W', 1), ('S', 1), ('S', 1))),
    474: list((('N', 2), ('N', 1), ('E', 2), ('W', 2), ('E', 1), ('S', 3)) + (('W', 1), ('E', 2), ('S', 3), ('W', 1), ('N', 5), ('S', 3), ('W', 1), ('S', 1), ('S', 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}
right = list((' Amber', 'BLUE', 'GARNET', 'cyan ') + ('frost', 'delta', 'Ember'))
blocked = ['EMBER']
route = record['bb']
cases = {
    6: list(('ivory', 'cyanx', 'GARNET', ' Amber') + ('delta', 'frost', 'Ember')),
    5: list(('ivory', 'cyan ', 'GARNET', 'Amberx') + ('delta', 'frost', 'Ember')),
}
left = cases[route]
a = set()
b = set()
ban = set()
for value in blocked:
    ban.add(value.strip().upper())
for value in left:
    value = value.strip().upper()
    if value not in ban:
        a.add(value)
for value in right:
    value = value.strip().upper()
    if value not in ban:
        b.add(value)
both = a.intersection(b)
record = {'aa': sorted(both), 'bb': sorted(a.difference(b)), 'cc': sorted(b.difference(a)), 'dd': sorted(a.union(b)), 'ee': sum(map(len, both))}
rows = list((('CX68', 'south', 'hold', 24), ('AN05', 'core', 'checked', 3), ('DL42', 'north', 'ready', 20), ('AN79', 'core', 'hold', 8), ('BR16', 'core', 'void', 20), ('AN53', 'south', 'hold', 14), ('BR90', 'core', 'ready', 11), ('AN27', 'core', 'ready', 18)) + (('BR64', 'edge', 'checked', 16), ('CX01', 'south', 'void', 24), ('CX38', 'core', 'ready', 20), ('BR75', 'south', 'checked', 9), ('CX12', 'edge', 'void', 22), ('BR49', 'edge', 'ready', 9)))
keep = list(('ready',) + ('checked',))
route = record['ee']
cases = {
    20: dict((('north', 7), ('south', 5), ('core', 12)) + (('edge', 3),)),
    21: dict((('north', 7), ('south', 9), ('core', 11)) + (('edge', 3),)),
}
rates = cases[route]
chosen = [(code, group, value) for code, group, state, value in rows if state in keep]
priced = [(code, group, value * rates[group]) for code, group, value in chosen]
groups = {}
for code, group, price in priced:
    groups[group] = groups.get(group, 0) + price
ranked = sorted(priced, key=lambda row: (-row[2], row[0]))
record = {'aa': [row[0] for row in ranked[:3]], 'bb': sum((row[2] for row in priced)), 'cc': len(priced), 'dd': groups}
width = 4
route = record['bb']
cases = {
    884: (list((17, 8, 21, 17, 17, 15, 21) + (24, 24, 10, 5, 9, 12, 20, 19)), 76),
    868: (list((17, 4, 21, 17, 17, 15, 21) + (24, 24, 10, 8, 9, 12, 20, 19)), 74),
}
values, limit = cases[route]
current = sum(values[:width])
sums = [current]
for pos in range(width, len(values)):
    current += values[pos] - values[pos - width]
    sums.append(current)
hits = []
rises = 0
for pos, value in enumerate(sums):
    if value >= limit:
        hits.append(pos)
    if pos and value > sums[pos - 1]:
        rises += 1
record = {'aa': hits, 'bb': max(sums), 'cc': rises, 'dd': sums}
nodes = list(('api', 'ui', 'db', 'jobs') + ('auth', 'worker', 'proxy', 'cache'))
route = record['dd'][0]
cases = {
    63: list((('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui')) + (('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache'))),
    59: list((('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui')) + (('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('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)}
lines = list(('Blue, helium. cyan ember', 'Helium, cyan. ember ember frost', 'Cyan, cyan. blue frost', 'Frost, frost. blue helium garnet') + ('Frost, delta. amber blue', 'Garnet, garnet. helium ember frost', 'Blue, ember. frost garnet'))
route = record['aa'][1]
cases = {
    'db': list(('amber',) + ('blue',)),
    'cache': list(('delta',) + ('ember',)),
}
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))}
out['aa'] = record['aa']
out['cc'] = record['cc']
out['bb'] = record['bb']
out['dd'] = record['dd']
print(json.dumps(out, separators=(",", ":"), sort_keys=True))