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

N = 1
observations = []
def solve(a, b):
    def covered(c, rep, n):
        return n < c['vv'].get(rep, 0) or [rep, n] in c['cloud']
    da = {tuple(x) for x in a['dots']}
    db = {tuple(x) for x in b['dots']}
    dots = (da & db) | {x for x in da if not covered(b, x[1], x[2])} | {x for x in db if not covered(a, x[1], x[2])}
    vv = dict(a['vv'])
    for rep, n in b['vv'].items():
        vv[rep] = max(vv.get(rep, 0), n)
    cloud = {tuple(x) for x in a['cloud']} | {tuple(x) for x in b['cloud']}
    changed = True
    while changed:
        changed = False
        for rep, n in sorted(cloud):
            if n == vv.get(rep, 0) + 1:
                vv[rep] = n
                cloud.discard((rep, n))
                changed = True
            elif n <= vv.get(rep, 0):
                cloud.discard((rep, n))
                changed = True
    return {'elements': sorted({x[0] for x in dots}), 'dots': sorted([list(x) for x in dots]), 'vv': sorted([k, v] for k, v in vv.items()), 'cloud': sorted([list(x) for x in cloud])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 1]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 3]], 'vv': {'c': 1}, 'cloud': [['c', 3]]}, {'dots': [['w', 'c', 2]], 'vv': {'c': 1}, 'cloud': [['c', 2]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 2], ['z', 'c', 3]], 'vv': [['c', 3]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 5]], 'vv': {}, 'cloud': [['a', 5]]}], {'elements': ['q'], 'dots': [['q', 'a', 5]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 5]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['r'], 'dots': [['r', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 4]]}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 1], ['k', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 1]], 'vv': [['a', 1], ['b', 1]], 'cloud': []})],
    2: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [], 'vv': {'a': 2}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 2]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 4]], 'vv': {'c': 2}, 'cloud': [['c', 4]]}, {'dots': [['w', 'c', 3]], 'vv': {'c': 2}, 'cloud': [['c', 3]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 3], ['z', 'c', 4]], 'vv': [['c', 4]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 6]], 'vv': {}, 'cloud': [['a', 6]]}], {'elements': ['q'], 'dots': [['q', 'a', 6]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 6]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 2]], 'vv': {'a': 2, 'b': 2}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 2], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 2]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 5]]}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 2], ['k', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 2]], 'vv': [['a', 2], ['b', 1]], 'cloud': []})],
    3: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 3]], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 3}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 3]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 5]], 'vv': {'c': 3}, 'cloud': [['c', 5]]}, {'dots': [['w', 'c', 4]], 'vv': {'c': 3}, 'cloud': [['c', 4]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 4], ['z', 'c', 5]], 'vv': [['c', 5]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 7]], 'vv': {}, 'cloud': [['a', 7]]}], {'elements': ['q'], 'dots': [['q', 'a', 7]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 7]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 3]], 'vv': {'a': 2, 'b': 3}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 3], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 3]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 6]]}], {'elements': [], 'dots': [], 'vv': [['a', 6]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 3], ['k', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 3]], 'vv': [['a', 3], ['b', 1]], 'cloud': []})],
    4: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 4]], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 4}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 6]], 'vv': {'c': 4}, 'cloud': [['c', 6]]}, {'dots': [['w', 'c', 5]], 'vv': {'c': 4}, 'cloud': [['c', 5]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 5], ['z', 'c', 6]], 'vv': [['c', 6]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 8]], 'vv': {}, 'cloud': [['a', 8]]}], {'elements': ['q'], 'dots': [['q', 'a', 8]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 8]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 4]], 'vv': {'a': 2, 'b': 4}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 4], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 4]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 6}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 7]]}], {'elements': [], 'dots': [], 'vv': [['a', 7]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 4], ['k', 'b', 1]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []})],
    5: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 5]], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 5}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 7]], 'vv': {'c': 5}, 'cloud': [['c', 7]]}, {'dots': [['w', 'c', 6]], 'vv': {'c': 5}, 'cloud': [['c', 6]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 6], ['z', 'c', 7]], 'vv': [['c', 7]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 9]], 'vv': {}, 'cloud': [['a', 9]]}], {'elements': ['q'], 'dots': [['q', 'a', 9]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 9]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 5]], 'vv': {'a': 2, 'b': 5}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 5], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 5]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 7}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 8]]}], {'elements': [], 'dots': [], 'vv': [['a', 8]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 5], ['k', 'b', 1]], 'vv': {'a': 5, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 5]], 'vv': [['a', 5], ['b', 1]], 'cloud': []})],
}[N]
for label, args, expected in cases:
    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(a, b):
    def covered(c, rep, n):
        return n <= c['vv'].get(rep, 1) or [rep, n] in c['cloud']
    da = {tuple(x) for x in a['dots']}
    db = {tuple(x) for x in b['dots']}
    dots = (da & db) | {x for x in da if not covered(b, x[1], x[2])} | {x for x in db if not covered(a, x[1], x[2])}
    vv = dict(a['vv'])
    for rep, n in b['vv'].items():
        vv[rep] = max(vv.get(rep, 0), n)
    cloud = {tuple(x) for x in a['cloud']} | {tuple(x) for x in b['cloud']}
    changed = True
    while changed:
        changed = False
        for rep, n in sorted(cloud):
            if n == vv.get(rep, 0) + 1:
                vv[rep] = n
                cloud.discard((rep, n))
                changed = True
            elif n <= vv.get(rep, 0):
                cloud.discard((rep, n))
                changed = True
    return {'elements': sorted({x[0] for x in dots}), 'dots': sorted([list(x) for x in dots]), 'vv': sorted([k, v] for k, v in vv.items()), 'cloud': sorted([list(x) for x in cloud])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 1]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 3]], 'vv': {'c': 1}, 'cloud': [['c', 3]]}, {'dots': [['w', 'c', 2]], 'vv': {'c': 1}, 'cloud': [['c', 2]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 2], ['z', 'c', 3]], 'vv': [['c', 3]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 5]], 'vv': {}, 'cloud': [['a', 5]]}], {'elements': ['q'], 'dots': [['q', 'a', 5]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 5]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['r'], 'dots': [['r', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 4]]}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 1], ['k', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 1]], 'vv': [['a', 1], ['b', 1]], 'cloud': []})],
    2: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [], 'vv': {'a': 2}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 2]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 4]], 'vv': {'c': 2}, 'cloud': [['c', 4]]}, {'dots': [['w', 'c', 3]], 'vv': {'c': 2}, 'cloud': [['c', 3]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 3], ['z', 'c', 4]], 'vv': [['c', 4]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 6]], 'vv': {}, 'cloud': [['a', 6]]}], {'elements': ['q'], 'dots': [['q', 'a', 6]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 6]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 2]], 'vv': {'a': 2, 'b': 2}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 2], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 2]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 5]]}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 2], ['k', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 2]], 'vv': [['a', 2], ['b', 1]], 'cloud': []})],
    3: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 3]], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 3}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 3]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 5]], 'vv': {'c': 3}, 'cloud': [['c', 5]]}, {'dots': [['w', 'c', 4]], 'vv': {'c': 3}, 'cloud': [['c', 4]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 4], ['z', 'c', 5]], 'vv': [['c', 5]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 7]], 'vv': {}, 'cloud': [['a', 7]]}], {'elements': ['q'], 'dots': [['q', 'a', 7]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 7]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 3]], 'vv': {'a': 2, 'b': 3}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 3], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 3]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 6]]}], {'elements': [], 'dots': [], 'vv': [['a', 6]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 3], ['k', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 3]], 'vv': [['a', 3], ['b', 1]], 'cloud': []})],
    4: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 4]], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 4}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 6]], 'vv': {'c': 4}, 'cloud': [['c', 6]]}, {'dots': [['w', 'c', 5]], 'vv': {'c': 4}, 'cloud': [['c', 5]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 5], ['z', 'c', 6]], 'vv': [['c', 6]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 8]], 'vv': {}, 'cloud': [['a', 8]]}], {'elements': ['q'], 'dots': [['q', 'a', 8]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 8]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 4]], 'vv': {'a': 2, 'b': 4}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 4], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 4]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 6}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 7]]}], {'elements': [], 'dots': [], 'vv': [['a', 7]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 4], ['k', 'b', 1]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []})],
    5: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 5]], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 5}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 7]], 'vv': {'c': 5}, 'cloud': [['c', 7]]}, {'dots': [['w', 'c', 6]], 'vv': {'c': 5}, 'cloud': [['c', 6]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 6], ['z', 'c', 7]], 'vv': [['c', 7]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 9]], 'vv': {}, 'cloud': [['a', 9]]}], {'elements': ['q'], 'dots': [['q', 'a', 9]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 9]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 5]], 'vv': {'a': 2, 'b': 5}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 5], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 5]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 7}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 8]]}], {'elements': [], 'dots': [], 'vv': [['a', 8]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 5], ['k', 'b', 1]], 'vv': {'a': 5, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 5]], 'vv': [['a', 5], ['b', 1]], 'cloud': []})],
}[N]
for label, args, expected in cases:
    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:
