broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(messages, root):
    replies = sorted((m for m in messages if m['root'] == root and not m['deleted']), key=lambda m: m['seq'])
    seen = []
    for m in replies:
        if not seen or m['author'] != seen[-1]:
            seen.append(m['author'])
    return {'count': len(replies), 'faces': seen[:3], 'more': max(0, len(seen) - 3),
            'last': replies[-1]['seq'] if replies else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 10, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 10, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u4', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u0', 'u1'], 'last': 19, 'more': 2}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 2: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 11, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 11, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u1', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u0'], 'last': 19, 'more': 3}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 3: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 12, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 12, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 6, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u5', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 4}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 4: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 13, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 13, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 7, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u3', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 5}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 5: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 14, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 14, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 8, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u8', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u8', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u1', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 6}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(messages, root):
    replies = sorted((m for m in messages if m['root'] == root and not m['deleted']), key=lambda m: m['seq'])
    seen = []
    for m in replies:
        if m['author'] not in seen[-3:]:
            seen.append(m['author'])
    return {'count': len(replies), 'faces': seen[:3], 'more': max(0, len(seen) - 3),
            'last': replies[-1]['seq'] if replies else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 10, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 10, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u4', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u0', 'u1'], 'last': 19, 'more': 2}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 2: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 11, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 11, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u1', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u0'], 'last': 19, 'more': 3}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 3: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 12, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 12, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 6, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u5', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 4}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 4: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 13, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 13, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 7, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u3', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 5}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 5: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 14, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 14, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 8, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u8', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u8', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u1', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 6}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Authors who reply repeatedly in alternation appear several times among the faces.

messages {seq, root, author, deleted}; replies of a thread have root equal to the root seq (the root itself has root None). Deleted replies are ignored. Result {count, faces: first three distinct reply authors in order of their first reply, more: number of further distinct authors, last: seq of the newest reply or None}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(requests, members):
    counters = {}
    known = {}
    out = []
    for conv, sender, nonce in requests:
        if sender not in members.get(conv, []):
            out.append('forbidden')
            continue
        key = nonce
        if key in known:
            out.append(known[key])
            continue
        counters[conv] = counters.get(conv, 0) + 1
        known[key] = counters[conv]
        out.append(counters[conv])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n1'], ['d', 'al', 'n1']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1']], {'c': ['al']}), [1, 2])], 2: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n2'], ['d', 'al', 'n2']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2']], {'c': ['al']}), [1, 2, 3])], 3: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n3'], ['d', 'al', 'n3']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3']], {'c': ['al']}), [1, 2, 3, 4])], 4: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n4'], ['d', 'al', 'n4']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4']], {'c': ['al']}), [1, 2, 3, 4, 5])], 5: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n5'], ['d', 'al', 'n5']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4'], ['c', 'al', 'm5']], {'c': ['al']}), [1, 2, 3, 4, 5, 6])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(requests, members):
    counters = {}
    known = {}
    out = []
    for conv, sender, nonce in requests:
        if sender not in members.get(conv, []):
            out.append('forbidden')
            continue
        key = (sender, nonce)
        if key in known:
            out.append(known[key])
            continue
        counters[conv] = counters.get(conv, 0) + 1
        known[key] = counters[conv]
        out.append(counters[conv])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n1'], ['d', 'al', 'n1']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1']], {'c': ['al']}), [1, 2])], 2: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n2'], ['d', 'al', 'n2']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2']], {'c': ['al']}), [1, 2, 3])], 3: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n3'], ['d', 'al', 'n3']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3']], {'c': ['al']}), [1, 2, 3, 4])], 4: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n4'], ['d', 'al', 'n4']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4']], {'c': ['al']}), [1, 2, 3, 4, 5])], 5: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n5'], ['d', 'al', 'n5']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4'], ['c', 'al', 'm5']], {'c': ['al']}), [1, 2, 3, 4, 5, 6])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A second sender, or the same sender in another conversation, who happens to reuse a nonce gets the other message's seq.

