broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import sqlite3
N = 1
observations = []
def solve(rows, refs):
    db = sqlite3.connect(':memory:')
    try:
        for name, records in [('a', rows), ('b', refs)]:
            db.execute('CREATE TABLE ' + name + ' (id INTEGER PRIMARY KEY, k TEXT, v INTEGER, w INTEGER, flag INTEGER, parent INTEGER)')
            db.executemany('INSERT INTO ' + name + ' VALUES (?,?,?,?,?,?)', records)
        return sorted([list(row) for row in db.execute('SELECT k,COUNT(*) FROM a GROUP BY k HAVING COUNT(*)<=2')], key=repr)
    finally:
        db.close()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[11, 'a', None, 8, None, None], [21, 'a', 0, 3, 0, 11], [31, 'a', 2, 1, 1, 21], [41, 'a', 2, 2, 2, 901], [51, 'a', -1, 4, -1, 31], [61, 'a', 3, 1, 1, 41], [71, 'b', -2, 2, 0, 11], [81, 'b', 2, 8, 1, 21], [91, 'b', None, 4, None, None], [101, None, None, 0, 1, 901], [111, None, 0, 5, 0, 11], [121, None, None, 7, None, 21], [131, 'c', None, 6, None, 31], [141, 'd', -1, 1, 0, 41], [151, 'A', 2, 2, 1, 51], [161, ' a ', 2, 8, 1, None], [171, '', None, 2, 0, None], [181, 'a', 2, 8, 1, 11], [191, 'd', 1, 3, 0, 41], [201, 'd', -1, 0, -1, 21]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[11, 'a', None, 0, 1, None], [21, 'a', 2, 2, 0, None], [31, 'a', 2, 3, 2, None], [41, 'a', 3, 4, None, None], [51, 'b', -2, 2, 1, None], [61, 'b', 0, 8, -1, None], [71, None, None, 2, 1, None], [81, None, 0, 5, None, None], [91, 'z', 3, 2, 0, None], [101, 'z', 3, 2, 1, None], [111, 'A', 2, 1, 1, None], [121, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[11, 'a', None, 8, None, None], [21, 'a', 0, 3, 0, 11], [31, 'a', 2, 1, 1, 21], [41, 'a', 2, 2, 2, 901], [51, 'a', -1, 4, -1, 31], [61, 'a', 3, 1, 1, 41], [71, 'b', -2, 2, 0, 11], [81, 'b', 2, 8, 1, 21], [91, 'b', None, 4, None, None], [101, None, None, 0, 1, 901], [111, None, 0, 5, 0, 11], [121, None, None, 7, None, 21], [131, 'c', None, 6, None, 31], [141, 'd', -1, 1, 0, 41], [151, 'A', 2, 2, 1, 51], [161, ' a ', 2, 8, 1, None], [171, '', None, 2, 0, None], [181, 'a', 2, 8, 1, 11], [191, 'd', 1, 3, 0, 41], [201, 'd', -1, 0, -1, 21]], [[11, 'a', None, 0, 1, None], [21, 'a', 2, 2, 0, None], [31, 'a', 2, 3, 2, None], [41, 'a', 3, 4, None, None], [51, 'b', -2, 2, 1, None], [61, 'b', 0, 8, -1, None], [71, None, None, 2, 1, None], [81, None, 0, 5, None, None], [91, 'z', 3, 2, 0, None], [101, 'z', 3, 2, 1, None], [111, 'A', 2, 1, 1, None], [121, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[11, None, None, 3, None, None], [21, None, None, 4, None, None], [31, 'x', None, 5, None, None]], [[11, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[11, 'a', 0, 9, 0, 11]], [[11, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[11, 'n', -2, 4, -1, 11], [21, 'n', None, 2, 0, 21], [31, 'n', -1, 0, 2, None]], [[11, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[11, 'p', 2, 1, 1, 11], [21, 'p', 2, 2, 1, 11], [31, 'p', 3, 0, 1, 11], [41, 'p', None, 1, 0, None]], [[11, 'p', 2, 1, 1, None], [21, 'p', 2, 1, 1, None]]), [['p', 4]])
elif N == 2:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[12, 'a', None, 8, None, None], [22, 'a', 0, 3, 0, 12], [32, 'a', 2, 1, 1, 22], [42, 'a', 2, 2, 2, 902], [52, 'a', -1, 4, -1, 32], [62, 'a', 3, 1, 1, 42], [72, 'b', -2, 2, 0, 12], [82, 'b', 2, 8, 1, 22], [92, 'b', None, 4, None, None], [102, None, None, 0, 1, 902], [112, None, 0, 5, 0, 12], [122, None, None, 7, None, 22], [132, 'c', None, 6, None, 32], [142, 'd', -1, 1, 0, 42], [152, 'A', 2, 2, 1, 52], [162, ' a ', 2, 8, 1, None], [172, '', None, 2, 0, None], [182, 'a', 2, 8, 1, 12], [192, 'd', 1, 3, 0, 42], [202, 'd', -1, 0, -1, 22]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[12, 'a', None, 0, 1, None], [22, 'a', 2, 2, 0, None], [32, 'a', 2, 3, 2, None], [42, 'a', 3, 4, None, None], [52, 'b', -2, 2, 1, None], [62, 'b', 0, 8, -1, None], [72, None, None, 2, 1, None], [82, None, 0, 5, None, None], [92, 'z', 3, 2, 0, None], [102, 'z', 3, 2, 1, None], [112, 'A', 2, 1, 1, None], [122, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[12, 'a', None, 8, None, None], [22, 'a', 0, 3, 0, 12], [32, 'a', 2, 1, 1, 22], [42, 'a', 2, 2, 2, 902], [52, 'a', -1, 4, -1, 32], [62, 'a', 3, 1, 1, 42], [72, 'b', -2, 2, 0, 12], [82, 'b', 2, 8, 1, 22], [92, 'b', None, 4, None, None], [102, None, None, 0, 1, 902], [112, None, 0, 5, 0, 12], [122, None, None, 7, None, 22], [132, 'c', None, 6, None, 32], [142, 'd', -1, 1, 0, 42], [152, 'A', 2, 2, 1, 52], [162, ' a ', 2, 8, 1, None], [172, '', None, 2, 0, None], [182, 'a', 2, 8, 1, 12], [192, 'd', 1, 3, 0, 42], [202, 'd', -1, 0, -1, 22]], [[12, 'a', None, 0, 1, None], [22, 'a', 2, 2, 0, None], [32, 'a', 2, 3, 2, None], [42, 'a', 3, 4, None, None], [52, 'b', -2, 2, 1, None], [62, 'b', 0, 8, -1, None], [72, None, None, 2, 1, None], [82, None, 0, 5, None, None], [92, 'z', 3, 2, 0, None], [102, 'z', 3, 2, 1, None], [112, 'A', 2, 1, 1, None], [122, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[12, None, None, 3, None, None], [22, None, None, 4, None, None], [32, 'x', None, 5, None, None]], [[12, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[12, 'a', 0, 9, 0, 12]], [[12, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[12, 'n', -2, 4, -1, 12], [22, 'n', None, 2, 0, 22], [32, 'n', -1, 0, 2, None]], [[12, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[12, 'p', 2, 1, 1, 12], [22, 'p', 2, 2, 1, 12], [32, 'p', 3, 0, 1, 12], [42, 'p', None, 1, 0, None]], [[12, 'p', 2, 1, 1, None], [22, 'p', 2, 1, 1, None]]), [['p', 4]])
elif N == 3:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[13, 'a', None, 8, None, None], [23, 'a', 0, 3, 0, 13], [33, 'a', 2, 1, 1, 23], [43, 'a', 2, 2, 2, 903], [53, 'a', -1, 4, -1, 33], [63, 'a', 3, 1, 1, 43], [73, 'b', -2, 2, 0, 13], [83, 'b', 2, 8, 1, 23], [93, 'b', None, 4, None, None], [103, None, None, 0, 1, 903], [113, None, 0, 5, 0, 13], [123, None, None, 7, None, 23], [133, 'c', None, 6, None, 33], [143, 'd', -1, 1, 0, 43], [153, 'A', 2, 2, 1, 53], [163, ' a ', 2, 8, 1, None], [173, '', None, 2, 0, None], [183, 'a', 2, 8, 1, 13], [193, 'd', 1, 3, 0, 43], [203, 'd', -1, 0, -1, 23]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[13, 'a', None, 0, 1, None], [23, 'a', 2, 2, 0, None], [33, 'a', 2, 3, 2, None], [43, 'a', 3, 4, None, None], [53, 'b', -2, 2, 1, None], [63, 'b', 0, 8, -1, None], [73, None, None, 2, 1, None], [83, None, 0, 5, None, None], [93, 'z', 3, 2, 0, None], [103, 'z', 3, 2, 1, None], [113, 'A', 2, 1, 1, None], [123, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[13, 'a', None, 8, None, None], [23, 'a', 0, 3, 0, 13], [33, 'a', 2, 1, 1, 23], [43, 'a', 2, 2, 2, 903], [53, 'a', -1, 4, -1, 33], [63, 'a', 3, 1, 1, 43], [73, 'b', -2, 2, 0, 13], [83, 'b', 2, 8, 1, 23], [93, 'b', None, 4, None, None], [103, None, None, 0, 1, 903], [113, None, 0, 5, 0, 13], [123, None, None, 7, None, 23], [133, 'c', None, 6, None, 33], [143, 'd', -1, 1, 0, 43], [153, 'A', 2, 2, 1, 53], [163, ' a ', 2, 8, 1, None], [173, '', None, 2, 0, None], [183, 'a', 2, 8, 1, 13], [193, 'd', 1, 3, 0, 43], [203, 'd', -1, 0, -1, 23]], [[13, 'a', None, 0, 1, None], [23, 'a', 2, 2, 0, None], [33, 'a', 2, 3, 2, None], [43, 'a', 3, 4, None, None], [53, 'b', -2, 2, 1, None], [63, 'b', 0, 8, -1, None], [73, None, None, 2, 1, None], [83, None, 0, 5, None, None], [93, 'z', 3, 2, 0, None], [103, 'z', 3, 2, 1, None], [113, 'A', 2, 1, 1, None], [123, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[13, None, None, 3, None, None], [23, None, None, 4, None, None], [33, 'x', None, 5, None, None]], [[13, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[13, 'a', 0, 9, 0, 13]], [[13, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[13, 'n', -2, 4, -1, 13], [23, 'n', None, 2, 0, 23], [33, 'n', -1, 0, 2, None]], [[13, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[13, 'p', 2, 1, 1, 13], [23, 'p', 2, 2, 1, 13], [33, 'p', 3, 0, 1, 13], [43, 'p', None, 1, 0, None]], [[13, 'p', 2, 1, 1, None], [23, 'p', 2, 1, 1, None]]), [['p', 4]])
elif N == 4:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[14, 'a', None, 8, None, None], [24, 'a', 0, 3, 0, 14], [34, 'a', 2, 1, 1, 24], [44, 'a', 2, 2, 2, 904], [54, 'a', -1, 4, -1, 34], [64, 'a', 3, 1, 1, 44], [74, 'b', -2, 2, 0, 14], [84, 'b', 2, 8, 1, 24], [94, 'b', None, 4, None, None], [104, None, None, 0, 1, 904], [114, None, 0, 5, 0, 14], [124, None, None, 7, None, 24], [134, 'c', None, 6, None, 34], [144, 'd', -1, 1, 0, 44], [154, 'A', 2, 2, 1, 54], [164, ' a ', 2, 8, 1, None], [174, '', None, 2, 0, None], [184, 'a', 2, 8, 1, 14], [194, 'd', 1, 3, 0, 44], [204, 'd', -1, 0, -1, 24]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[14, 'a', None, 0, 1, None], [24, 'a', 2, 2, 0, None], [34, 'a', 2, 3, 2, None], [44, 'a', 3, 4, None, None], [54, 'b', -2, 2, 1, None], [64, 'b', 0, 8, -1, None], [74, None, None, 2, 1, None], [84, None, 0, 5, None, None], [94, 'z', 3, 2, 0, None], [104, 'z', 3, 2, 1, None], [114, 'A', 2, 1, 1, None], [124, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[14, 'a', None, 8, None, None], [24, 'a', 0, 3, 0, 14], [34, 'a', 2, 1, 1, 24], [44, 'a', 2, 2, 2, 904], [54, 'a', -1, 4, -1, 34], [64, 'a', 3, 1, 1, 44], [74, 'b', -2, 2, 0, 14], [84, 'b', 2, 8, 1, 24], [94, 'b', None, 4, None, None], [104, None, None, 0, 1, 904], [114, None, 0, 5, 0, 14], [124, None, None, 7, None, 24], [134, 'c', None, 6, None, 34], [144, 'd', -1, 1, 0, 44], [154, 'A', 2, 2, 1, 54], [164, ' a ', 2, 8, 1, None], [174, '', None, 2, 0, None], [184, 'a', 2, 8, 1, 14], [194, 'd', 1, 3, 0, 44], [204, 'd', -1, 0, -1, 24]], [[14, 'a', None, 0, 1, None], [24, 'a', 2, 2, 0, None], [34, 'a', 2, 3, 2, None], [44, 'a', 3, 4, None, None], [54, 'b', -2, 2, 1, None], [64, 'b', 0, 8, -1, None], [74, None, None, 2, 1, None], [84, None, 0, 5, None, None], [94, 'z', 3, 2, 0, None], [104, 'z', 3, 2, 1, None], [114, 'A', 2, 1, 1, None], [124, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[14, None, None, 3, None, None], [24, None, None, 4, None, None], [34, 'x', None, 5, None, None]], [[14, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[14, 'a', 0, 9, 0, 14]], [[14, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[14, 'n', -2, 4, -1, 14], [24, 'n', None, 2, 0, 24], [34, 'n', -1, 0, 2, None]], [[14, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[14, 'p', 2, 1, 1, 14], [24, 'p', 2, 2, 1, 14], [34, 'p', 3, 0, 1, 14], [44, 'p', None, 1, 0, None]], [[14, 'p', 2, 1, 1, None], [24, 'p', 2, 1, 1, None]]), [['p', 4]])
elif N == 5:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[15, 'a', None, 8, None, None], [25, 'a', 0, 3, 0, 15], [35, 'a', 2, 1, 1, 25], [45, 'a', 2, 2, 2, 905], [55, 'a', -1, 4, -1, 35], [65, 'a', 3, 1, 1, 45], [75, 'b', -2, 2, 0, 15], [85, 'b', 2, 8, 1, 25], [95, 'b', None, 4, None, None], [105, None, None, 0, 1, 905], [115, None, 0, 5, 0, 15], [125, None, None, 7, None, 25], [135, 'c', None, 6, None, 35], [145, 'd', -1, 1, 0, 45], [155, 'A', 2, 2, 1, 55], [165, ' a ', 2, 8, 1, None], [175, '', None, 2, 0, None], [185, 'a', 2, 8, 1, 15], [195, 'd', 1, 3, 0, 45], [205, 'd', -1, 0, -1, 25]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[15, 'a', None, 0, 1, None], [25, 'a', 2, 2, 0, None], [35, 'a', 2, 3, 2, None], [45, 'a', 3, 4, None, None], [55, 'b', -2, 2, 1, None], [65, 'b', 0, 8, -1, None], [75, None, None, 2, 1, None], [85, None, 0, 5, None, None], [95, 'z', 3, 2, 0, None], [105, 'z', 3, 2, 1, None], [115, 'A', 2, 1, 1, None], [125, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[15, 'a', None, 8, None, None], [25, 'a', 0, 3, 0, 15], [35, 'a', 2, 1, 1, 25], [45, 'a', 2, 2, 2, 905], [55, 'a', -1, 4, -1, 35], [65, 'a', 3, 1, 1, 45], [75, 'b', -2, 2, 0, 15], [85, 'b', 2, 8, 1, 25], [95, 'b', None, 4, None, None], [105, None, None, 0, 1, 905], [115, None, 0, 5, 0, 15], [125, None, None, 7, None, 25], [135, 'c', None, 6, None, 35], [145, 'd', -1, 1, 0, 45], [155, 'A', 2, 2, 1, 55], [165, ' a ', 2, 8, 1, None], [175, '', None, 2, 0, None], [185, 'a', 2, 8, 1, 15], [195, 'd', 1, 3, 0, 45], [205, 'd', -1, 0, -1, 25]], [[15, 'a', None, 0, 1, None], [25, 'a', 2, 2, 0, None], [35, 'a', 2, 3, 2, None], [45, 'a', 3, 4, None, None], [55, 'b', -2, 2, 1, None], [65, 'b', 0, 8, -1, None], [75, None, None, 2, 1, None], [85, None, 0, 5, None, None], [95, 'z', 3, 2, 0, None], [105, 'z', 3, 2, 1, None], [115, 'A', 2, 1, 1, None], [125, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[15, None, None, 3, None, None], [25, None, None, 4, None, None], [35, 'x', None, 5, None, None]], [[15, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[15, 'a', 0, 9, 0, 15]], [[15, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[15, 'n', -2, 4, -1, 15], [25, 'n', None, 2, 0, 25], [35, 'n', -1, 0, 2, None]], [[15, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[15, 'p', 2, 1, 1, 15], [25, 'p', 2, 2, 1, 15], [35, 'p', 3, 0, 1, 15], [45, 'p', None, 1, 0, None]], [[15, 'p', 2, 1, 1, None], [25, 'p', 2, 1, 1, None]]), [['p', 4]])
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)

evaluation_group: xs-group-cardinality-filter

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import sqlite3
N = 1
observations = []
def solve(rows, refs):
    db = sqlite3.connect(':memory:')
    try:
        for name, records in [('a', rows), ('b', refs)]:
            db.execute('CREATE TABLE ' + name + ' (id INTEGER PRIMARY KEY, k TEXT, v INTEGER, w INTEGER, flag INTEGER, parent INTEGER)')
            db.executemany('INSERT INTO ' + name + ' VALUES (?,?,?,?,?,?)', records)
        return sorted([list(row) for row in db.execute('SELECT k,COUNT(*) FROM a GROUP BY k HAVING COUNT(*)>2')], key=repr)
    finally:
        db.close()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[11, 'a', None, 8, None, None], [21, 'a', 0, 3, 0, 11], [31, 'a', 2, 1, 1, 21], [41, 'a', 2, 2, 2, 901], [51, 'a', -1, 4, -1, 31], [61, 'a', 3, 1, 1, 41], [71, 'b', -2, 2, 0, 11], [81, 'b', 2, 8, 1, 21], [91, 'b', None, 4, None, None], [101, None, None, 0, 1, 901], [111, None, 0, 5, 0, 11], [121, None, None, 7, None, 21], [131, 'c', None, 6, None, 31], [141, 'd', -1, 1, 0, 41], [151, 'A', 2, 2, 1, 51], [161, ' a ', 2, 8, 1, None], [171, '', None, 2, 0, None], [181, 'a', 2, 8, 1, 11], [191, 'd', 1, 3, 0, 41], [201, 'd', -1, 0, -1, 21]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[11, 'a', None, 0, 1, None], [21, 'a', 2, 2, 0, None], [31, 'a', 2, 3, 2, None], [41, 'a', 3, 4, None, None], [51, 'b', -2, 2, 1, None], [61, 'b', 0, 8, -1, None], [71, None, None, 2, 1, None], [81, None, 0, 5, None, None], [91, 'z', 3, 2, 0, None], [101, 'z', 3, 2, 1, None], [111, 'A', 2, 1, 1, None], [121, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[11, 'a', None, 8, None, None], [21, 'a', 0, 3, 0, 11], [31, 'a', 2, 1, 1, 21], [41, 'a', 2, 2, 2, 901], [51, 'a', -1, 4, -1, 31], [61, 'a', 3, 1, 1, 41], [71, 'b', -2, 2, 0, 11], [81, 'b', 2, 8, 1, 21], [91, 'b', None, 4, None, None], [101, None, None, 0, 1, 901], [111, None, 0, 5, 0, 11], [121, None, None, 7, None, 21], [131, 'c', None, 6, None, 31], [141, 'd', -1, 1, 0, 41], [151, 'A', 2, 2, 1, 51], [161, ' a ', 2, 8, 1, None], [171, '', None, 2, 0, None], [181, 'a', 2, 8, 1, 11], [191, 'd', 1, 3, 0, 41], [201, 'd', -1, 0, -1, 21]], [[11, 'a', None, 0, 1, None], [21, 'a', 2, 2, 0, None], [31, 'a', 2, 3, 2, None], [41, 'a', 3, 4, None, None], [51, 'b', -2, 2, 1, None], [61, 'b', 0, 8, -1, None], [71, None, None, 2, 1, None], [81, None, 0, 5, None, None], [91, 'z', 3, 2, 0, None], [101, 'z', 3, 2, 1, None], [111, 'A', 2, 1, 1, None], [121, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[11, None, None, 3, None, None], [21, None, None, 4, None, None], [31, 'x', None, 5, None, None]], [[11, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[11, 'a', 0, 9, 0, 11]], [[11, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[11, 'n', -2, 4, -1, 11], [21, 'n', None, 2, 0, 21], [31, 'n', -1, 0, 2, None]], [[11, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[11, 'p', 2, 1, 1, 11], [21, 'p', 2, 2, 1, 11], [31, 'p', 3, 0, 1, 11], [41, 'p', None, 1, 0, None]], [[11, 'p', 2, 1, 1, None], [21, 'p', 2, 1, 1, None]]), [['p', 4]])
elif N == 2:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[12, 'a', None, 8, None, None], [22, 'a', 0, 3, 0, 12], [32, 'a', 2, 1, 1, 22], [42, 'a', 2, 2, 2, 902], [52, 'a', -1, 4, -1, 32], [62, 'a', 3, 1, 1, 42], [72, 'b', -2, 2, 0, 12], [82, 'b', 2, 8, 1, 22], [92, 'b', None, 4, None, None], [102, None, None, 0, 1, 902], [112, None, 0, 5, 0, 12], [122, None, None, 7, None, 22], [132, 'c', None, 6, None, 32], [142, 'd', -1, 1, 0, 42], [152, 'A', 2, 2, 1, 52], [162, ' a ', 2, 8, 1, None], [172, '', None, 2, 0, None], [182, 'a', 2, 8, 1, 12], [192, 'd', 1, 3, 0, 42], [202, 'd', -1, 0, -1, 22]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[12, 'a', None, 0, 1, None], [22, 'a', 2, 2, 0, None], [32, 'a', 2, 3, 2, None], [42, 'a', 3, 4, None, None], [52, 'b', -2, 2, 1, None], [62, 'b', 0, 8, -1, None], [72, None, None, 2, 1, None], [82, None, 0, 5, None, None], [92, 'z', 3, 2, 0, None], [102, 'z', 3, 2, 1, None], [112, 'A', 2, 1, 1, None], [122, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[12, 'a', None, 8, None, None], [22, 'a', 0, 3, 0, 12], [32, 'a', 2, 1, 1, 22], [42, 'a', 2, 2, 2, 902], [52, 'a', -1, 4, -1, 32], [62, 'a', 3, 1, 1, 42], [72, 'b', -2, 2, 0, 12], [82, 'b', 2, 8, 1, 22], [92, 'b', None, 4, None, None], [102, None, None, 0, 1, 902], [112, None, 0, 5, 0, 12], [122, None, None, 7, None, 22], [132, 'c', None, 6, None, 32], [142, 'd', -1, 1, 0, 42], [152, 'A', 2, 2, 1, 52], [162, ' a ', 2, 8, 1, None], [172, '', None, 2, 0, None], [182, 'a', 2, 8, 1, 12], [192, 'd', 1, 3, 0, 42], [202, 'd', -1, 0, -1, 22]], [[12, 'a', None, 0, 1, None], [22, 'a', 2, 2, 0, None], [32, 'a', 2, 3, 2, None], [42, 'a', 3, 4, None, None], [52, 'b', -2, 2, 1, None], [62, 'b', 0, 8, -1, None], [72, None, None, 2, 1, None], [82, None, 0, 5, None, None], [92, 'z', 3, 2, 0, None], [102, 'z', 3, 2, 1, None], [112, 'A', 2, 1, 1, None], [122, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[12, None, None, 3, None, None], [22, None, None, 4, None, None], [32, 'x', None, 5, None, None]], [[12, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[12, 'a', 0, 9, 0, 12]], [[12, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[12, 'n', -2, 4, -1, 12], [22, 'n', None, 2, 0, 22], [32, 'n', -1, 0, 2, None]], [[12, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[12, 'p', 2, 1, 1, 12], [22, 'p', 2, 2, 1, 12], [32, 'p', 3, 0, 1, 12], [42, 'p', None, 1, 0, None]], [[12, 'p', 2, 1, 1, None], [22, 'p', 2, 1, 1, None]]), [['p', 4]])
elif N == 3:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[13, 'a', None, 8, None, None], [23, 'a', 0, 3, 0, 13], [33, 'a', 2, 1, 1, 23], [43, 'a', 2, 2, 2, 903], [53, 'a', -1, 4, -1, 33], [63, 'a', 3, 1, 1, 43], [73, 'b', -2, 2, 0, 13], [83, 'b', 2, 8, 1, 23], [93, 'b', None, 4, None, None], [103, None, None, 0, 1, 903], [113, None, 0, 5, 0, 13], [123, None, None, 7, None, 23], [133, 'c', None, 6, None, 33], [143, 'd', -1, 1, 0, 43], [153, 'A', 2, 2, 1, 53], [163, ' a ', 2, 8, 1, None], [173, '', None, 2, 0, None], [183, 'a', 2, 8, 1, 13], [193, 'd', 1, 3, 0, 43], [203, 'd', -1, 0, -1, 23]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[13, 'a', None, 0, 1, None], [23, 'a', 2, 2, 0, None], [33, 'a', 2, 3, 2, None], [43, 'a', 3, 4, None, None], [53, 'b', -2, 2, 1, None], [63, 'b', 0, 8, -1, None], [73, None, None, 2, 1, None], [83, None, 0, 5, None, None], [93, 'z', 3, 2, 0, None], [103, 'z', 3, 2, 1, None], [113, 'A', 2, 1, 1, None], [123, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[13, 'a', None, 8, None, None], [23, 'a', 0, 3, 0, 13], [33, 'a', 2, 1, 1, 23], [43, 'a', 2, 2, 2, 903], [53, 'a', -1, 4, -1, 33], [63, 'a', 3, 1, 1, 43], [73, 'b', -2, 2, 0, 13], [83, 'b', 2, 8, 1, 23], [93, 'b', None, 4, None, None], [103, None, None, 0, 1, 903], [113, None, 0, 5, 0, 13], [123, None, None, 7, None, 23], [133, 'c', None, 6, None, 33], [143, 'd', -1, 1, 0, 43], [153, 'A', 2, 2, 1, 53], [163, ' a ', 2, 8, 1, None], [173, '', None, 2, 0, None], [183, 'a', 2, 8, 1, 13], [193, 'd', 1, 3, 0, 43], [203, 'd', -1, 0, -1, 23]], [[13, 'a', None, 0, 1, None], [23, 'a', 2, 2, 0, None], [33, 'a', 2, 3, 2, None], [43, 'a', 3, 4, None, None], [53, 'b', -2, 2, 1, None], [63, 'b', 0, 8, -1, None], [73, None, None, 2, 1, None], [83, None, 0, 5, None, None], [93, 'z', 3, 2, 0, None], [103, 'z', 3, 2, 1, None], [113, 'A', 2, 1, 1, None], [123, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[13, None, None, 3, None, None], [23, None, None, 4, None, None], [33, 'x', None, 5, None, None]], [[13, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[13, 'a', 0, 9, 0, 13]], [[13, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[13, 'n', -2, 4, -1, 13], [23, 'n', None, 2, 0, 23], [33, 'n', -1, 0, 2, None]], [[13, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[13, 'p', 2, 1, 1, 13], [23, 'p', 2, 2, 1, 13], [33, 'p', 3, 0, 1, 13], [43, 'p', None, 1, 0, None]], [[13, 'p', 2, 1, 1, None], [23, 'p', 2, 1, 1, None]]), [['p', 4]])
elif N == 4:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[14, 'a', None, 8, None, None], [24, 'a', 0, 3, 0, 14], [34, 'a', 2, 1, 1, 24], [44, 'a', 2, 2, 2, 904], [54, 'a', -1, 4, -1, 34], [64, 'a', 3, 1, 1, 44], [74, 'b', -2, 2, 0, 14], [84, 'b', 2, 8, 1, 24], [94, 'b', None, 4, None, None], [104, None, None, 0, 1, 904], [114, None, 0, 5, 0, 14], [124, None, None, 7, None, 24], [134, 'c', None, 6, None, 34], [144, 'd', -1, 1, 0, 44], [154, 'A', 2, 2, 1, 54], [164, ' a ', 2, 8, 1, None], [174, '', None, 2, 0, None], [184, 'a', 2, 8, 1, 14], [194, 'd', 1, 3, 0, 44], [204, 'd', -1, 0, -1, 24]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[14, 'a', None, 0, 1, None], [24, 'a', 2, 2, 0, None], [34, 'a', 2, 3, 2, None], [44, 'a', 3, 4, None, None], [54, 'b', -2, 2, 1, None], [64, 'b', 0, 8, -1, None], [74, None, None, 2, 1, None], [84, None, 0, 5, None, None], [94, 'z', 3, 2, 0, None], [104, 'z', 3, 2, 1, None], [114, 'A', 2, 1, 1, None], [124, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[14, 'a', None, 8, None, None], [24, 'a', 0, 3, 0, 14], [34, 'a', 2, 1, 1, 24], [44, 'a', 2, 2, 2, 904], [54, 'a', -1, 4, -1, 34], [64, 'a', 3, 1, 1, 44], [74, 'b', -2, 2, 0, 14], [84, 'b', 2, 8, 1, 24], [94, 'b', None, 4, None, None], [104, None, None, 0, 1, 904], [114, None, 0, 5, 0, 14], [124, None, None, 7, None, 24], [134, 'c', None, 6, None, 34], [144, 'd', -1, 1, 0, 44], [154, 'A', 2, 2, 1, 54], [164, ' a ', 2, 8, 1, None], [174, '', None, 2, 0, None], [184, 'a', 2, 8, 1, 14], [194, 'd', 1, 3, 0, 44], [204, 'd', -1, 0, -1, 24]], [[14, 'a', None, 0, 1, None], [24, 'a', 2, 2, 0, None], [34, 'a', 2, 3, 2, None], [44, 'a', 3, 4, None, None], [54, 'b', -2, 2, 1, None], [64, 'b', 0, 8, -1, None], [74, None, None, 2, 1, None], [84, None, 0, 5, None, None], [94, 'z', 3, 2, 0, None], [104, 'z', 3, 2, 1, None], [114, 'A', 2, 1, 1, None], [124, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[14, None, None, 3, None, None], [24, None, None, 4, None, None], [34, 'x', None, 5, None, None]], [[14, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[14, 'a', 0, 9, 0, 14]], [[14, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[14, 'n', -2, 4, -1, 14], [24, 'n', None, 2, 0, 24], [34, 'n', -1, 0, 2, None]], [[14, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[14, 'p', 2, 1, 1, 14], [24, 'p', 2, 2, 1, 14], [34, 'p', 3, 0, 1, 14], [44, 'p', None, 1, 0, None]], [[14, 'p', 2, 1, 1, None], [24, 'p', 2, 1, 1, None]]), [['p', 4]])
elif N == 5:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[15, 'a', None, 8, None, None], [25, 'a', 0, 3, 0, 15], [35, 'a', 2, 1, 1, 25], [45, 'a', 2, 2, 2, 905], [55, 'a', -1, 4, -1, 35], [65, 'a', 3, 1, 1, 45], [75, 'b', -2, 2, 0, 15], [85, 'b', 2, 8, 1, 25], [95, 'b', None, 4, None, None], [105, None, None, 0, 1, 905], [115, None, 0, 5, 0, 15], [125, None, None, 7, None, 25], [135, 'c', None, 6, None, 35], [145, 'd', -1, 1, 0, 45], [155, 'A', 2, 2, 1, 55], [165, ' a ', 2, 8, 1, None], [175, '', None, 2, 0, None], [185, 'a', 2, 8, 1, 15], [195, 'd', 1, 3, 0, 45], [205, 'd', -1, 0, -1, 25]], []), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('references without candidates', solve([], [[15, 'a', None, 0, 1, None], [25, 'a', 2, 2, 0, None], [35, 'a', 2, 3, 2, None], [45, 'a', 3, 4, None, None], [55, 'b', -2, 2, 1, None], [65, 'b', 0, 8, -1, None], [75, None, None, 2, 1, None], [85, None, 0, 5, None, None], [95, 'z', 3, 2, 0, None], [105, 'z', 3, 2, 1, None], [115, 'A', 2, 1, 1, None], [125, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[15, 'a', None, 8, None, None], [25, 'a', 0, 3, 0, 15], [35, 'a', 2, 1, 1, 25], [45, 'a', 2, 2, 2, 905], [55, 'a', -1, 4, -1, 35], [65, 'a', 3, 1, 1, 45], [75, 'b', -2, 2, 0, 15], [85, 'b', 2, 8, 1, 25], [95, 'b', None, 4, None, None], [105, None, None, 0, 1, 905], [115, None, 0, 5, 0, 15], [125, None, None, 7, None, 25], [135, 'c', None, 6, None, 35], [145, 'd', -1, 1, 0, 45], [155, 'A', 2, 2, 1, 55], [165, ' a ', 2, 8, 1, None], [175, '', None, 2, 0, None], [185, 'a', 2, 8, 1, 15], [195, 'd', 1, 3, 0, 45], [205, 'd', -1, 0, -1, 25]], [[15, 'a', None, 0, 1, None], [25, 'a', 2, 2, 0, None], [35, 'a', 2, 3, 2, None], [45, 'a', 3, 4, None, None], [55, 'b', -2, 2, 1, None], [65, 'b', 0, 8, -1, None], [75, None, None, 2, 1, None], [85, None, 0, 5, None, None], [95, 'z', 3, 2, 0, None], [105, 'z', 3, 2, 1, None], [115, 'A', 2, 1, 1, None], [125, 'c', None, 2, 0, None]]), [['a', 7], ['b', 3], ['d', 3], [None, 3]])
    check('unknown-only group with duplicate nullable index keys', solve([[15, None, None, 3, None, None], [25, None, None, 4, None, None], [35, 'x', None, 5, None, None]], [[15, None, None, 2, None, None]]), [[None, 2]])
    check('single known zero and matching reference', solve([[15, 'a', 0, 9, 0, 15]], [[15, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[15, 'n', -2, 4, -1, 15], [25, 'n', None, 2, 0, 25], [35, 'n', -1, 0, 2, None]], [[15, 'n', -2, 1, 1, None]]), [['n', 3]])
    check('positive-only group with repeated measurements and NULL', solve([[15, 'p', 2, 1, 1, 15], [25, 'p', 2, 2, 1, 15], [35, 'p', 3, 0, 1, 15], [45, 'p', None, 1, 0, None]], [[15, 'p', 2, 1, 1, None], [25, 'p', 2, 1, 1, None]]), [['p', 4]])
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 query violates its result contract: keeps small rather than large groups.

Return key and row count for groups with at least two row occurrences. Inputs are finite relations a=rows and b=refs with columns (id,k,v,w,flag,parent). IDs are unique within each relation, None is SQL NULL, keys are ASCII strings or None, and other values are integers or None. Return an unordered result bag as lists sorted by repr, preserving multiplicity unless explicitly distinct.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import sqlite3
N = 1
observations = []
def solve(rows, refs):
    db = sqlite3.connect(':memory:')
    try:
        for name, records in [('a', rows), ('b', refs)]:
            db.execute('CREATE TABLE ' + name + ' (id INTEGER PRIMARY KEY, k TEXT, v INTEGER, w INTEGER, flag INTEGER, parent INTEGER)')
            db.executemany('INSERT INTO ' + name + ' VALUES (?,?,?,?,?,?)', records)
        return sorted([list(row) for row in db.execute('SELECT k,SUM(v) FROM a GROUP BY k HAVING SUM(v)>=0')], key=repr)
    finally:
        db.close()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[11, 'a', None, 8, None, None], [21, 'a', 0, 3, 0, 11], [31, 'a', 2, 1, 1, 21], [41, 'a', 2, 2, 2, 901], [51, 'a', -1, 4, -1, 31], [61, 'a', 3, 1, 1, 41], [71, 'b', -2, 2, 0, 11], [81, 'b', 2, 8, 1, 21], [91, 'b', None, 4, None, None], [101, None, None, 0, 1, 901], [111, None, 0, 5, 0, 11], [121, None, None, 7, None, 21], [131, 'c', None, 6, None, 31], [141, 'd', -1, 1, 0, 41], [151, 'A', 2, 2, 1, 51], [161, ' a ', 2, 8, 1, None], [171, '', None, 2, 0, None], [181, 'a', 2, 8, 1, 11], [191, 'd', 1, 3, 0, 41], [201, 'd', -1, 0, -1, 21]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[11, 'a', None, 0, 1, None], [21, 'a', 2, 2, 0, None], [31, 'a', 2, 3, 2, None], [41, 'a', 3, 4, None, None], [51, 'b', -2, 2, 1, None], [61, 'b', 0, 8, -1, None], [71, None, None, 2, 1, None], [81, None, 0, 5, None, None], [91, 'z', 3, 2, 0, None], [101, 'z', 3, 2, 1, None], [111, 'A', 2, 1, 1, None], [121, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[11, 'a', None, 8, None, None], [21, 'a', 0, 3, 0, 11], [31, 'a', 2, 1, 1, 21], [41, 'a', 2, 2, 2, 901], [51, 'a', -1, 4, -1, 31], [61, 'a', 3, 1, 1, 41], [71, 'b', -2, 2, 0, 11], [81, 'b', 2, 8, 1, 21], [91, 'b', None, 4, None, None], [101, None, None, 0, 1, 901], [111, None, 0, 5, 0, 11], [121, None, None, 7, None, 21], [131, 'c', None, 6, None, 31], [141, 'd', -1, 1, 0, 41], [151, 'A', 2, 2, 1, 51], [161, ' a ', 2, 8, 1, None], [171, '', None, 2, 0, None], [181, 'a', 2, 8, 1, 11], [191, 'd', 1, 3, 0, 41], [201, 'd', -1, 0, -1, 21]], [[11, 'a', None, 0, 1, None], [21, 'a', 2, 2, 0, None], [31, 'a', 2, 3, 2, None], [41, 'a', 3, 4, None, None], [51, 'b', -2, 2, 1, None], [61, 'b', 0, 8, -1, None], [71, None, None, 2, 1, None], [81, None, 0, 5, None, None], [91, 'z', 3, 2, 0, None], [101, 'z', 3, 2, 1, None], [111, 'A', 2, 1, 1, None], [121, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[11, None, None, 3, None, None], [21, None, None, 4, None, None], [31, 'x', None, 5, None, None]], [[11, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[11, 'a', 0, 9, 0, 11]], [[11, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[11, 'n', -2, 4, -1, 11], [21, 'n', None, 2, 0, 21], [31, 'n', -1, 0, 2, None]], [[11, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[11, 'p', 2, 1, 1, 11], [21, 'p', 2, 2, 1, 11], [31, 'p', 3, 0, 1, 11], [41, 'p', None, 1, 0, None]], [[11, 'p', 2, 1, 1, None], [21, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[11, None, -2, 1, 0, 11], [21, 'b', None, 2, 1, 191], [31, None, 2, 7, 2, 191], [41, 'A', 3, 3, -1, 31], [51, ' a ', None, 7, 2, 11], [61, '', 1, 7, 2, None], [71, None, 2, 0, 2, 21], [81, 'A', None, 3, -1, 21], [91, 'a', 2, 7, 2, 191], [101, 'b', 3, 2, 0, None], [111, 'c', None, 3, 2, None], [121, 'A', 5, 2, None, None], [131, ' a ', 0, 1, 1, 21], [141, 'b', 2, 7, 2, None]], [[11, ' a ', -1, 1, 0, 31], [21, 'a', 5, 0, 0, None], [31, 'c', -3, 0, 1, 191], [41, ' a ', 2, 7, 1, None], [51, 'b', None, 7, -1, 11], [61, '', 2, 0, None, 31], [71, 'b', -3, 3, 1, None], [81, 'a', 0, 1, None, 191], [91, 'a', 5, 0, None, 11], [101, '', None, 3, 0, 191]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
elif N == 2:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[12, 'a', None, 8, None, None], [22, 'a', 0, 3, 0, 12], [32, 'a', 2, 1, 1, 22], [42, 'a', 2, 2, 2, 902], [52, 'a', -1, 4, -1, 32], [62, 'a', 3, 1, 1, 42], [72, 'b', -2, 2, 0, 12], [82, 'b', 2, 8, 1, 22], [92, 'b', None, 4, None, None], [102, None, None, 0, 1, 902], [112, None, 0, 5, 0, 12], [122, None, None, 7, None, 22], [132, 'c', None, 6, None, 32], [142, 'd', -1, 1, 0, 42], [152, 'A', 2, 2, 1, 52], [162, ' a ', 2, 8, 1, None], [172, '', None, 2, 0, None], [182, 'a', 2, 8, 1, 12], [192, 'd', 1, 3, 0, 42], [202, 'd', -1, 0, -1, 22]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[12, 'a', None, 0, 1, None], [22, 'a', 2, 2, 0, None], [32, 'a', 2, 3, 2, None], [42, 'a', 3, 4, None, None], [52, 'b', -2, 2, 1, None], [62, 'b', 0, 8, -1, None], [72, None, None, 2, 1, None], [82, None, 0, 5, None, None], [92, 'z', 3, 2, 0, None], [102, 'z', 3, 2, 1, None], [112, 'A', 2, 1, 1, None], [122, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[12, 'a', None, 8, None, None], [22, 'a', 0, 3, 0, 12], [32, 'a', 2, 1, 1, 22], [42, 'a', 2, 2, 2, 902], [52, 'a', -1, 4, -1, 32], [62, 'a', 3, 1, 1, 42], [72, 'b', -2, 2, 0, 12], [82, 'b', 2, 8, 1, 22], [92, 'b', None, 4, None, None], [102, None, None, 0, 1, 902], [112, None, 0, 5, 0, 12], [122, None, None, 7, None, 22], [132, 'c', None, 6, None, 32], [142, 'd', -1, 1, 0, 42], [152, 'A', 2, 2, 1, 52], [162, ' a ', 2, 8, 1, None], [172, '', None, 2, 0, None], [182, 'a', 2, 8, 1, 12], [192, 'd', 1, 3, 0, 42], [202, 'd', -1, 0, -1, 22]], [[12, 'a', None, 0, 1, None], [22, 'a', 2, 2, 0, None], [32, 'a', 2, 3, 2, None], [42, 'a', 3, 4, None, None], [52, 'b', -2, 2, 1, None], [62, 'b', 0, 8, -1, None], [72, None, None, 2, 1, None], [82, None, 0, 5, None, None], [92, 'z', 3, 2, 0, None], [102, 'z', 3, 2, 1, None], [112, 'A', 2, 1, 1, None], [122, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[12, None, None, 3, None, None], [22, None, None, 4, None, None], [32, 'x', None, 5, None, None]], [[12, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[12, 'a', 0, 9, 0, 12]], [[12, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[12, 'n', -2, 4, -1, 12], [22, 'n', None, 2, 0, 22], [32, 'n', -1, 0, 2, None]], [[12, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[12, 'p', 2, 1, 1, 12], [22, 'p', 2, 2, 1, 12], [32, 'p', 3, 0, 1, 12], [42, 'p', None, 1, 0, None]], [[12, 'p', 2, 1, 1, None], [22, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[12, None, -2, 1, 0, 12], [22, 'b', None, 2, 1, 192], [32, None, 2, 7, 2, 192], [42, 'A', 3, 3, -1, 32], [52, ' a ', None, 7, 2, 12], [62, '', 1, 7, 2, None], [72, None, 2, 0, 2, 22], [82, 'A', None, 3, -1, 22], [92, 'a', 2, 7, 2, 192], [102, 'b', 3, 2, 0, None], [112, 'c', None, 3, 2, None], [122, 'A', 5, 2, None, None], [132, ' a ', 0, 1, 1, 22], [142, 'b', 2, 7, 2, None]], [[12, ' a ', -1, 1, 0, 32], [22, 'a', 5, 0, 0, None], [32, 'c', -3, 0, 1, 192], [42, ' a ', 2, 7, 1, None], [52, 'b', None, 7, -1, 12], [62, '', 2, 0, None, 32], [72, 'b', -3, 3, 1, None], [82, 'a', 0, 1, None, 192], [92, 'a', 5, 0, None, 12], [102, '', None, 3, 0, 192]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
elif N == 3:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[13, 'a', None, 8, None, None], [23, 'a', 0, 3, 0, 13], [33, 'a', 2, 1, 1, 23], [43, 'a', 2, 2, 2, 903], [53, 'a', -1, 4, -1, 33], [63, 'a', 3, 1, 1, 43], [73, 'b', -2, 2, 0, 13], [83, 'b', 2, 8, 1, 23], [93, 'b', None, 4, None, None], [103, None, None, 0, 1, 903], [113, None, 0, 5, 0, 13], [123, None, None, 7, None, 23], [133, 'c', None, 6, None, 33], [143, 'd', -1, 1, 0, 43], [153, 'A', 2, 2, 1, 53], [163, ' a ', 2, 8, 1, None], [173, '', None, 2, 0, None], [183, 'a', 2, 8, 1, 13], [193, 'd', 1, 3, 0, 43], [203, 'd', -1, 0, -1, 23]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[13, 'a', None, 0, 1, None], [23, 'a', 2, 2, 0, None], [33, 'a', 2, 3, 2, None], [43, 'a', 3, 4, None, None], [53, 'b', -2, 2, 1, None], [63, 'b', 0, 8, -1, None], [73, None, None, 2, 1, None], [83, None, 0, 5, None, None], [93, 'z', 3, 2, 0, None], [103, 'z', 3, 2, 1, None], [113, 'A', 2, 1, 1, None], [123, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[13, 'a', None, 8, None, None], [23, 'a', 0, 3, 0, 13], [33, 'a', 2, 1, 1, 23], [43, 'a', 2, 2, 2, 903], [53, 'a', -1, 4, -1, 33], [63, 'a', 3, 1, 1, 43], [73, 'b', -2, 2, 0, 13], [83, 'b', 2, 8, 1, 23], [93, 'b', None, 4, None, None], [103, None, None, 0, 1, 903], [113, None, 0, 5, 0, 13], [123, None, None, 7, None, 23], [133, 'c', None, 6, None, 33], [143, 'd', -1, 1, 0, 43], [153, 'A', 2, 2, 1, 53], [163, ' a ', 2, 8, 1, None], [173, '', None, 2, 0, None], [183, 'a', 2, 8, 1, 13], [193, 'd', 1, 3, 0, 43], [203, 'd', -1, 0, -1, 23]], [[13, 'a', None, 0, 1, None], [23, 'a', 2, 2, 0, None], [33, 'a', 2, 3, 2, None], [43, 'a', 3, 4, None, None], [53, 'b', -2, 2, 1, None], [63, 'b', 0, 8, -1, None], [73, None, None, 2, 1, None], [83, None, 0, 5, None, None], [93, 'z', 3, 2, 0, None], [103, 'z', 3, 2, 1, None], [113, 'A', 2, 1, 1, None], [123, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[13, None, None, 3, None, None], [23, None, None, 4, None, None], [33, 'x', None, 5, None, None]], [[13, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[13, 'a', 0, 9, 0, 13]], [[13, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[13, 'n', -2, 4, -1, 13], [23, 'n', None, 2, 0, 23], [33, 'n', -1, 0, 2, None]], [[13, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[13, 'p', 2, 1, 1, 13], [23, 'p', 2, 2, 1, 13], [33, 'p', 3, 0, 1, 13], [43, 'p', None, 1, 0, None]], [[13, 'p', 2, 1, 1, None], [23, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[13, None, -2, 1, 0, 13], [23, 'b', None, 2, 1, 193], [33, None, 2, 7, 2, 193], [43, 'A', 3, 3, -1, 33], [53, ' a ', None, 7, 2, 13], [63, '', 1, 7, 2, None], [73, None, 2, 0, 2, 23], [83, 'A', None, 3, -1, 23], [93, 'a', 2, 7, 2, 193], [103, 'b', 3, 2, 0, None], [113, 'c', None, 3, 2, None], [123, 'A', 5, 2, None, None], [133, ' a ', 0, 1, 1, 23], [143, 'b', 2, 7, 2, None]], [[13, ' a ', -1, 1, 0, 33], [23, 'a', 5, 0, 0, None], [33, 'c', -3, 0, 1, 193], [43, ' a ', 2, 7, 1, None], [53, 'b', None, 7, -1, 13], [63, '', 2, 0, None, 33], [73, 'b', -3, 3, 1, None], [83, 'a', 0, 1, None, 193], [93, 'a', 5, 0, None, 13], [103, '', None, 3, 0, 193]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
elif N == 4:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[14, 'a', None, 8, None, None], [24, 'a', 0, 3, 0, 14], [34, 'a', 2, 1, 1, 24], [44, 'a', 2, 2, 2, 904], [54, 'a', -1, 4, -1, 34], [64, 'a', 3, 1, 1, 44], [74, 'b', -2, 2, 0, 14], [84, 'b', 2, 8, 1, 24], [94, 'b', None, 4, None, None], [104, None, None, 0, 1, 904], [114, None, 0, 5, 0, 14], [124, None, None, 7, None, 24], [134, 'c', None, 6, None, 34], [144, 'd', -1, 1, 0, 44], [154, 'A', 2, 2, 1, 54], [164, ' a ', 2, 8, 1, None], [174, '', None, 2, 0, None], [184, 'a', 2, 8, 1, 14], [194, 'd', 1, 3, 0, 44], [204, 'd', -1, 0, -1, 24]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[14, 'a', None, 0, 1, None], [24, 'a', 2, 2, 0, None], [34, 'a', 2, 3, 2, None], [44, 'a', 3, 4, None, None], [54, 'b', -2, 2, 1, None], [64, 'b', 0, 8, -1, None], [74, None, None, 2, 1, None], [84, None, 0, 5, None, None], [94, 'z', 3, 2, 0, None], [104, 'z', 3, 2, 1, None], [114, 'A', 2, 1, 1, None], [124, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[14, 'a', None, 8, None, None], [24, 'a', 0, 3, 0, 14], [34, 'a', 2, 1, 1, 24], [44, 'a', 2, 2, 2, 904], [54, 'a', -1, 4, -1, 34], [64, 'a', 3, 1, 1, 44], [74, 'b', -2, 2, 0, 14], [84, 'b', 2, 8, 1, 24], [94, 'b', None, 4, None, None], [104, None, None, 0, 1, 904], [114, None, 0, 5, 0, 14], [124, None, None, 7, None, 24], [134, 'c', None, 6, None, 34], [144, 'd', -1, 1, 0, 44], [154, 'A', 2, 2, 1, 54], [164, ' a ', 2, 8, 1, None], [174, '', None, 2, 0, None], [184, 'a', 2, 8, 1, 14], [194, 'd', 1, 3, 0, 44], [204, 'd', -1, 0, -1, 24]], [[14, 'a', None, 0, 1, None], [24, 'a', 2, 2, 0, None], [34, 'a', 2, 3, 2, None], [44, 'a', 3, 4, None, None], [54, 'b', -2, 2, 1, None], [64, 'b', 0, 8, -1, None], [74, None, None, 2, 1, None], [84, None, 0, 5, None, None], [94, 'z', 3, 2, 0, None], [104, 'z', 3, 2, 1, None], [114, 'A', 2, 1, 1, None], [124, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[14, None, None, 3, None, None], [24, None, None, 4, None, None], [34, 'x', None, 5, None, None]], [[14, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[14, 'a', 0, 9, 0, 14]], [[14, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[14, 'n', -2, 4, -1, 14], [24, 'n', None, 2, 0, 24], [34, 'n', -1, 0, 2, None]], [[14, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[14, 'p', 2, 1, 1, 14], [24, 'p', 2, 2, 1, 14], [34, 'p', 3, 0, 1, 14], [44, 'p', None, 1, 0, None]], [[14, 'p', 2, 1, 1, None], [24, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[14, None, -2, 1, 0, 14], [24, 'b', None, 2, 1, 194], [34, None, 2, 7, 2, 194], [44, 'A', 3, 3, -1, 34], [54, ' a ', None, 7, 2, 14], [64, '', 1, 7, 2, None], [74, None, 2, 0, 2, 24], [84, 'A', None, 3, -1, 24], [94, 'a', 2, 7, 2, 194], [104, 'b', 3, 2, 0, None], [114, 'c', None, 3, 2, None], [124, 'A', 5, 2, None, None], [134, ' a ', 0, 1, 1, 24], [144, 'b', 2, 7, 2, None]], [[14, ' a ', -1, 1, 0, 34], [24, 'a', 5, 0, 0, None], [34, 'c', -3, 0, 1, 194], [44, ' a ', 2, 7, 1, None], [54, 'b', None, 7, -1, 14], [64, '', 2, 0, None, 34], [74, 'b', -3, 3, 1, None], [84, 'a', 0, 1, None, 194], [94, 'a', 5, 0, None, 14], [104, '', None, 3, 0, 194]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
elif N == 5:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[15, 'a', None, 8, None, None], [25, 'a', 0, 3, 0, 15], [35, 'a', 2, 1, 1, 25], [45, 'a', 2, 2, 2, 905], [55, 'a', -1, 4, -1, 35], [65, 'a', 3, 1, 1, 45], [75, 'b', -2, 2, 0, 15], [85, 'b', 2, 8, 1, 25], [95, 'b', None, 4, None, None], [105, None, None, 0, 1, 905], [115, None, 0, 5, 0, 15], [125, None, None, 7, None, 25], [135, 'c', None, 6, None, 35], [145, 'd', -1, 1, 0, 45], [155, 'A', 2, 2, 1, 55], [165, ' a ', 2, 8, 1, None], [175, '', None, 2, 0, None], [185, 'a', 2, 8, 1, 15], [195, 'd', 1, 3, 0, 45], [205, 'd', -1, 0, -1, 25]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[15, 'a', None, 0, 1, None], [25, 'a', 2, 2, 0, None], [35, 'a', 2, 3, 2, None], [45, 'a', 3, 4, None, None], [55, 'b', -2, 2, 1, None], [65, 'b', 0, 8, -1, None], [75, None, None, 2, 1, None], [85, None, 0, 5, None, None], [95, 'z', 3, 2, 0, None], [105, 'z', 3, 2, 1, None], [115, 'A', 2, 1, 1, None], [125, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[15, 'a', None, 8, None, None], [25, 'a', 0, 3, 0, 15], [35, 'a', 2, 1, 1, 25], [45, 'a', 2, 2, 2, 905], [55, 'a', -1, 4, -1, 35], [65, 'a', 3, 1, 1, 45], [75, 'b', -2, 2, 0, 15], [85, 'b', 2, 8, 1, 25], [95, 'b', None, 4, None, None], [105, None, None, 0, 1, 905], [115, None, 0, 5, 0, 15], [125, None, None, 7, None, 25], [135, 'c', None, 6, None, 35], [145, 'd', -1, 1, 0, 45], [155, 'A', 2, 2, 1, 55], [165, ' a ', 2, 8, 1, None], [175, '', None, 2, 0, None], [185, 'a', 2, 8, 1, 15], [195, 'd', 1, 3, 0, 45], [205, 'd', -1, 0, -1, 25]], [[15, 'a', None, 0, 1, None], [25, 'a', 2, 2, 0, None], [35, 'a', 2, 3, 2, None], [45, 'a', 3, 4, None, None], [55, 'b', -2, 2, 1, None], [65, 'b', 0, 8, -1, None], [75, None, None, 2, 1, None], [85, None, 0, 5, None, None], [95, 'z', 3, 2, 0, None], [105, 'z', 3, 2, 1, None], [115, 'A', 2, 1, 1, None], [125, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[15, None, None, 3, None, None], [25, None, None, 4, None, None], [35, 'x', None, 5, None, None]], [[15, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[15, 'a', 0, 9, 0, 15]], [[15, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[15, 'n', -2, 4, -1, 15], [25, 'n', None, 2, 0, 25], [35, 'n', -1, 0, 2, None]], [[15, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[15, 'p', 2, 1, 1, 15], [25, 'p', 2, 2, 1, 15], [35, 'p', 3, 0, 1, 15], [45, 'p', None, 1, 0, None]], [[15, 'p', 2, 1, 1, None], [25, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[15, None, -2, 1, 0, 15], [25, 'b', None, 2, 1, 195], [35, None, 2, 7, 2, 195], [45, 'A', 3, 3, -1, 35], [55, ' a ', None, 7, 2, 15], [65, '', 1, 7, 2, None], [75, None, 2, 0, 2, 25], [85, 'A', None, 3, -1, 25], [95, 'a', 2, 7, 2, 195], [105, 'b', 3, 2, 0, None], [115, 'c', None, 3, 2, None], [125, 'A', 5, 2, None, None], [135, ' a ', 0, 1, 1, 25], [145, 'b', 2, 7, 2, None]], [[15, ' a ', -1, 1, 0, 35], [25, 'a', 5, 0, 0, None], [35, 'c', -3, 0, 1, 195], [45, ' a ', 2, 7, 1, None], [55, 'b', None, 7, -1, 15], [65, '', 2, 0, None, 35], [75, 'b', -3, 3, 1, None], [85, 'a', 0, 1, None, 195], [95, 'a', 5, 0, None, 15], [105, '', None, 3, 0, 195]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
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

evaluation_group: xs-group-total-filter

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import sqlite3
N = 1
observations = []
def solve(rows, refs):
    db = sqlite3.connect(':memory:')
    try:
        for name, records in [('a', rows), ('b', refs)]:
            db.execute('CREATE TABLE ' + name + ' (id INTEGER PRIMARY KEY, k TEXT, v INTEGER, w INTEGER, flag INTEGER, parent INTEGER)')
            db.executemany('INSERT INTO ' + name + ' VALUES (?,?,?,?,?,?)', records)
        return sorted([list(row) for row in db.execute('SELECT k,SUM(v) FROM a GROUP BY k HAVING MAX(v)>0')], key=repr)
    finally:
        db.close()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[11, 'a', None, 8, None, None], [21, 'a', 0, 3, 0, 11], [31, 'a', 2, 1, 1, 21], [41, 'a', 2, 2, 2, 901], [51, 'a', -1, 4, -1, 31], [61, 'a', 3, 1, 1, 41], [71, 'b', -2, 2, 0, 11], [81, 'b', 2, 8, 1, 21], [91, 'b', None, 4, None, None], [101, None, None, 0, 1, 901], [111, None, 0, 5, 0, 11], [121, None, None, 7, None, 21], [131, 'c', None, 6, None, 31], [141, 'd', -1, 1, 0, 41], [151, 'A', 2, 2, 1, 51], [161, ' a ', 2, 8, 1, None], [171, '', None, 2, 0, None], [181, 'a', 2, 8, 1, 11], [191, 'd', 1, 3, 0, 41], [201, 'd', -1, 0, -1, 21]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[11, 'a', None, 0, 1, None], [21, 'a', 2, 2, 0, None], [31, 'a', 2, 3, 2, None], [41, 'a', 3, 4, None, None], [51, 'b', -2, 2, 1, None], [61, 'b', 0, 8, -1, None], [71, None, None, 2, 1, None], [81, None, 0, 5, None, None], [91, 'z', 3, 2, 0, None], [101, 'z', 3, 2, 1, None], [111, 'A', 2, 1, 1, None], [121, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[11, 'a', None, 8, None, None], [21, 'a', 0, 3, 0, 11], [31, 'a', 2, 1, 1, 21], [41, 'a', 2, 2, 2, 901], [51, 'a', -1, 4, -1, 31], [61, 'a', 3, 1, 1, 41], [71, 'b', -2, 2, 0, 11], [81, 'b', 2, 8, 1, 21], [91, 'b', None, 4, None, None], [101, None, None, 0, 1, 901], [111, None, 0, 5, 0, 11], [121, None, None, 7, None, 21], [131, 'c', None, 6, None, 31], [141, 'd', -1, 1, 0, 41], [151, 'A', 2, 2, 1, 51], [161, ' a ', 2, 8, 1, None], [171, '', None, 2, 0, None], [181, 'a', 2, 8, 1, 11], [191, 'd', 1, 3, 0, 41], [201, 'd', -1, 0, -1, 21]], [[11, 'a', None, 0, 1, None], [21, 'a', 2, 2, 0, None], [31, 'a', 2, 3, 2, None], [41, 'a', 3, 4, None, None], [51, 'b', -2, 2, 1, None], [61, 'b', 0, 8, -1, None], [71, None, None, 2, 1, None], [81, None, 0, 5, None, None], [91, 'z', 3, 2, 0, None], [101, 'z', 3, 2, 1, None], [111, 'A', 2, 1, 1, None], [121, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[11, None, None, 3, None, None], [21, None, None, 4, None, None], [31, 'x', None, 5, None, None]], [[11, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[11, 'a', 0, 9, 0, 11]], [[11, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[11, 'n', -2, 4, -1, 11], [21, 'n', None, 2, 0, 21], [31, 'n', -1, 0, 2, None]], [[11, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[11, 'p', 2, 1, 1, 11], [21, 'p', 2, 2, 1, 11], [31, 'p', 3, 0, 1, 11], [41, 'p', None, 1, 0, None]], [[11, 'p', 2, 1, 1, None], [21, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[11, None, -2, 1, 0, 11], [21, 'b', None, 2, 1, 191], [31, None, 2, 7, 2, 191], [41, 'A', 3, 3, -1, 31], [51, ' a ', None, 7, 2, 11], [61, '', 1, 7, 2, None], [71, None, 2, 0, 2, 21], [81, 'A', None, 3, -1, 21], [91, 'a', 2, 7, 2, 191], [101, 'b', 3, 2, 0, None], [111, 'c', None, 3, 2, None], [121, 'A', 5, 2, None, None], [131, ' a ', 0, 1, 1, 21], [141, 'b', 2, 7, 2, None]], [[11, ' a ', -1, 1, 0, 31], [21, 'a', 5, 0, 0, None], [31, 'c', -3, 0, 1, 191], [41, ' a ', 2, 7, 1, None], [51, 'b', None, 7, -1, 11], [61, '', 2, 0, None, 31], [71, 'b', -3, 3, 1, None], [81, 'a', 0, 1, None, 191], [91, 'a', 5, 0, None, 11], [101, '', None, 3, 0, 191]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
elif N == 2:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[12, 'a', None, 8, None, None], [22, 'a', 0, 3, 0, 12], [32, 'a', 2, 1, 1, 22], [42, 'a', 2, 2, 2, 902], [52, 'a', -1, 4, -1, 32], [62, 'a', 3, 1, 1, 42], [72, 'b', -2, 2, 0, 12], [82, 'b', 2, 8, 1, 22], [92, 'b', None, 4, None, None], [102, None, None, 0, 1, 902], [112, None, 0, 5, 0, 12], [122, None, None, 7, None, 22], [132, 'c', None, 6, None, 32], [142, 'd', -1, 1, 0, 42], [152, 'A', 2, 2, 1, 52], [162, ' a ', 2, 8, 1, None], [172, '', None, 2, 0, None], [182, 'a', 2, 8, 1, 12], [192, 'd', 1, 3, 0, 42], [202, 'd', -1, 0, -1, 22]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[12, 'a', None, 0, 1, None], [22, 'a', 2, 2, 0, None], [32, 'a', 2, 3, 2, None], [42, 'a', 3, 4, None, None], [52, 'b', -2, 2, 1, None], [62, 'b', 0, 8, -1, None], [72, None, None, 2, 1, None], [82, None, 0, 5, None, None], [92, 'z', 3, 2, 0, None], [102, 'z', 3, 2, 1, None], [112, 'A', 2, 1, 1, None], [122, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[12, 'a', None, 8, None, None], [22, 'a', 0, 3, 0, 12], [32, 'a', 2, 1, 1, 22], [42, 'a', 2, 2, 2, 902], [52, 'a', -1, 4, -1, 32], [62, 'a', 3, 1, 1, 42], [72, 'b', -2, 2, 0, 12], [82, 'b', 2, 8, 1, 22], [92, 'b', None, 4, None, None], [102, None, None, 0, 1, 902], [112, None, 0, 5, 0, 12], [122, None, None, 7, None, 22], [132, 'c', None, 6, None, 32], [142, 'd', -1, 1, 0, 42], [152, 'A', 2, 2, 1, 52], [162, ' a ', 2, 8, 1, None], [172, '', None, 2, 0, None], [182, 'a', 2, 8, 1, 12], [192, 'd', 1, 3, 0, 42], [202, 'd', -1, 0, -1, 22]], [[12, 'a', None, 0, 1, None], [22, 'a', 2, 2, 0, None], [32, 'a', 2, 3, 2, None], [42, 'a', 3, 4, None, None], [52, 'b', -2, 2, 1, None], [62, 'b', 0, 8, -1, None], [72, None, None, 2, 1, None], [82, None, 0, 5, None, None], [92, 'z', 3, 2, 0, None], [102, 'z', 3, 2, 1, None], [112, 'A', 2, 1, 1, None], [122, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[12, None, None, 3, None, None], [22, None, None, 4, None, None], [32, 'x', None, 5, None, None]], [[12, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[12, 'a', 0, 9, 0, 12]], [[12, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[12, 'n', -2, 4, -1, 12], [22, 'n', None, 2, 0, 22], [32, 'n', -1, 0, 2, None]], [[12, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[12, 'p', 2, 1, 1, 12], [22, 'p', 2, 2, 1, 12], [32, 'p', 3, 0, 1, 12], [42, 'p', None, 1, 0, None]], [[12, 'p', 2, 1, 1, None], [22, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[12, None, -2, 1, 0, 12], [22, 'b', None, 2, 1, 192], [32, None, 2, 7, 2, 192], [42, 'A', 3, 3, -1, 32], [52, ' a ', None, 7, 2, 12], [62, '', 1, 7, 2, None], [72, None, 2, 0, 2, 22], [82, 'A', None, 3, -1, 22], [92, 'a', 2, 7, 2, 192], [102, 'b', 3, 2, 0, None], [112, 'c', None, 3, 2, None], [122, 'A', 5, 2, None, None], [132, ' a ', 0, 1, 1, 22], [142, 'b', 2, 7, 2, None]], [[12, ' a ', -1, 1, 0, 32], [22, 'a', 5, 0, 0, None], [32, 'c', -3, 0, 1, 192], [42, ' a ', 2, 7, 1, None], [52, 'b', None, 7, -1, 12], [62, '', 2, 0, None, 32], [72, 'b', -3, 3, 1, None], [82, 'a', 0, 1, None, 192], [92, 'a', 5, 0, None, 12], [102, '', None, 3, 0, 192]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
elif N == 3:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[13, 'a', None, 8, None, None], [23, 'a', 0, 3, 0, 13], [33, 'a', 2, 1, 1, 23], [43, 'a', 2, 2, 2, 903], [53, 'a', -1, 4, -1, 33], [63, 'a', 3, 1, 1, 43], [73, 'b', -2, 2, 0, 13], [83, 'b', 2, 8, 1, 23], [93, 'b', None, 4, None, None], [103, None, None, 0, 1, 903], [113, None, 0, 5, 0, 13], [123, None, None, 7, None, 23], [133, 'c', None, 6, None, 33], [143, 'd', -1, 1, 0, 43], [153, 'A', 2, 2, 1, 53], [163, ' a ', 2, 8, 1, None], [173, '', None, 2, 0, None], [183, 'a', 2, 8, 1, 13], [193, 'd', 1, 3, 0, 43], [203, 'd', -1, 0, -1, 23]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[13, 'a', None, 0, 1, None], [23, 'a', 2, 2, 0, None], [33, 'a', 2, 3, 2, None], [43, 'a', 3, 4, None, None], [53, 'b', -2, 2, 1, None], [63, 'b', 0, 8, -1, None], [73, None, None, 2, 1, None], [83, None, 0, 5, None, None], [93, 'z', 3, 2, 0, None], [103, 'z', 3, 2, 1, None], [113, 'A', 2, 1, 1, None], [123, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[13, 'a', None, 8, None, None], [23, 'a', 0, 3, 0, 13], [33, 'a', 2, 1, 1, 23], [43, 'a', 2, 2, 2, 903], [53, 'a', -1, 4, -1, 33], [63, 'a', 3, 1, 1, 43], [73, 'b', -2, 2, 0, 13], [83, 'b', 2, 8, 1, 23], [93, 'b', None, 4, None, None], [103, None, None, 0, 1, 903], [113, None, 0, 5, 0, 13], [123, None, None, 7, None, 23], [133, 'c', None, 6, None, 33], [143, 'd', -1, 1, 0, 43], [153, 'A', 2, 2, 1, 53], [163, ' a ', 2, 8, 1, None], [173, '', None, 2, 0, None], [183, 'a', 2, 8, 1, 13], [193, 'd', 1, 3, 0, 43], [203, 'd', -1, 0, -1, 23]], [[13, 'a', None, 0, 1, None], [23, 'a', 2, 2, 0, None], [33, 'a', 2, 3, 2, None], [43, 'a', 3, 4, None, None], [53, 'b', -2, 2, 1, None], [63, 'b', 0, 8, -1, None], [73, None, None, 2, 1, None], [83, None, 0, 5, None, None], [93, 'z', 3, 2, 0, None], [103, 'z', 3, 2, 1, None], [113, 'A', 2, 1, 1, None], [123, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[13, None, None, 3, None, None], [23, None, None, 4, None, None], [33, 'x', None, 5, None, None]], [[13, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[13, 'a', 0, 9, 0, 13]], [[13, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[13, 'n', -2, 4, -1, 13], [23, 'n', None, 2, 0, 23], [33, 'n', -1, 0, 2, None]], [[13, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[13, 'p', 2, 1, 1, 13], [23, 'p', 2, 2, 1, 13], [33, 'p', 3, 0, 1, 13], [43, 'p', None, 1, 0, None]], [[13, 'p', 2, 1, 1, None], [23, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[13, None, -2, 1, 0, 13], [23, 'b', None, 2, 1, 193], [33, None, 2, 7, 2, 193], [43, 'A', 3, 3, -1, 33], [53, ' a ', None, 7, 2, 13], [63, '', 1, 7, 2, None], [73, None, 2, 0, 2, 23], [83, 'A', None, 3, -1, 23], [93, 'a', 2, 7, 2, 193], [103, 'b', 3, 2, 0, None], [113, 'c', None, 3, 2, None], [123, 'A', 5, 2, None, None], [133, ' a ', 0, 1, 1, 23], [143, 'b', 2, 7, 2, None]], [[13, ' a ', -1, 1, 0, 33], [23, 'a', 5, 0, 0, None], [33, 'c', -3, 0, 1, 193], [43, ' a ', 2, 7, 1, None], [53, 'b', None, 7, -1, 13], [63, '', 2, 0, None, 33], [73, 'b', -3, 3, 1, None], [83, 'a', 0, 1, None, 193], [93, 'a', 5, 0, None, 13], [103, '', None, 3, 0, 193]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
elif N == 4:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[14, 'a', None, 8, None, None], [24, 'a', 0, 3, 0, 14], [34, 'a', 2, 1, 1, 24], [44, 'a', 2, 2, 2, 904], [54, 'a', -1, 4, -1, 34], [64, 'a', 3, 1, 1, 44], [74, 'b', -2, 2, 0, 14], [84, 'b', 2, 8, 1, 24], [94, 'b', None, 4, None, None], [104, None, None, 0, 1, 904], [114, None, 0, 5, 0, 14], [124, None, None, 7, None, 24], [134, 'c', None, 6, None, 34], [144, 'd', -1, 1, 0, 44], [154, 'A', 2, 2, 1, 54], [164, ' a ', 2, 8, 1, None], [174, '', None, 2, 0, None], [184, 'a', 2, 8, 1, 14], [194, 'd', 1, 3, 0, 44], [204, 'd', -1, 0, -1, 24]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[14, 'a', None, 0, 1, None], [24, 'a', 2, 2, 0, None], [34, 'a', 2, 3, 2, None], [44, 'a', 3, 4, None, None], [54, 'b', -2, 2, 1, None], [64, 'b', 0, 8, -1, None], [74, None, None, 2, 1, None], [84, None, 0, 5, None, None], [94, 'z', 3, 2, 0, None], [104, 'z', 3, 2, 1, None], [114, 'A', 2, 1, 1, None], [124, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[14, 'a', None, 8, None, None], [24, 'a', 0, 3, 0, 14], [34, 'a', 2, 1, 1, 24], [44, 'a', 2, 2, 2, 904], [54, 'a', -1, 4, -1, 34], [64, 'a', 3, 1, 1, 44], [74, 'b', -2, 2, 0, 14], [84, 'b', 2, 8, 1, 24], [94, 'b', None, 4, None, None], [104, None, None, 0, 1, 904], [114, None, 0, 5, 0, 14], [124, None, None, 7, None, 24], [134, 'c', None, 6, None, 34], [144, 'd', -1, 1, 0, 44], [154, 'A', 2, 2, 1, 54], [164, ' a ', 2, 8, 1, None], [174, '', None, 2, 0, None], [184, 'a', 2, 8, 1, 14], [194, 'd', 1, 3, 0, 44], [204, 'd', -1, 0, -1, 24]], [[14, 'a', None, 0, 1, None], [24, 'a', 2, 2, 0, None], [34, 'a', 2, 3, 2, None], [44, 'a', 3, 4, None, None], [54, 'b', -2, 2, 1, None], [64, 'b', 0, 8, -1, None], [74, None, None, 2, 1, None], [84, None, 0, 5, None, None], [94, 'z', 3, 2, 0, None], [104, 'z', 3, 2, 1, None], [114, 'A', 2, 1, 1, None], [124, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[14, None, None, 3, None, None], [24, None, None, 4, None, None], [34, 'x', None, 5, None, None]], [[14, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[14, 'a', 0, 9, 0, 14]], [[14, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[14, 'n', -2, 4, -1, 14], [24, 'n', None, 2, 0, 24], [34, 'n', -1, 0, 2, None]], [[14, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[14, 'p', 2, 1, 1, 14], [24, 'p', 2, 2, 1, 14], [34, 'p', 3, 0, 1, 14], [44, 'p', None, 1, 0, None]], [[14, 'p', 2, 1, 1, None], [24, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[14, None, -2, 1, 0, 14], [24, 'b', None, 2, 1, 194], [34, None, 2, 7, 2, 194], [44, 'A', 3, 3, -1, 34], [54, ' a ', None, 7, 2, 14], [64, '', 1, 7, 2, None], [74, None, 2, 0, 2, 24], [84, 'A', None, 3, -1, 24], [94, 'a', 2, 7, 2, 194], [104, 'b', 3, 2, 0, None], [114, 'c', None, 3, 2, None], [124, 'A', 5, 2, None, None], [134, ' a ', 0, 1, 1, 24], [144, 'b', 2, 7, 2, None]], [[14, ' a ', -1, 1, 0, 34], [24, 'a', 5, 0, 0, None], [34, 'c', -3, 0, 1, 194], [44, ' a ', 2, 7, 1, None], [54, 'b', None, 7, -1, 14], [64, '', 2, 0, None, 34], [74, 'b', -3, 3, 1, None], [84, 'a', 0, 1, None, 194], [94, 'a', 5, 0, None, 14], [104, '', None, 3, 0, 194]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
elif N == 5:
    check('empty relations', solve([], []), [])
    check('left facts without references', solve([[15, 'a', None, 8, None, None], [25, 'a', 0, 3, 0, 15], [35, 'a', 2, 1, 1, 25], [45, 'a', 2, 2, 2, 905], [55, 'a', -1, 4, -1, 35], [65, 'a', 3, 1, 1, 45], [75, 'b', -2, 2, 0, 15], [85, 'b', 2, 8, 1, 25], [95, 'b', None, 4, None, None], [105, None, None, 0, 1, 905], [115, None, 0, 5, 0, 15], [125, None, None, 7, None, 25], [135, 'c', None, 6, None, 35], [145, 'd', -1, 1, 0, 45], [155, 'A', 2, 2, 1, 55], [165, ' a ', 2, 8, 1, None], [175, '', None, 2, 0, None], [185, 'a', 2, 8, 1, 15], [195, 'd', 1, 3, 0, 45], [205, 'd', -1, 0, -1, 25]], []), [[' a ', 2], ['A', 2], ['a', 8]])
    check('references without candidates', solve([], [[15, 'a', None, 0, 1, None], [25, 'a', 2, 2, 0, None], [35, 'a', 2, 3, 2, None], [45, 'a', 3, 4, None, None], [55, 'b', -2, 2, 1, None], [65, 'b', 0, 8, -1, None], [75, None, None, 2, 1, None], [85, None, 0, 5, None, None], [95, 'z', 3, 2, 0, None], [105, 'z', 3, 2, 1, None], [115, 'A', 2, 1, 1, None], [125, 'c', None, 2, 0, None]]), [])
    check('mixed nullable groups duplicates ties and truth flags', solve([[15, 'a', None, 8, None, None], [25, 'a', 0, 3, 0, 15], [35, 'a', 2, 1, 1, 25], [45, 'a', 2, 2, 2, 905], [55, 'a', -1, 4, -1, 35], [65, 'a', 3, 1, 1, 45], [75, 'b', -2, 2, 0, 15], [85, 'b', 2, 8, 1, 25], [95, 'b', None, 4, None, None], [105, None, None, 0, 1, 905], [115, None, 0, 5, 0, 15], [125, None, None, 7, None, 25], [135, 'c', None, 6, None, 35], [145, 'd', -1, 1, 0, 45], [155, 'A', 2, 2, 1, 55], [165, ' a ', 2, 8, 1, None], [175, '', None, 2, 0, None], [185, 'a', 2, 8, 1, 15], [195, 'd', 1, 3, 0, 45], [205, 'd', -1, 0, -1, 25]], [[15, 'a', None, 0, 1, None], [25, 'a', 2, 2, 0, None], [35, 'a', 2, 3, 2, None], [45, 'a', 3, 4, None, None], [55, 'b', -2, 2, 1, None], [65, 'b', 0, 8, -1, None], [75, None, None, 2, 1, None], [85, None, 0, 5, None, None], [95, 'z', 3, 2, 0, None], [105, 'z', 3, 2, 1, None], [115, 'A', 2, 1, 1, None], [125, 'c', None, 2, 0, None]]), [[' a ', 2], ['A', 2], ['a', 8]])
    check('unknown-only group with duplicate nullable index keys', solve([[15, None, None, 3, None, None], [25, None, None, 4, None, None], [35, 'x', None, 5, None, None]], [[15, None, None, 2, None, None]]), [])
    check('single known zero and matching reference', solve([[15, 'a', 0, 9, 0, 15]], [[15, 'a', 0, 3, 1, None]]), [])
    check('negative-only group and missing measurement', solve([[15, 'n', -2, 4, -1, 15], [25, 'n', None, 2, 0, 25], [35, 'n', -1, 0, 2, None]], [[15, 'n', -2, 1, 1, None]]), [])
    check('positive-only group with repeated measurements and NULL', solve([[15, 'p', 2, 1, 1, 15], [25, 'p', 2, 2, 1, 15], [35, 'p', 3, 0, 1, 15], [45, 'p', None, 1, 0, None]], [[15, 'p', 2, 1, 1, None], [25, 'p', 2, 1, 1, None]]), [['p', 7]])
    check('adversarial key cardinality and NULL placement witness 9', solve([[15, None, -2, 1, 0, 15], [25, 'b', None, 2, 1, 195], [35, None, 2, 7, 2, 195], [45, 'A', 3, 3, -1, 35], [55, ' a ', None, 7, 2, 15], [65, '', 1, 7, 2, None], [75, None, 2, 0, 2, 25], [85, 'A', None, 3, -1, 25], [95, 'a', 2, 7, 2, 195], [105, 'b', 3, 2, 0, None], [115, 'c', None, 3, 2, None], [125, 'A', 5, 2, None, None], [135, ' a ', 0, 1, 1, 25], [145, 'b', 2, 7, 2, None]], [[15, ' a ', -1, 1, 0, 35], [25, 'a', 5, 0, 0, None], [35, 'c', -3, 0, 1, 195], [45, ' a ', 2, 7, 1, None], [55, 'b', None, 7, -1, 15], [65, '', 2, 0, None, 35], [75, 'b', -3, 3, 1, None], [85, 'a', 0, 1, None, 195], [95, 'a', 5, 0, None, 15], [105, '', None, 3, 0, 195]]), [['', 1], ['A', 8], ['a', 2], ['b', 5], [None, 2]])
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 query violates its result contract: includes groups whose contributions cancel.

Return key and sum for groups whose known measurements sum to a strictly positive total. Inputs are finite relations a=rows and b=refs with columns (id,k,v,w,flag,parent). IDs are unique within each relation, None is SQL NULL, keys are ASCII strings or None, and other values are integers or None. Return an unordered result bag as lists sorted by repr, preserving multiplicity unless explicitly distinct.

split: open-access