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

001

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

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

002

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

Example call:

f2(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

003

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

Example call:

f3(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

004

def f4(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([0] + windows), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f4([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

005

def f5(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:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    unmatched = sorted((key for key, count in left if key not in ratemap))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f5([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

006

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

Example call:

f6(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

007

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

Example call:

f7([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

008

def f8(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop 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:

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

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

009

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

f9([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

010

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

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

f10(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

011

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

f11([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

012

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

f12(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

013

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

Example call:

f13([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

014

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

Example call:

f14([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

015

def f15(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            charge = value * abs(prices[group])
            selected.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            sumvalue += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    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:

f15([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

016

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

Example call:

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

Output example:

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

017

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

Example call:

f17(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

018

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

Example call:

f18([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

019

def f19(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 str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * abs(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': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f19([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

020

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

f20(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

021

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

022

def f22(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' or (char == "'" and word):
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            continue
        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': min(256, sum((len(word) * count for word, count in frequency.items())))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f22(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

023

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

Example call:

f23([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

024

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

Example call:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

025

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

026

def f26(rows, keep, factors):
    rows = list(rows)
    selected = []
    buckets = {}
    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]
            selected.append((code, cost))
            buckets[group] = buckets.get(group, 0) + cost
            grand += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(selected), 'total': grand, 'groups': buckets, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f26([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

027

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

Example call:

f27(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

028

def f28(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} if limit > 0 or limit < 0 else {}
    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)
    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:

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

Output example:

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

029

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

Example call:

f29([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

030

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

Example call:

f30(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

031

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

f31(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

032

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

f32(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

033

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

Example call:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

034

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

035

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

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

Output example:

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

036

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

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

Example call:

f36(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

037

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

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

Output example:

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

038

def f38(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    matched = []
    for key, count in left[:20]:
        if key in ratemap 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:

f38([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

039

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

Example call:

f39(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

040

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

Example call:

f40([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

041

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

f41(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

042

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

Example call:

f42([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

043

def f43(rows, keep, prices):
    rows = list(rows)
    kept = []
    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 * abs(prices[group])
            kept.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            grand += cost
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(kept), 'total': grand, 'groups': totals, 'top': [code for code, cost in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f43([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

044

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

f44(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

045

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

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

Example call:

f45(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

046

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

Example call:

f46([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

047

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

Example call:

f47(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

048

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

Example call:

f48(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

049

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

Example call:

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

050

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

Example call:

f50([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

051

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

Example call:

f51([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

052

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

Example call:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

053

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

f53([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

054

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

Example call:

f54(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

055

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

056

def f56(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {word.lower() for word in stop}
    terms = []
    for line in lines[:32]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z' or (char == "'" and word):
                word += char
            elif word:
                terms.append(word)
                word = ''
        if word:
            terms.append(word)
    for word in terms:
        if word in stop:
            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:

f56(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

057

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

058

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

Example call:

f58([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

059

def f59(moves):
    moves = list(moves)
    step = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
    x = 0
    y = 0
    visited = {(0, 0)}
    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 = 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:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

060

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

Example call:

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

Output example:

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

061

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

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

Example call:

f61(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

062

def f62(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices and rate0 != 0:
            prices[name0] = rate0
    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:

f62([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

063

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

Example call:

f63([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

064

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

Example call:

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

Output example:

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

065

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

Example call:

f65(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

066

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

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

f66(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

067

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

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

f67(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

068

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

Example call:

f68(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

069

def f69(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    totals = []
    for pos in range(len(values) - size + 1):
        totals.append(sum(values[pos:pos + size]))
    indexes = [pos for pos, value in enumerate(totals) if value >= limit]
    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([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

070

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

071

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

Example call:

f71(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

072

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

Example call:

f72([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

073

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

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

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

074

def f74(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right[:20]:
        if name0 not in ratemap:
            ratemap[name0] = rate0
    combined = []
    for key, count in left[:20]:
        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(combined)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

075

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

Example call:

f75(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

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:
        dx, dy = step[direction]
        for turn in range(count):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

077

def f77(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                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:

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

Output example:

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

078

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

Example call:

f78(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

079

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

f79(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

080

def f80(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right[:20]:
        if name0 not in factors:
            factors[name0] = rate0
    items = []
    for key, count in left:
        if key in factors:
            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:

f80([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

081

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

Example call:

f81(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

082

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

083

def f83(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            cost = value * prices[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(selected), 'total': grand, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f83([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

084

def f84(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}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if steps[cur] < min(limit, 3):
            for nxt in (node for node in sorted(nextmap.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    pending.append(nxt)
    sequence = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

085

def f85(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors:
            factors[name0] = rate0
    items = []
    for key, count in left[:20]:
        if key in factors:
            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:

f85([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

086

def f86(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * factors[group]
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            grand += charge
    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, charge in selected)))[:3]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f86([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

087

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

Example call:

f87(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

088

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

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

f88(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

089

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

f89(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

090

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

Example call:

f90([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

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

Example call:

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

Output example:

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

092

def f92(rows, keep, prices):
    rows = list(rows)
    matches = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        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': [code for code, cost in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f92([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

093

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

Example call:

f93([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

094

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

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

095

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

Example call:

f95([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

096

def f96(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]
    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': positions, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f96([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

097

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

f97(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

098

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

Example call:

f98([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

099

def f99(left, right, fee):
    left = list(left)
    factors = {}
    for name0, rate0 in right:
        if name0 not in factors and rate0 != 0:
            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]))
    leftover = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f99([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

100

def f100(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 and count > 0:
            matched.append((key, count * prices[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    unmatched = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

101

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

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

102

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

f102(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

103

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

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

f103(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

104

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

Example call:

f104(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

105

def f105(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} - 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:

f105(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

106

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

Example call:

f106([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

107

def f107(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])))
    positions = [pos for pos, value in enumerate(totals) if value >= limit]
    increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f107([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

108

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

Example call:

f108(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

109

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

f109(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

110

def f110(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]
    growth = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f110([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

111

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

112

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

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

Example call:

f112(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

113

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

Example call:

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

Output example:

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

114

def f114(rows, keep, ratemap):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 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
            amount += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    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:

f114([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

115

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

Example call:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

116

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

Example call:

f116([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

117

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

Example call:

f117(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

118

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

Example call:

f118([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

119

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

Example call:

f119([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

120

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

Example call:

f120(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

121

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

Example call:

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

Output example:

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

122

def f122(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' or (char == "'" and word):
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop or len(word) > 12:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
    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:

f122(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

123

def f123(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 {} if limit > 0 or limit < 0 else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if distance[cur] < min(limit, 3):
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

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

124

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

Example call:

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

125

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

Example call:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

126

def f126(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * prices[group]
            selected.append((code, charge))
            groupmap[group] = groupmap.get(group, 0) + charge
            amount += charge
    selected.sort(key=lambda item: (-item[1], item[0]))
    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:

f126([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

127

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

Example call:

f127(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

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:
        dx, dy = step[direction]
        for turn in range(min(count, 3 + (count - count))):
            x += dx
            y += dy
            used = min(64, used + 1)
            point = (x, y)
            if point in visited and list(point) not in returns:
                returns.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': returns[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

129

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

Example call:

f129(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

130

def f130(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, 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:

f130([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

131

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

Example call:

f131(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

132

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

    def normalize(value):
        return str(value).strip().upper()[:12]
    ignored = {str(value).upper() for value in ignored}
    a = {normalize(value) for value in left} - ignored
    b = {normalize(value) for value in right} - 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:

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

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

133

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

Example call:

f133(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

134

def f134(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' or (char == "'" and word):
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        frequency[word] = min(9, 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:

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

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

135

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

Example call:

f135([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

136

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

Example call:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

137

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

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

f137(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

138

def f138(rows, keep, prices):
    rows = list(rows)
    selected = []
    buckets = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * prices[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': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f138([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

139

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

Example call:

f139(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

140

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

    def canon(value):
        return str(value).strip(' \r').upper()[:12]
    banned = {canon(value) for value in banned}
    a = {canon(value) for value in left} - banned
    b = {canon(value) for value in right if canon(value) != ''} - banned
    both = a & b
    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:

f140(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

141

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

Example call:

f141(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

142

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

f142(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

143

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

f143([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

144

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

f144([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

145

def f145(rows, keep, factors):
    rows = list(rows)
    selected = []
    buckets = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value != 0:
            cost = value * factors[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(dict.fromkeys(selected)), 'total': amount, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f145([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

146

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

f146([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

147

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

Example call:

f147([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

148

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

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

Example call:

f148(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

149

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

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

Example call:

f149(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

150

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

Example call:

f150(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

151

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

Example call:

f151([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

152

def f152(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]))
    leftover = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f152([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

153

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

Example call:

f153(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

154

def f154(lines, stop):
    lines = list(lines)
    frequency = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens[:64]:
        if word in stop or len(word) > 12:
            continue
        frequency[word] = frequency.get(word, 0) + 1
    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(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

155

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

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

Output example:

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

156

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

Example call:

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

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

157

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

158

def f158(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}
    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)
    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:

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

159

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

Example call:

f159(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

160

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

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

Example call:

f160(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

161

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

162

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

f162(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

163

def f163(edges, start, limit):
    edges = list(edges)
    routes = {}
    for a, b in edges[:16]:
        routes.setdefault(a, []).append(b)
    steps = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if steps[cur] < min(limit, 3):
            for nxt in sorted(routes.get(cur, [])):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    pending.append(nxt)
    listing = list(steps)
    edge = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': listing, 'depth': steps, 'frontier': edge[:3], 'count': len(steps)}
    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'), ('C', 'E'), ('H', 'B'), ('A', 'E')], 'A', 3)

Output example:

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

164

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

f164(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

165

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

Example call:

f165([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

166

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

Example call:

f166([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

167

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

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

f167(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

168

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

Example call:

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

Output example:

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

169

def f169(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]
    growth = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
    returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': growth}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f169([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

170

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

Example call:

f170(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

171

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

Example call:

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

Output example:

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

172

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

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

f172(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

173

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

Example call:

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

Output example:

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

174

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

175

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

Example call:

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

176

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

Example call:

f176(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

177

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

Example call:

f177([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

178

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

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

Example call:

f178(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

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 % 100):
            x += dx
            y += dy
            used += 1
            point = (x, y)
            if point in visited and list(point) not in crossings:
                crossings.append(list(point))
            visited.add(point)
            far = max(far, abs(x) + abs(y))
            lowx, highx = (min(lowx, x), max(highx, x))
            lowy, highy = (min(lowy, y), max(highy, y))
    returnvalue = {'end': [x, y], 'far': far, 'revisits': crossings[:5], 'bounds': [lowx, lowy, highx, highy], 'steps': used}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

180

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

Example call:

f180([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

181

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

Example call:

f181(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

182

def f182(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} if any((start in edge for edge in edges)) else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if steps[cur] < limit:
            for nxt in (node for node in sorted(children.get(cur, [])) if len(str(node)) == 1):
                if nxt not in steps:
                    steps[nxt] = steps[cur] + 1
                    queue.append(nxt)
    sequence = list(steps)
    furthest = sorted((node for node in steps if steps[node] == max(steps.values())))
    returnvalue = {'order': sequence, 'depth': steps, 'frontier': furthest, 'count': len(steps)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

183

def f183(rows, keep, prices):
    rows = list(rows)
    kept = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * abs(prices[group])
            kept.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            amount += cost
    kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    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:

f183([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

184

def f184(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(totals), 'hits': indexes, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f184([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

185

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

f185([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

186

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

f186([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

187

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

f187([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

188

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

Example call:

f188([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

189

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

Example call:

f189([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

190

def f190(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] < min(limit, 3):
            for nxt in sorted(children.get(cur, []))[:20]:
                if nxt not in distance:
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    sequence = list(distance)
    furthest = sorted((node for node in distance if distance[node] == max(distance.values())))
    returnvalue = {'order': sequence, 'depth': distance, 'frontier': furthest[:3], 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

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

191

def f191(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]))
    unmatched = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': unmatched, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f191([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

192

def f192(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:
            items.append((key, count * factors[key] + fee))
    items.sort(key=lambda item: (-item[1], item[0]))
    leftover = sorted((key for key, count in left if key not in factors))
    returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': leftover, 'count': len(items)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f192([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

193

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

Example call:

f193([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

194

def f194(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {word.lower() for word in stop}
    tokens = []
    for line in lines:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                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]))
    starts = {}
    for word, count in wordmap.items():
        starts[word[0]] = starts.get(word[0], 0) + count
    returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f194(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

195

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

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

f195(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

196

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

Example call:

f196(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

197

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

Example call:

f197([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

198

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

Example call:

f198([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

199

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

Example call:

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

Output example:

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

200

def f200(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(factors[group])
            selected.append((code, charge))
            totals[group] = totals.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': totals, 'top': [code for code, charge in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f200([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

201

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

Example call:

f201(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

202

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

Example call:

f202([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

203

def f203(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]))
    unmatched = sorted({key for key, count in left if key not in prices})
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len(matched)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f203([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

204

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

Example call:

f204([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

205

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

f205(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

206

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

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)}
    repeats = []
    far = 0
    lowx = highx = lowy = highy = 0
    used = 0
    for direction, count in moves:
        dx, dy = step[direction]
        for turn in range(count % 100):
            x += dx
            y += dy
            used = 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:

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

208

def f208(left, right, fee):
    left = list(left)
    prices = {}
    for name0, rate0 in right:
        if name0 not in prices:
            prices[name0] = rate0
    combined = []
    for key, count in left[:20]:
        if key in prices:
            combined.append((key, count * prices[key] + fee))
    combined.sort(key=lambda item: (-item[1], item[0]))
    leftover = 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': leftover, 'count': len({key for key, value in combined})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f208([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

209

def f209(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[1]) < 2):
        nextmap.setdefault(a, []).append(b)
    distance = {start: 0}
    pending = [start]
    while pending:
        cur = pending.pop(0)
        if distance[cur] < min(limit, 3):
            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, 'count': len(distance)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

210

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

Example call:

f210([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

211

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

Example call:

f211([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

212

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

Example call:

f212([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

213

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

Example call:

f213([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

214

def f214(lines, stop):
    lines = list(lines)
    wordmap = {}
    stop = {word.lower() for word in stop}
    items = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                items.append(word)
                word = ''
        if word:
            items.append(word)
    for word in items:
        if word in stop:
            continue
        wordmap[word] = wordmap.get(word, 0) + 1
    ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
    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:

f214(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

215

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

Example call:

f215(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

216

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

Example call:

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

217

def f217(rows, keep, factors):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep:
            charge = value * abs(factors[group])
            selected.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            grand += charge
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    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:

f217([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

218

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

219

def f219(values, width, limit):
    values = list(values)
    size = width if width > 1 or width < 1 else 2
    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]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f219([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

220

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

f220([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

221

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

222

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

223

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

Example call:

f223(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

224

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

Example call:

f224(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

225

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

226

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

Example call:

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

227

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

Example call:

f227([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

228

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

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

Example call:

f228(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

229

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

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

Example call:

f229(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

230

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

Example call:

f230([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

231

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

Example call:

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

Output example:

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

232

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

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

f232(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

233

def f233(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)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(children.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[:3], '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'), ('C', 'E'), ('H', 'B'), ('G', 'C')], '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(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
    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:

f234(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

235

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

f235(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

236

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

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

f236(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

237

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

Example call:

f237([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

238

def f238(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} - banned
    b = {normalize(value) for value in right if normalize(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:

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

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

239

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

Example call:

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

240

def f240(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]))
    unmatched = sorted((key for key, count in left if key not in prices))
    returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len({key for key, value in matched})}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f240([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

241

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

Example call:

f241(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

242

def f242(lines, stop):
    lines = list(lines)
    tallies = {}
    stop = {str(word) for word in stop}
    tokens = []
    for line in lines[:20]:
        text = line.lower()
        word = ''
        for char in text[:64]:
            if 'a' <= char <= 'z':
                word += char
            elif word:
                tokens.append(word)
                word = ''
        if word:
            tokens.append(word)
    for word in tokens:
        if word in stop:
            continue
        tallies[word] = tallies.get(word, 0) + 1
    sorteditems = 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 sorteditems[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in tallies.items()))}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f242(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

243

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

Example call:

f243([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

244

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

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

Example call:

f244(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

245

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

Example call:

f245(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

246

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

Example call:

f246([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

247

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

248

def f248(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, min(65, 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:

f248([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

249

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

Example call:

f249(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

250

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

Example call:

f250(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

251

def f251(edges, start, limit):
    edges = list(edges)
    children = {}
    for a, b in edges[:16]:
        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 sorted(children.get(cur, [])):
                if nxt not in distance and (not nxt.startswith('Z')):
                    distance[nxt] = distance[cur] + 1
                    queue.append(nxt)
    listing = list(distance)
    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:

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

Output example:

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

252

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

Example call:

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

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

253

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

Example call:

f253([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

254

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

Example call:

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

255

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

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

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

256

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

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

Example call:

f256(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

257

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

Example call:

f257([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

258

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

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

f258(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

259

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

260

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

Example call:

f260(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

261

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

Example call:

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

Output example:

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

262

def f262(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[: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([0] + windows), 'hits': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f262([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

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, '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'), ('C', 'E'), ('H', 'B'), ('G', 'C')], '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"]}

264

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

Example call:

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

265

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

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

266

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

Example call:

f266(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

267

def f267(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} - 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:

f267(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

268

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

f268(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

269

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

Example call:

f269([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

270

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

Example call:

f270([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

271

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

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

f271(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

272

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

Example call:

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

Output example:

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

273

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

Example call:

f273([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

274

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

    def tidy(value):
        return str(value).strip().upper()[:12]
    ignored = {tidy(value) for value in ignored}
    a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - ignored
    b = {tidy(value) for value in right} - 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:

f274(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

275

def f275(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]
    increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
    returnvalue = {'sums': windows, 'best': max(windows), 'hits': positions, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f275([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

276

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

Example call:

f276([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

277

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

278

def f278(rows, keep, ratemap):
    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 * ratemap[group]
            selected.append((code, cost))
            totals[group] = totals.get(group, 0) + cost
            sumvalue += cost
    selected.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f278([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

279

def f279(left, right, fee):
    left = list(left)
    ratemap = {}
    for name0, rate0 in right:
        if name0 not in ratemap and rate0 != 0:
            ratemap[name0] = rate0
    matched = []
    for key, count in left:
        if key in ratemap:
            matched.append((key, count * ratemap[key] + fee))
    matched.sort(key=lambda item: (-item[1], item[0]))
    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:

f279([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

280

def f280(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            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], item[0]))
    returnvalue = {'accepted': len(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:

f280([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

281

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

f281(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

282

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

Example call:

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

283

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

Example call:

f283([('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["EV",64],["BR",54],["FP",53],["GQ",40],["CX",34]],"missing":["DL"],"total":281}

284

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

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

Example call:

f284(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

285

def f285(rows, keep, prices):
    rows = list(rows)
    selected = []
    totals = {}
    grand = 0
    for code, group, state, value in rows:
        if state in keep and value >= 0:
            cost = value * prices[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(selected), 'total': grand, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f285([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

286

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

Example call:

f286([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

287

def f287(rows, keep, prices):
    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:
            charge = value * prices[group]
            kept.append((code, charge))
            totals[group] = totals.get(group, 0) + charge
            sumvalue += charge
    kept.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': sumvalue, 'groups': totals, 'top': [code for code, charge in kept[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f287([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

288

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

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

Example call:

f288(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

289

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

Example call:

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

290

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

f290(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['amber', 'blue'])

Output example:

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

291

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

Example call:

f291([('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8), ('FP', 7), ('GQ', 12), ('HR', 4)], [('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5), ('FP', 7), ('GQ', 3), ('HR', 5)], 4)

Output example:

{"count":7,"items":[["BR",64],["FP",53],["EV",44],["GQ",40],["CX",34]],"missing":["DL"],"total":271}

292

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

f292([20, 24, 12, 20, 11, 21, 22, 19, 16, 10, 18, 16, 7, 22, 9], 3, 46)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,43,52,54,62,57,45,44,44,41,45,38]}

293

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

Example call:

f293(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

294

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

f294([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

295

def f295(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    sumvalue = 0
    for code, group, state, value in rows:
        if state in keep:
            cost = value * prices[group]
            selected.append((code, cost))
            groupmap[group] = groupmap.get(group, 0) + cost
            sumvalue += cost
    selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
    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:

f295([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

296

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

f296(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['EMBER'])

Output example:

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

297

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

298

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

Example call:

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

299

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

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

f299(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

300

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

301

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

Example call:

f301(['#...##', '.###..', '#..#.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,1],[2,5],[0,4],[0,0],[5,3]],"count":6,"filled":18,"sizes":[7,4,3,2,1,1]}

302

def f302(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]
    increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
    returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': matches, 'rises': increases}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f302([20, 24, 12, 20, 15, 21, 22, 19, 16, 10, 18, 16, 7, 19, 9], 3, 48)

Output example:

{"best":62,"hits":[0,1,3,4,5,6],"rises":4,"sums":[56,56,47,56,58,62,57,45,44,44,41,42,35]}

303

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

Example call:

f303(['Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta', 'Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'], ['frost', 'garnet'])

Output example:

{"counts":{"amber":3,"blue":4,"cyan":3,"delta":5,"ember":5,"helium":4},"initials":{"a":3,"b":4,"c":3,"d":5,"e":5,"h":4},"size":117,"top":["delta","ember","blue","helium","amber"]}

304

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

Example call:

f304([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

305

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

Example call:

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

306

def f306(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} if any((start in edge for edge in edges)) else {} if limit > 0 or limit < 0 else {}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < limit:
            for nxt in sorted(children.get(cur, [])):
                if nxt not in levels:
                    levels[nxt] = levels[cur] + 1
                    queue.append(nxt)
    result = list(levels)
    lastlevel = sorted((node for node in levels if levels[node] == max(levels.values())))
    returnvalue = {'order': result, 'depth': levels, 'frontier': lastlevel, 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

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

307

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

Example call:

f307(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

308

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

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

Output example:

{"bounds":[-5,0,2,12],"end":[-1,10],"far":15,"revisits":[[1,4],[-3,11],[-3,10],[-3,9],[-4,10]],"steps":29}

309

def f309(rows, keep, prices):
    rows = list(rows)
    selected = []
    groupmap = {}
    amount = 0
    for code, group, state, value in rows:
        if str(state).lower() in {str(item).lower() for item in keep}:
            score = value * prices[group]
            selected.append((code, score))
            groupmap[group] = groupmap.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': groupmap, 'top': [code for code, score in selected[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f309([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":329,"south":40},"top":["DL37","DL59","DL63"],"total":619}

310

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

Example call:

f310([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

311

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

Example call:

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

312

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

Example call:

f312(['#...##', '.#.#..', '#.##.#', '#...##', '###...', '##.#..'])

Output example:

{"anchors":[[2,0],[1,3],[2,5],[0,4],[0,0],[1,1],[5,3]],"count":7,"filled":18,"sizes":[7,3,3,2,1,1,1]}

313

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

Example call:

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

314

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

Example call:

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

Output example:

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

315

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

Example call:

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

316

def f316(edges, start, limit):
    edges = list(edges)
    nextmap = {}
    for a, b in (edge for edge in edges if len(edge[0]) < 2):
        nextmap.setdefault(a, []).append(b)
    levels = {start: 0}
    queue = [start]
    while queue:
        cur = queue.pop(0)
        if levels[cur] < min(limit, 3):
            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[:3], 'count': len(levels)}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

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

Output example:

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

317

def f317(rows, keep, ratemap):
    rows = list(rows)
    matches = []
    buckets = {}
    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} and value >= 0:
            score = value * ratemap[group]
            matches.append((code, score))
            buckets[group] = buckets.get(group, 0) + score
            grand += score
    matches.sort(key=lambda item: (-item[1], item[0]))
    returnvalue = {'accepted': len(matches), 'total': grand, 'groups': buckets, 'top': [code for code, score in matches[:3]]}
    output = dict()
    output.update(returnvalue)
    return output

Example call:

f317([('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8), ('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14)], ['ready', 'checked'], {'north': 7, 'south': 5, 'core': 11, 'edge': 3})

Output example:

{"accepted":8,"groups":{"core":88,"edge":162,"north":357,"south":25},"top":["DL37","DL59","DL63"],"total":632}

318

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

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

Example call:

f318(['ivory', ' Amber', 'Ember', 'frost', 'GARNET', 'helium', 'Ember'], ['delta', ' Amber', 'ivory', 'cyan ', 'BLUE', 'helium', 'Ember'], ['ivory'])

Output example:

{"all":["AMBER","BLUE","CYAN","DELTA","EMBER","FROST","GARNET","HELIUM"],"both":["AMBER","EMBER","HELIUM"],"left":["FROST","GARNET"],"right":["BLUE","CYAN","DELTA"],"score":16}

319

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

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

Output example:

{"bounds":[-5,0,2,14],"end":[-4,12],"far":17,"revisits":[[1,4],[-3,13],[-3,12],[-3,11],[-4,12]],"steps":28}

320

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

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

Final Query

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

import json, re
from collections import deque
out = {}
left = list(('ivory', ' Amber', 'Ember', 'frost') + ('GARNET', 'helium', 'Ember'))
right = list(('delta', ' Amber', 'ivory', 'cyan ') + ('BLUE', 'helium', 'Ember'))
blocked = ['EMBER']
a = set()
b = set()
ban = set()
for value in blocked:
    ban.add(value.strip().upper())
for value in left:
    value = value.strip().upper()
    if value not in ban:
        a.add(value)
for value in right:
    value = value.strip().upper()
    if value not in ban:
        b.add(value)
both = a.intersection(b)
record = {'aa': sorted(both), 'bb': sorted(a.difference(b)), 'cc': sorted(b.difference(a)), 'dd': sorted(a.union(b)), 'ee': sum(map(len, both))}
width = 3
route = record['aa'][1]
cases = {
    'EMBER': (list((20, 24, 12, 20, 15, 21, 22) + (19, 16, 10, 18, 16, 7, 19, 9)), 48),
    'HELIUM': (list((20, 24, 12, 20, 11, 21, 22) + (19, 16, 10, 18, 16, 7, 22, 9)), 46),
}
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}
start = 'A'
limit = 3
route = record['dd'][2]
cases = {
    43: list((('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G')) + (('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B'), ('G', 'C'))),
    47: list((('A', 'C'), ('A', 'B'), ('B', 'D'), ('B', 'E'), ('C', 'F'), ('D', 'G')) + (('E', 'G'), ('F', 'H'), ('G', 'A'), ('C', 'E'), ('H', 'B'), ('A', 'E'))),
}
edges = cases[route]
links = {}
for edge in edges:
    links.setdefault(edge[0], []).append(edge[1])
distance = {start: 0}
queue = deque([start])
while queue:
    node = queue.popleft()
    if distance[node] == limit:
        continue
    for child in sorted(links.get(node, [])):
        if child in distance:
            continue
        distance[child] = distance[node] + 1
        queue.append(child)
furthest = max(distance.values())
record = {'aa': list(distance), 'bb': distance, 'cc': sorted((node for node in distance if distance[node] == furthest)), 'dd': len(distance)}
lines = list(('Frost, frost. blue amber', 'Ember, helium. delta helium ember', 'Ember, garnet. garnet delta', 'Blue, amber. blue ember delta') + ('Helium, helium. cyan delta', 'Frost, cyan. blue cyan delta', 'Amber, garnet. garnet ember'))
route = record['aa'][3]
cases = {
    'D': list(('amber',) + ('blue',)),
    'E': list(('frost',) + ('garnet',)),
}
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))}
route = record['dd']
cases = {
    125: list((('E', 1), ('N', 1), ('N', 3), ('E', 1), ('W', 3), ('W', 2), ('N', 3)) + (('N', 3), ('N', 2), ('N', 2), ('S', 1), ('S', 2), ('N', 1), ('W', 2), ('E', 1))),
    117: list((('E', 1), ('N', 1), ('N', 3), ('E', 1), ('W', 3), ('W', 2), ('N', 3)) + (('N', 1), ('N', 2), ('N', 2), ('S', 1), ('S', 2), ('N', 1), ('W', 2), ('E', 4))),
}
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}
keep = list(('ready',) + ('checked',))
rates = dict((('north', 7),) + (('south', 5), ('core', 11), ('edge', 3)))
route = record['bb']
cases = {
    17: list((('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8)) + (('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 21), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 8), ('DL59', 'north', 'checked', 14))),
    15: list((('BR78', 'south', 'void', 18), ('DL15', 'north', 'ready', 12), ('DL52', 'north', 'hold', 21), ('BR89', 'edge', 'void', 19), ('DL26', 'edge', 'void', 16), ('DL63', 'core', 'ready', 8)) + (('DL00', 'edge', 'checked', 18), ('DL37', 'north', 'ready', 25), ('BR74', 'north', 'hold', 23), ('DL11', 'edge', 'checked', 17), ('AN48', 'edge', 'ready', 19), ('DL85', 'core', 'hold', 10), ('DL22', 'south', 'checked', 5), ('DL59', 'north', 'checked', 14))),
}
rows = cases[route]
chosen = [(code, group, value) for code, group, state, value in rows if state in keep]
priced = [(code, group, value * rates[group]) for code, group, value in chosen]
groups = {}
for code, group, price in priced:
    groups[group] = groups.get(group, 0) + price
ranked = sorted(priced, key=lambda row: (-row[2], row[0]))
record = {'aa': [row[0] for row in ranked[:3]], 'bb': sum((row[2] for row in priced)), 'cc': len(priced), 'dd': groups}
route = record['bb']
cases = {
    632: list(('#...##', '.###..', '#..#.#') + ('#...##', '###...', '##.#..')),
    619: list(('#...##', '.#.#..', '#.##.#') + ('#...##', '###...', '##.#..')),
}
board = cases[route]
cells = [(row, col) for row in range(len(board)) for col in range(len(board[row])) if board[row][col] == '#']
parent = {cell: cell for cell in cells}

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

def merge(a, b):
    a = root(a)
    b = root(b)
    if a != b:
        parent[b] = a
for row, col in cells:
    for other in ((row - 1, col), (row, col - 1)):
        if other in parent:
            merge((row, col), other)
groups = {}
for cell in cells:
    groups.setdefault(root(cell), []).append(cell)
parts = [(len(group), min(group)) for group in groups.values()]
parts.sort(key=lambda item: (-item[0], item[1]))
record = {'aa': [part[0] for part in parts], 'bb': [list(part[1]) for part in parts], 'cc': len(cells), 'dd': len(parts)}
right = list((('AN', 4), ('BR', 10), ('CX', 6), ('EV', 5)) + (('FP', 7), ('GQ', 3), ('HR', 5)))
fee = 4
route = record['dd']
cases = {
    7: list((('AN', 2), ('BR', 5), ('CX', 5), ('DL', 10), ('EV', 12)) + (('FP', 7), ('GQ', 12), ('HR', 4))),
    6: list((('AN', 2), ('BR', 6), ('CX', 5), ('DL', 10), ('EV', 8)) + (('FP', 7), ('GQ', 12), ('HR', 4))),
}
left = 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)}
out['aa'] = record['aa']
out['cc'] = record['cc']
out['bb'] = record['bb']
out['dd'] = record['dd']
print(json.dumps(out, separators=(",", ":"), sort_keys=True))