An element removed at the peer survives when its dot equals the peer's vector entry.

A state is {"dots": [[element, replica, n]], "vv": {replica: n}, "cloud": [[replica, n]]}. A context covers (r, n) when n <= vv[r] or [r, n] is in the cloud. Join keeps dots present in both states plus dots of one state not covered by the other's context; contexts join by vector maximum and cloud union, then the cloud is compacted: an entry equal to vv[r]+1 advances vv[r], entries at or below vv[r] are pruned. Return elements, dots, vector and cloud, all sorted.

split: open-access


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

N = 1
observations = []
def solve(a, b):
    def covered(c, rep, n):
        return n <= c['vv'].get(rep, 0) or [rep, n] in c['cloud']
    da = {tuple(x) for x in a['dots']}
    db = {tuple(x) for x in b['dots']}
    dots = (da & db) | {x for x in da if not covered(b, x[1], x[2])} | {x for x in db if not covered(a, x[1], x[2])}
    vv = dict(a['vv'])
    for rep, n in b['vv'].items():
        vv[rep] = n
    cloud = {tuple(x) for x in a['cloud']} | {tuple(x) for x in b['cloud']}
    changed = True
    while changed:
        changed = False
        for rep, n in sorted(cloud):
            if n == vv.get(rep, 0) + 1:
                vv[rep] = n
                cloud.discard((rep, n))
                changed = True
            elif n <= vv.get(rep, 0):
                cloud.discard((rep, n))
                changed = True
    return {'elements': sorted({x[0] for x in dots}), 'dots': sorted([list(x) for x in dots]), 'vv': sorted([k, v] for k, v in vv.items()), 'cloud': sorted([list(x) for x in cloud])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 1]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 3]], 'vv': {'c': 1}, 'cloud': [['c', 3]]}, {'dots': [['w', 'c', 2]], 'vv': {'c': 1}, 'cloud': [['c', 2]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 2], ['z', 'c', 3]], 'vv': [['c', 3]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 5]], 'vv': {}, 'cloud': [['a', 5]]}], {'elements': ['q'], 'dots': [['q', 'a', 5]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 5]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['r'], 'dots': [['r', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 4]]}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 1], ['k', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 1]], 'vv': [['a', 1], ['b', 1]], 'cloud': []})],
    2: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [], 'vv': {'a': 2}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 2]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 4]], 'vv': {'c': 2}, 'cloud': [['c', 4]]}, {'dots': [['w', 'c', 3]], 'vv': {'c': 2}, 'cloud': [['c', 3]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 3], ['z', 'c', 4]], 'vv': [['c', 4]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 6]], 'vv': {}, 'cloud': [['a', 6]]}], {'elements': ['q'], 'dots': [['q', 'a', 6]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 6]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 2]], 'vv': {'a': 2, 'b': 2}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 2], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 2]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 5]]}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 2], ['k', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 2]], 'vv': [['a', 2], ['b', 1]], 'cloud': []})],
    3: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 3]], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 3}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 3]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 5]], 'vv': {'c': 3}, 'cloud': [['c', 5]]}, {'dots': [['w', 'c', 4]], 'vv': {'c': 3}, 'cloud': [['c', 4]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 4], ['z', 'c', 5]], 'vv': [['c', 5]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 7]], 'vv': {}, 'cloud': [['a', 7]]}], {'elements': ['q'], 'dots': [['q', 'a', 7]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 7]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 3]], 'vv': {'a': 2, 'b': 3}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 3], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 3]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 6]]}], {'elements': [], 'dots': [], 'vv': [['a', 6]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 3], ['k', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 3]], 'vv': [['a', 3], ['b', 1]], 'cloud': []})],
    4: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 4]], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 4}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 6]], 'vv': {'c': 4}, 'cloud': [['c', 6]]}, {'dots': [['w', 'c', 5]], 'vv': {'c': 4}, 'cloud': [['c', 5]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 5], ['z', 'c', 6]], 'vv': [['c', 6]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 8]], 'vv': {}, 'cloud': [['a', 8]]}], {'elements': ['q'], 'dots': [['q', 'a', 8]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 8]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 4]], 'vv': {'a': 2, 'b': 4}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 4], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 4]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 6}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 7]]}], {'elements': [], 'dots': [], 'vv': [['a', 7]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 4], ['k', 'b', 1]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []})],
    5: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 5]], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 5}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 7]], 'vv': {'c': 5}, 'cloud': [['c', 7]]}, {'dots': [['w', 'c', 6]], 'vv': {'c': 5}, 'cloud': [['c', 6]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 6], ['z', 'c', 7]], 'vv': [['c', 7]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 9]], 'vv': {}, 'cloud': [['a', 9]]}], {'elements': ['q'], 'dots': [['q', 'a', 9]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 9]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 5]], 'vv': {'a': 2, 'b': 5}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 5], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 5]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 7}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 8]]}], {'elements': [], 'dots': [], 'vv': [['a', 8]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 5], ['k', 'b', 1]], 'vv': {'a': 5, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 5]], 'vv': [['a', 5], ['b', 1]], 'cloud': []})],
}[N]
for label, args, expected in cases:
    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(a, b):
    def covered(c, rep, n):
        return n <= c['vv'].get(rep, 0) or [rep, n] in c['cloud']
    da = {tuple(x) for x in a['dots']}
    db = {tuple(x) for x in b['dots']}
    dots = (da & db) | {x for x in da if not covered(b, x[1], x[2])} | {x for x in db if not covered(a, x[1], x[2])}
    vv = dict(a['vv'])
    for rep, n in b['vv'].items():
        if rep in vv:
            vv[rep] = max(vv[rep], n)
    cloud = {tuple(x) for x in a['cloud']} | {tuple(x) for x in b['cloud']}
    changed = True
    while changed:
        changed = False
        for rep, n in sorted(cloud):
            if n == vv.get(rep, 0) + 1:
                vv[rep] = n
                cloud.discard((rep, n))
                changed = True
            elif n <= vv.get(rep, 0):
                cloud.discard((rep, n))
                changed = True
    return {'elements': sorted({x[0] for x in dots}), 'dots': sorted([list(x) for x in dots]), 'vv': sorted([k, v] for k, v in vv.items()), 'cloud': sorted([list(x) for x in cloud])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 1]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 3]], 'vv': {'c': 1}, 'cloud': [['c', 3]]}, {'dots': [['w', 'c', 2]], 'vv': {'c': 1}, 'cloud': [['c', 2]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 2], ['z', 'c', 3]], 'vv': [['c', 3]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 5]], 'vv': {}, 'cloud': [['a', 5]]}], {'elements': ['q'], 'dots': [['q', 'a', 5]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 5]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['r'], 'dots': [['r', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 4]]}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 1], ['k', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 1]], 'vv': [['a', 1], ['b', 1]], 'cloud': []})],
    2: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [], 'vv': {'a': 2}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 2]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 4]], 'vv': {'c': 2}, 'cloud': [['c', 4]]}, {'dots': [['w', 'c', 3]], 'vv': {'c': 2}, 'cloud': [['c', 3]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 3], ['z', 'c', 4]], 'vv': [['c', 4]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 6]], 'vv': {}, 'cloud': [['a', 6]]}], {'elements': ['q'], 'dots': [['q', 'a', 6]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 6]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 2]], 'vv': {'a': 2, 'b': 2}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 2], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 2]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 5]]}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 2], ['k', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 2]], 'vv': [['a', 2], ['b', 1]], 'cloud': []})],
    3: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 3]], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 3}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 3]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 5]], 'vv': {'c': 3}, 'cloud': [['c', 5]]}, {'dots': [['w', 'c', 4]], 'vv': {'c': 3}, 'cloud': [['c', 4]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 4], ['z', 'c', 5]], 'vv': [['c', 5]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 7]], 'vv': {}, 'cloud': [['a', 7]]}], {'elements': ['q'], 'dots': [['q', 'a', 7]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 7]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 3]], 'vv': {'a': 2, 'b': 3}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 3], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 3]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 6]]}], {'elements': [], 'dots': [], 'vv': [['a', 6]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 3], ['k', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 3]], 'vv': [['a', 3], ['b', 1]], 'cloud': []})],
    4: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 4]], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 4}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 6]], 'vv': {'c': 4}, 'cloud': [['c', 6]]}, {'dots': [['w', 'c', 5]], 'vv': {'c': 4}, 'cloud': [['c', 5]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 5], ['z', 'c', 6]], 'vv': [['c', 6]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 8]], 'vv': {}, 'cloud': [['a', 8]]}], {'elements': ['q'], 'dots': [['q', 'a', 8]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 8]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 4]], 'vv': {'a': 2, 'b': 4}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 4], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 4]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 6}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 7]]}], {'elements': [], 'dots': [], 'vv': [['a', 7]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 4], ['k', 'b', 1]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []})],
    5: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 5]], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 5}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 7]], 'vv': {'c': 5}, 'cloud': [['c', 7]]}, {'dots': [['w', 'c', 6]], 'vv': {'c': 5}, 'cloud': [['c', 6]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 6], ['z', 'c', 7]], 'vv': [['c', 7]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 9]], 'vv': {}, 'cloud': [['a', 9]]}], {'elements': ['q'], 'dots': [['q', 'a', 9]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 9]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 5]], 'vv': {'a': 2, 'b': 5}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 5], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 5]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 7}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 8]]}], {'elements': [], 'dots': [], 'vv': [['a', 8]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 5], ['k', 'b', 1]], 'vv': {'a': 5, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 5]], 'vv': [['a', 5], ['b', 1]], 'cloud': []})],
}[N]
for label, args, expected in cases:
    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 joined context regresses, later letting removed dots reappear.