requests are [conv, sender, nonce] in arrival order; members maps conv -> member list. A sender who is not a member gets "forbidden" and consumes nothing. Each conversation numbers accepted messages 1, 2, 3... A retry with the same (conv, sender, nonce) returns the originally assigned seq without consuming a new one.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(requests, members):
    counters = {}
    known = {}
    out = []
    for conv, sender, nonce in requests:
        if sender not in members.get(conv, []):
            out.append('forbidden')
            continue
        key = (conv, sender, nonce)
        if key in known:
            out.append(known[key])
            continue
        counters[conv] = len(known) + 1
        known[key] = counters[conv]
        out.append(counters[conv])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n1'], ['d', 'al', 'n1']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1']], {'c': ['al']}), [1, 2])], 2: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n2'], ['d', 'al', 'n2']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2']], {'c': ['al']}), [1, 2, 3])], 3: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n3'], ['d', 'al', 'n3']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3']], {'c': ['al']}), [1, 2, 3, 4])], 4: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n4'], ['d', 'al', 'n4']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4']], {'c': ['al']}), [1, 2, 3, 4, 5])], 5: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n5'], ['d', 'al', 'n5']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4'], ['c', 'al', 'm5']], {'c': ['al']}), [1, 2, 3, 4, 5, 6])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(requests, members):
    counters = {}
    known = {}
    out = []
    for conv, sender, nonce in requests:
        if sender not in members.get(conv, []):
            out.append('forbidden')
            continue
        key = (conv, sender, nonce)
        if key in known:
            out.append(known[key])
            continue
        counters[conv] = max(counters.values(), default=0) + 1
        known[key] = counters[conv]
        out.append(counters[conv])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n1'], ['d', 'al', 'n1']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1']], {'c': ['al']}), [1, 2])], 2: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n2'], ['d', 'al', 'n2']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2']], {'c': ['al']}), [1, 2, 3])], 3: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n3'], ['d', 'al', 'n3']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3']], {'c': ['al']}), [1, 2, 3, 4])], 4: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n4'], ['d', 'al', 'n4']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4']], {'c': ['al']}), [1, 2, 3, 4, 5])], 5: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n5'], ['d', 'al', 'n5']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4'], ['c', 'al', 'm5']], {'c': ['al']}), [1, 2, 3, 4, 5, 6])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Conversations share one global counter, leaving gaps in every conversation's sequence.

requests are [conv, sender, nonce] in arrival order; members maps conv -> member list. A sender who is not a member gets "forbidden" and consumes nothing. Each conversation numbers accepted messages 1, 2, 3... A retry with the same (conv, sender, nonce) returns the originally assigned seq without consuming a new one.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(requests, members):
    counters = {}
    known = {}
    out = []
    for conv, sender, nonce in requests:
        if sender not in members.get(conv, []):
            out.append('forbidden')
            continue
        key = (conv, sender, nonce)
        if key in known:
            out.append(known[key])
            continue
        counters[conv] = counters.get(conv, -1) + 1
        known[key] = counters[conv]
        out.append(counters[conv])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n1'], ['d', 'al', 'n1']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1']], {'c': ['al']}), [1, 2])], 2: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n2'], ['d', 'al', 'n2']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2']], {'c': ['al']}), [1, 2, 3])], 3: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n3'], ['d', 'al', 'n3']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3']], {'c': ['al']}), [1, 2, 3, 4])], 4: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n4'], ['d', 'al', 'n4']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4']], {'c': ['al']}), [1, 2, 3, 4, 5])], 5: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n5'], ['d', 'al', 'n5']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4'], ['c', 'al', 'm5']], {'c': ['al']}), [1, 2, 3, 4, 5, 6])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(requests, members):
    counters = {}
    known = {}
    out = []
    for conv, sender, nonce in requests:
        if sender not in members.get(conv, []):
            out.append('forbidden')
            continue
        key = (conv, sender, nonce)
        if key in known:
            out.append(known[key])
            continue
        counters[conv] = counters.get(conv, 0) + (1 if conv in counters else 0)
        known[key] = counters[conv]
        out.append(counters[conv])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n1'], ['d', 'al', 'n1']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1']], {'c': ['al']}), [1, 2])], 2: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n2'], ['d', 'al', 'n2']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2']], {'c': ['al']}), [1, 2, 3])], 3: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n3'], ['d', 'al', 'n3']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3']], {'c': ['al']}), [1, 2, 3, 4])], 4: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n4'], ['d', 'al', 'n4']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4']], {'c': ['al']}), [1, 2, 3, 4, 5])], 5: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n5'], ['d', 'al', 'n5']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4'], ['c', 'al', 'm5']], {'c': ['al']}), [1, 2, 3, 4, 5, 6])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The first message of a conversation receives seq 0 instead of 1.