A state is {"dots": [[element, replica, n]], "vv": {replica: n}, "cloud": [[replica, n]]}. A context covers (r, n) when n <= vv[r] or [r, n] is in the cloud. Join keeps dots present in both states plus dots of one state not covered by the other's context; contexts join by vector maximum and cloud union, then the cloud is compacted: an entry equal to vv[r]+1 advances vv[r], entries at or below vv[r] are pruned. Return elements, dots, vector and cloud, all sorted.

split: open-access


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

N = 1
observations = []
def solve(a, b):
    def covered(c, rep, n):
        return n <= c['vv'].get(rep, 0) or [rep, n] in c['cloud']
    da = {tuple(x) for x in a['dots']}
    db = {tuple(x) for x in b['dots']}
    dots = (da & db) | {x for x in da if not covered(b, x[1], x[2])} | {x for x in db if not covered(a, x[1], x[2])}
    vv = dict(a['vv'])
    for rep, n in b['vv'].items():
        vv[rep] = max(vv.get(rep, 0), n)
    cloud = {tuple(x) for x in a['cloud']} | {tuple(x) for x in b['cloud']}
    changed = True
    while changed:
        changed = False
        for rep, n in sorted(cloud):
            if n >= vv.get(rep, 0) + 1:
                vv[rep] = n
                cloud.discard((rep, n))
                changed = True
            elif n <= vv.get(rep, 0):
                cloud.discard((rep, n))
                changed = True
    return {'elements': sorted({x[0] for x in dots}), 'dots': sorted([list(x) for x in dots]), 'vv': sorted([k, v] for k, v in vv.items()), 'cloud': sorted([list(x) for x in cloud])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 1]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 3]], 'vv': {'c': 1}, 'cloud': [['c', 3]]}, {'dots': [['w', 'c', 2]], 'vv': {'c': 1}, 'cloud': [['c', 2]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 2], ['z', 'c', 3]], 'vv': [['c', 3]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 5]], 'vv': {}, 'cloud': [['a', 5]]}], {'elements': ['q'], 'dots': [['q', 'a', 5]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 5]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['r'], 'dots': [['r', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 4]]}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 1], ['k', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 1]], 'vv': [['a', 1], ['b', 1]], 'cloud': []})],
    2: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [], 'vv': {'a': 2}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 2]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 4]], 'vv': {'c': 2}, 'cloud': [['c', 4]]}, {'dots': [['w', 'c', 3]], 'vv': {'c': 2}, 'cloud': [['c', 3]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 3], ['z', 'c', 4]], 'vv': [['c', 4]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 6]], 'vv': {}, 'cloud': [['a', 6]]}], {'elements': ['q'], 'dots': [['q', 'a', 6]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 6]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 2]], 'vv': {'a': 2, 'b': 2}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 2], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 2]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 5]]}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 2], ['k', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 2]], 'vv': [['a', 2], ['b', 1]], 'cloud': []})],
    3: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 3]], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 3}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 3]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 5]], 'vv': {'c': 3}, 'cloud': [['c', 5]]}, {'dots': [['w', 'c', 4]], 'vv': {'c': 3}, 'cloud': [['c', 4]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 4], ['z', 'c', 5]], 'vv': [['c', 5]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 7]], 'vv': {}, 'cloud': [['a', 7]]}], {'elements': ['q'], 'dots': [['q', 'a', 7]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 7]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 3]], 'vv': {'a': 2, 'b': 3}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 3], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 3]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 6]]}], {'elements': [], 'dots': [], 'vv': [['a', 6]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 3], ['k', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 3]], 'vv': [['a', 3], ['b', 1]], 'cloud': []})],
    4: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 4]], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 4}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 6]], 'vv': {'c': 4}, 'cloud': [['c', 6]]}, {'dots': [['w', 'c', 5]], 'vv': {'c': 4}, 'cloud': [['c', 5]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 5], ['z', 'c', 6]], 'vv': [['c', 6]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 8]], 'vv': {}, 'cloud': [['a', 8]]}], {'elements': ['q'], 'dots': [['q', 'a', 8]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 8]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 4]], 'vv': {'a': 2, 'b': 4}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 4], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 4]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 6}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 7]]}], {'elements': [], 'dots': [], 'vv': [['a', 7]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 4], ['k', 'b', 1]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []})],
    5: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 5]], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 5}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 7]], 'vv': {'c': 5}, 'cloud': [['c', 7]]}, {'dots': [['w', 'c', 6]], 'vv': {'c': 5}, 'cloud': [['c', 6]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 6], ['z', 'c', 7]], 'vv': [['c', 7]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 9]], 'vv': {}, 'cloud': [['a', 9]]}], {'elements': ['q'], 'dots': [['q', 'a', 9]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 9]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 5]], 'vv': {'a': 2, 'b': 5}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 5], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 5]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 7}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 8]]}], {'elements': [], 'dots': [], 'vv': [['a', 8]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 5], ['k', 'b', 1]], 'vv': {'a': 5, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 5]], 'vv': [['a', 5], ['b', 1]], 'cloud': []})],
}[N]
for label, args, expected in cases:
    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(a, b):
    def covered(c, rep, n):
        return n <= c['vv'].get(rep, 0) or [rep, n] in c['cloud']
    da = {tuple(x) for x in a['dots']}
    db = {tuple(x) for x in b['dots']}
    dots = (da & db) | {x for x in da if not covered(b, x[1], x[2])} | {x for x in db if not covered(a, x[1], x[2])}
    vv = dict(a['vv'])
    for rep, n in b['vv'].items():
        vv[rep] = max(vv.get(rep, 0), n)
    cloud = {tuple(x) for x in a['cloud']} | {tuple(x) for x in b['cloud']}
    changed = True
    while changed:
        changed = False
        for rep, n in sorted(cloud):
            if n == vv.get(rep, 0) + 1 and rep in vv:
                vv[rep] = n
                cloud.discard((rep, n))
                changed = True
            elif n <= vv.get(rep, 0):
                cloud.discard((rep, n))
                changed = True
    return {'elements': sorted({x[0] for x in dots}), 'dots': sorted([list(x) for x in dots]), 'vv': sorted([k, v] for k, v in vv.items()), 'cloud': sorted([list(x) for x in cloud])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 1]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 3]], 'vv': {'c': 1}, 'cloud': [['c', 3]]}, {'dots': [['w', 'c', 2]], 'vv': {'c': 1}, 'cloud': [['c', 2]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 2], ['z', 'c', 3]], 'vv': [['c', 3]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 5]], 'vv': {}, 'cloud': [['a', 5]]}], {'elements': ['q'], 'dots': [['q', 'a', 5]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 5]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['r'], 'dots': [['r', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 4]]}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 1], ['k', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 1]], 'vv': [['a', 1], ['b', 1]], 'cloud': []})],
    2: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [], 'vv': {'a': 2}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 2]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 4]], 'vv': {'c': 2}, 'cloud': [['c', 4]]}, {'dots': [['w', 'c', 3]], 'vv': {'c': 2}, 'cloud': [['c', 3]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 3], ['z', 'c', 4]], 'vv': [['c', 4]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 6]], 'vv': {}, 'cloud': [['a', 6]]}], {'elements': ['q'], 'dots': [['q', 'a', 6]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 6]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 2]], 'vv': {'a': 2, 'b': 2}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 2], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 2]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 5]]}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 2], ['k', 'b', 1]], 'vv': {'a': 2, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 2]], 'vv': [['a', 2], ['b', 1]], 'cloud': []})],
    3: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 3]], 'vv': {'a': 3}, 'cloud': []}, {'dots': [], 'vv': {'a': 3}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 3]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 5]], 'vv': {'c': 3}, 'cloud': [['c', 5]]}, {'dots': [['w', 'c', 4]], 'vv': {'c': 3}, 'cloud': [['c', 4]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 4], ['z', 'c', 5]], 'vv': [['c', 5]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 7]], 'vv': {}, 'cloud': [['a', 7]]}], {'elements': ['q'], 'dots': [['q', 'a', 7]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 7]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 3]], 'vv': {'a': 2, 'b': 3}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 3], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 3]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 6]]}], {'elements': [], 'dots': [], 'vv': [['a', 6]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 3], ['k', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 3]], 'vv': [['a', 3], ['b', 1]], 'cloud': []})],
    4: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 4]], 'vv': {'a': 4}, 'cloud': []}, {'dots': [], 'vv': {'a': 4}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 4]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 6]], 'vv': {'c': 4}, 'cloud': [['c', 6]]}, {'dots': [['w', 'c', 5]], 'vv': {'c': 4}, 'cloud': [['c', 5]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 5], ['z', 'c', 6]], 'vv': [['c', 6]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 8]], 'vv': {}, 'cloud': [['a', 8]]}], {'elements': ['q'], 'dots': [['q', 'a', 8]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 8]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 4]], 'vv': {'a': 2, 'b': 4}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 4], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 4]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 6}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 7]]}], {'elements': [], 'dots': [], 'vv': [['a', 7]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 4], ['k', 'b', 1]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 4]], 'vv': [['a', 4], ['b', 1]], 'cloud': []})],
    5: [('dot unseen by the peer survives', [{'dots': [['x', 'a', 1]], 'vv': {'a': 1}, 'cloud': []}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['x'], 'dots': [['x', 'a', 1]], 'vv': [['a', 1]], 'cloud': []}), ('dot removed by the peer is dropped', [{'dots': [['x', 'a', 1], ['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}, {'dots': [['y', 'a', 2]], 'vv': {'a': 2}, 'cloud': []}], {'elements': ['y'], 'dots': [['y', 'a', 2]], 'vv': [['a', 2]], 'cloud': []}), ('dot covered only by the peer cloud is dropped', [{'dots': [['x', 'a', 3], ['y', 'b', 1]], 'vv': {'a': 3, 'b': 1}, 'cloud': []}, {'dots': [['y', 'b', 1]], 'vv': {'a': 1, 'b': 1}, 'cloud': [['a', 3]]}], {'elements': ['y'], 'dots': [['y', 'b', 1]], 'vv': [['a', 3], ['b', 1]], 'cloud': []}), ('dot at the vector boundary is covered', [{'dots': [['x', 'a', 5]], 'vv': {'a': 5}, 'cloud': []}, {'dots': [], 'vv': {'a': 5}, 'cloud': []}], {'elements': [], 'dots': [], 'vv': [['a', 5]], 'cloud': []}), ('cloud compacts into the vector', [{'dots': [['z', 'c', 7]], 'vv': {'c': 5}, 'cloud': [['c', 7]]}, {'dots': [['w', 'c', 6]], 'vv': {'c': 5}, 'cloud': [['c', 6]]}], {'elements': ['w', 'z'], 'dots': [['w', 'c', 6], ['z', 'c', 7]], 'vv': [['c', 7]], 'cloud': []}), ('gaps stay in the cloud', [{'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 3]]}, {'dots': [['q', 'a', 9]], 'vv': {}, 'cloud': [['a', 9]]}], {'elements': ['q'], 'dots': [['q', 'a', 9]], 'vv': [['a', 1]], 'cloud': [['a', 3], ['a', 9]]}), ('vectors join by maximum', [{'dots': [['p', 'b', 5]], 'vv': {'a': 2, 'b': 5}, 'cloud': []}, {'dots': [['r', 'a', 4]], 'vv': {'a': 4, 'b': 1}, 'cloud': []}], {'elements': ['p', 'r'], 'dots': [['p', 'b', 5], ['r', 'a', 4]], 'vv': [['a', 4], ['b', 5]], 'cloud': []}), ('cloud entries for a fresh replica compact from zero', [{'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': {}, 'cloud': [['d', 1], ['d', 2]]}, {'dots': [], 'vv': {}, 'cloud': []}], {'elements': ['m'], 'dots': [['m', 'd', 1], ['m', 'd', 2]], 'vv': [['d', 2]], 'cloud': []}), ('cloud entries already under the vector are pruned', [{'dots': [], 'vv': {'a': 7}, 'cloud': []}, {'dots': [], 'vv': {'a': 1}, 'cloud': [['a', 2], ['a', 8]]}], {'elements': [], 'dots': [], 'vv': [['a', 8]], 'cloud': []}), ('peer-only dot unseen locally survives', [{'dots': [], 'vv': {'b': 1}, 'cloud': []}, {'dots': [['k', 'a', 5], ['k', 'b', 1]], 'vv': {'a': 5, 'b': 1}, 'cloud': []}], {'elements': ['k'], 'dots': [['k', 'a', 5]], 'vv': [['a', 5], ['b', 1]], 'cloud': []})],
}[N]
for label, args, expected in cases:
    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 vector claims dots that were never observed, so unseen additions are later discarded.

A state is {"dots": [[element, replica, n]], "vv": {replica: n}, "cloud": [[replica, n]]}. A context covers (r, n) when n <= vv[r] or [r, n] is in the cloud. Join keeps dots present in both states plus dots of one state not covered by the other's context; contexts join by vector maximum and cloud union, then the cloud is compacted: an entry equal to vv[r]+1 advances vv[r], entries at or below vv[r] are pruned. Return elements, dots, vector and cloud, all sorted.

split: open-access