requests are [conv, sender, nonce] in arrival order; members maps conv -> member list. A sender who is not a member gets "forbidden" and consumes nothing. Each conversation numbers accepted messages 1, 2, 3... A retry with the same (conv, sender, nonce) returns the originally assigned seq without consuming a new one.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(requests, members):
    counters = {}
    known = {}
    out = []
    for conv, sender, nonce in requests:
        if sender not in members.get(conv, []):
            out.append('forbidden')
            continue
        key = (conv, sender, nonce)
        if key in known:
            out.append(counters[conv])
            continue
        counters[conv] = counters.get(conv, 0) + 1
        known[key] = counters[conv]
        out.append(counters[conv])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n1'], ['d', 'al', 'n1']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1']], {'c': ['al']}), [1, 2])], 2: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n2'], ['d', 'al', 'n2']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2']], {'c': ['al']}), [1, 2, 3])], 3: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n3'], ['d', 'al', 'n3']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3']], {'c': ['al']}), [1, 2, 3, 4])], 4: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n4'], ['d', 'al', 'n4']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4']], {'c': ['al']}), [1, 2, 3, 4, 5])], 5: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n5'], ['d', 'al', 'n5']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4'], ['c', 'al', 'm5']], {'c': ['al']}), [1, 2, 3, 4, 5, 6])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(requests, members):
    counters = {}
    known = {}
    out = []
    for conv, sender, nonce in requests:
        if sender not in members.get(conv, []):
            out.append('forbidden')
            continue
        key = (conv, sender, nonce)
        if key in known:
            out.append('duplicate')
            continue
        counters[conv] = counters.get(conv, 0) + 1
        known[key] = counters[conv]
        out.append(counters[conv])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n1'], ['d', 'al', 'n1']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1']], {'c': ['al']}), [1, 2])], 2: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n2'], ['d', 'al', 'n2']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2']], {'c': ['al']}), [1, 2, 3])], 3: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n3'], ['d', 'al', 'n3']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3']], {'c': ['al']}), [1, 2, 3, 4])], 4: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n4'], ['d', 'al', 'n4']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4']], {'c': ['al']}), [1, 2, 3, 4, 5])], 5: [('nonce reused by another sender', ([['c', 'al', 'n1'], ['c', 'bo', 'n1']], {'c': ['al', 'bo']}), [1, 2]), ('nonce reused in another conversation', ([['d', 'al', 'z'], ['c', 'al', 'n5'], ['d', 'al', 'n5']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('two conversations interleaved', ([['c', 'al', 'a'], ['d', 'al', 'b'], ['c', 'al', 'c']], {'c': ['al'], 'd': ['al']}), [1, 1, 2]), ('retry returns original', ([['c', 'al', 'x'], ['c', 'al', 'y'], ['c', 'al', 'x']], {'c': ['al']}), [1, 2, 1]), ('forbidden sender', ([['c', 'eve', 'z'], ['c', 'al', 'q']], {'c': ['al']}), ['forbidden', 1]), ('burst', ([['c', 'al', 'm0'], ['c', 'al', 'm1'], ['c', 'al', 'm2'], ['c', 'al', 'm3'], ['c', 'al', 'm4'], ['c', 'al', 'm5']], {'c': ['al']}), [1, 2, 3, 4, 5, 6])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A retried send is told it received the newest seq of the conversation instead of its own.

requests are [conv, sender, nonce] in arrival order; members maps conv -> member list. A sender who is not a member gets "forbidden" and consumes nothing. Each conversation numbers accepted messages 1, 2, 3... A retry with the same (conv, sender, nonce) returns the originally assigned seq without consuming a new one.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(convs):
    def activity(c):
        return max(c['last_msg'], c['last_silent'], c['draft_ts'] or 0)
    pinned = sorted((c for c in convs if c['pinned'] is not None), key=lambda c: c['pinned'])
    rest = sorted((c for c in convs if c['pinned'] is None), key=lambda c: (-activity(c), c['id']))
    return [c['id'] for c in pinned + rest]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 21, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 4, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 21, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 91, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 2: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 22, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 22, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 92, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 3: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 23, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 6, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 23, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 93, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 4: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 24, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 24, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 94, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 5: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 25, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': None}],), ['z', 'c', 'm']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 25, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 95, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(convs):
    def activity(c):
        return max(c['last_msg'], c['draft_ts'] or c['last_silent'])
    pinned = sorted((c for c in convs if c['pinned'] is not None), key=lambda c: c['pinned'])
    rest = sorted((c for c in convs if c['pinned'] is None), key=lambda c: (-activity(c), c['id']))
    return [c['id'] for c in pinned + rest]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 21, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 4, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 21, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 91, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 2: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 22, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 22, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 92, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 3: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 23, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 6, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 23, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 93, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 4: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 24, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 24, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 94, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 5: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 25, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': None}],), ['z', 'c', 'm']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 25, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 95, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A conversation jumps to the top because someone changed its avatar or topic.

convs {id, pinned (rank or None), last_msg, last_silent, draft_ts (or None)}. Pinned conversations come first by pin rank (rank 0 is a valid pin). The rest are ordered by activity descending, then id ascending, where activity is the later of the last real message and the local draft; silent events (avatar or topic changes) never count.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(convs):
    def activity(c):
        return max(c['last_msg'], c['draft_ts'] or 0)
    pinned = sorted((c for c in convs if c['pinned']), key=lambda c: c['pinned'])
    rest = sorted((c for c in convs if c['pinned'] is None), key=lambda c: (-activity(c), c['id']))
    return [c['id'] for c in pinned + rest]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 21, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 4, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 21, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 91, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 2: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 22, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 22, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 92, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 3: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 23, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 6, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 23, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 93, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 4: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 24, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 24, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 94, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 5: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 25, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': None}],), ['z', 'c', 'm']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 25, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 95, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(convs):
    def activity(c):
        return max(c['last_msg'], c['draft_ts'] or 0)
    pinned = sorted((c for c in convs if c['pinned'] not in (None, False)), key=lambda c: c['pinned'])
    rest = sorted((c for c in convs if c['pinned'] is None), key=lambda c: (-activity(c), c['id']))
    return [c['id'] for c in pinned + rest]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 21, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 4, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 21, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 91, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 2: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 22, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 22, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 92, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 3: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 23, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 6, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 23, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 93, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 4: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 24, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}],), ['c', 'm', 'z']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 24, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 94, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])], 5: [('silent topic change', ([{'id': 'a', 'pinned': None, 'last_msg': 10, 'last_silent': 99, 'draft_ts': None}, {'id': 'b', 'pinned': None, 'last_msg': 25, 'last_silent': 0, 'draft_ts': None}],), ['b', 'a']), ('pin rank zero', ([{'id': 'p0', 'pinned': 0, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'p1', 'pinned': 1, 'last_msg': 2, 'last_silent': 0, 'draft_ts': None}, {'id': 'x', 'pinned': None, 'last_msg': 50, 'last_silent': 0, 'draft_ts': None}],), ['p0', 'p1', 'x']), ('activity ties', ([{'id': 'm', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'c', 'pinned': None, 'last_msg': 7, 'last_silent': 0, 'draft_ts': None}, {'id': 'z', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': None}],), ['z', 'c', 'm']), ('draft bumps', ([{'id': 'd', 'pinned': None, 'last_msg': 5, 'last_silent': 0, 'draft_ts': 30}, {'id': 'e', 'pinned': None, 'last_msg': 25, 'last_silent': 0, 'draft_ts': None}],), ['d', 'e']), ('pins by rank not activity', ([{'id': 'old', 'pinned': 1, 'last_msg': 1, 'last_silent': 0, 'draft_ts': None}, {'id': 'new', 'pinned': 2, 'last_msg': 95, 'last_silent': 0, 'draft_ts': None}],), ['old', 'new']), ('silent without draft', ([{'id': 'q', 'pinned': None, 'last_msg': 4, 'last_silent': 60, 'draft_ts': None}, {'id': 'r', 'pinned': None, 'last_msg': 8, 'last_silent': 0, 'draft_ts': 2}],), ['r', 'q'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The conversation pinned at rank 0 disappears from the list.

convs {id, pinned (rank or None), last_msg, last_silent, draft_ts (or None)}. Pinned conversations come first by pin rank (rank 0 is a valid pin). The rest are ordered by activity descending, then id ascending, where activity is the later of the last real message and the local draft; silent events (avatar or topic changes) never count.

split: open-access